// Guide to Java
// Copyright 2014, by J.T. Streib and T. Soma


// a program to create card, make purchases, and output balance

public class Purchases {                                  
 public static void main(String[] args) {             
    // output the information for Euros conversion
    Card.setRate(1.2128);                                       
    System.out.println("rate = " + Card.getRate());     
    System.out.println("1.00 euro is equal to "
     + Card.convertEurosToDollars(1.00) + " dollars.");  

    // declaration and initialization of instance variables
    Card card;                                                          
    card = new Card(12345, 0.0);                        
      
    // purchase and output balance
    card.purchaseInDollars(100.00);                             
    System.out.println("after spending 100.00 dollars");
    System.out.print("card: Account Number = "
    + card.getAccountNum() + ", balance = ");            
    System.out.printf("%.2f dollar",card.getBalance());
    System.out.println();                              
                        
    // purchase and output balance
    card.purchaseInEuros(100.00);                 // See Exercise 5
    System.out.println("after spending 100.00 euros");
    System.out.print("card: Account Number = "
    + card.getAccountNum() + ", balance = ");           
    System.out.printf("%.2f dollars",card.getBalance());
    System.out.println();                                
 }       
}

// definition of Card class

public class Card {
 // data members
 private static final int DEFAULT_ACCOUNT_NUMBER = 0;
 private static final double DEFAULT_BALANCE = 0.0;
 private static double rate;
 private int accountNum;
 private double balance;

 // class methods
 public static double convertEurosToDollars(double euros) {
    return euros*rate;
 }    

 public static void setRate(double aRate) {
    rate = aRate;
 }    
  
 public static double getRate() {
    return rate;       
 }    

 // constructors
 public Card() {
    // using second constructor
    this(DEFAULT_ACCOUNT_NUMBER, DEFAULT_BALANCE);
 }

 public Card(int accountNum, double amount) {
    // using setAccountNum and purchaseInDollars methods
    setAccountNum(accountNum);
    balance = amount;
 }
      
 // mutator methods
 public void setAccountNum(int accountNum) {
    this.accountNum = accountNum;       
 }    
  
 public void purchaseInDollars(double dollars) {
    balance += dollars;       
 }    
  
 public void purchaseInEuros(double euros) {
    balance += convertEurosToDollars(euros);
 }    
  
 // accessor methods
 public int getAccountNum() {
    return accountNum;       
 }    
  
 public double getBalance() {
    return balance;       
 }
}