Created
June 17, 2014 20:59
-
-
Save anonymous/dc2f24c7f0d23e90d1c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package atmmachine; | |
import java.util.Date; | |
import java.util.Scanner; | |
/** | |
* | |
* @author Madai | |
*/ | |
public class AtmMachine { | |
private int id; | |
private double balance = 100; | |
private double annualInterestRate; | |
private Date dateCreated; | |
double monthlyInterestRate; | |
double monthlyInterest; | |
double deposit; | |
double withdraw; | |
int answer; | |
Scanner input = new Scanner(System.in); | |
public AtmMachine(int id, double balance) { | |
dateCreated = new Date(); | |
this.id = id; | |
this.balance = balance; | |
} | |
public AtmMachine() { | |
id = 0; | |
balance = 100; | |
annualInterestRate = 0; | |
} | |
public int getId() { | |
int [][] AccountID = { | |
{1, 2, 3, 4, 5}, | |
{6, 7, 8, 9, 10}}; | |
return id; | |
} | |
public void setId(int id) { | |
this.id = id; | |
} | |
public double getBalance() { | |
return balance; | |
} | |
public void setBalance(double balance) { | |
this.balance = balance; | |
} | |
public double getAnnualInterestRate() { | |
return annualInterestRate ; | |
} | |
public void setAnnualInterestRate(double newAnnualInterestRate) { | |
this.annualInterestRate = newAnnualInterestRate; | |
} | |
public Date getDateCreated() { | |
return dateCreated; | |
} | |
public double getMonthlyInterestRate() { | |
return monthlyInterestRate = annualInterestRate / 1200; | |
} | |
public double getMonthlyInterest(){ | |
return monthlyInterest = balance * monthlyInterestRate; | |
} | |
public double getWithdraw() { | |
return withdraw; | |
} | |
public void setWithdraw(double withdrawMoney){ | |
this.withdraw = balance - withdrawMoney; | |
} | |
public double getDeposit() { | |
return deposit; | |
} | |
public void setDeposit(double depositMoney){ | |
this.deposit = balance + depositMoney; | |
} | |
@Override | |
public String toString() { | |
while(id <= 10){ | |
if (answer == 1){ | |
getBalance(); | |
System.out.println("The balance is " + balance); | |
return balance + ""; | |
} | |
if (answer == 2){ | |
getWithdraw(); | |
System.out.println("Enter the amount to withdraw" + withdraw); | |
withdraw = input.nextInt(); | |
return withdraw + ""; | |
} | |
if (answer == 3){ | |
System.out.println("Enter ammount to deposit " + deposit); | |
deposit = input.nextInt(); | |
getDeposit(); | |
return deposit + ""; | |
} | |
if (answer == 4) | |
System.exit(answer); | |
} | |
return answer + ""; | |
} | |
public static void main(String[] args) { | |
int withdraw = 0; | |
int deposit = 0; | |
int id; | |
Scanner input = new Scanner(System.in); | |
System.out.print("Enter an id: " ); | |
id = input.nextInt(); | |
System.out.print("\nMain menu\n" + "1: check balance\n" + "2: withdraw\n" + | |
"3: deposit\n" + "4: exit\n"); | |
System.out.print("Enter a choice: "); | |
int choice = input.nextInt(); | |
AtmMachine myATM = new AtmMachine(id, 100); | |
myATM.getBalance(); | |
myATM.getWithdraw(); | |
myATM.getDeposit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment