hi danpost
I have decided to leave it jus like that. that it is the only problem with it. everything else is working just perfectly thanks for all of your help, understanding and patience
Please select your choice now!! 4 Account@3570b0/nID: 3 Balance: -5.0 2 Enter the amount to deposit 10 Balance is 35.0 Enter the amount to withdraw 40 Insufficient amount Balance is: -5.0
public double deposit(double deposit)
{
balance +=deposit;
return(getbalance()+deposit);
}
public double withdraw(double withdraw)
{
balance -=withdraw;
return (getbalance() - withdraw);
import java.text.DecimalFormat;
import java.util.Scanner;
public class ATM {
DecimalFormat df = new DecimalFormat("#.00");
public static void main(String[] args) {
createAccount();
}
public static void createAccount()
{
Scanner input = new Scanner(System.in);
int i=0;
double bal=50.0;
Account[] acc = new Account[10];
Person[] p = new Person[i++];
for(i=0; i<acc.length; i++){
System.out.println("Enter first name");
String fn = input.next();
System.out.println("Enter last name");
String ln = input.next();
System.out.println("Enter address");
String ad = input.next();
System.out.println("Enter contact");
String c = input.next();
Person person= new Person(fn, ln, ad, c);
acc[i]= new Account(i, 50, person);
}
while(true)
{
System.out.println("Enter your id");
int id = input.nextInt();
if(id == -1)
{
break;
}
while(id < 0 || id > 9)
{
System.out.println("id is incorect, try again");
id = input.nextInt();
}
while(true)
{
displayMenu();
if(!useMenu(acc[id],input))
{
System.out.println();
break;
}
System.out.println("\n");
}
}
}
public static boolean useMenu(Account acc, Scanner input)
{
int userchoice = input.nextInt();
double amt=0;
if(userchoice == 5)
{
return false;
}
else if(userchoice == 1)
{
System.out.println("The account balance is: "+ acc.getbalance());
return true;
}
else if(userchoice == 2)
{
System.out.println("Enter the amount to withdraw");
acc.withdraw(input.nextDouble());
if(amt > acc.getbalance())
{
System.out.println("Insufficient amount "+ " Balance is: "+acc.getbalance());
}
else
{
acc.withdraw(amt);
}
}
else if(userchoice == 3)
{
System.out.println("Enter the amount to deposit");
acc.deposit(input.nextDouble());
acc.deposit(amt);
System.out.println("Balance is "+ acc.getbalance());
return true;
}
else if(userchoice == 4)
{
System.out.println(acc.toString());
}
else
{
System.out.println("invalid choice");
}
return true;
}
public static void displayMenu()
{
System.out.println("Welcome to the Automated Teller Machine!\n");
System.out.println("Select from the following menu option below:\n");
System.out.println("===================================");
System.out.println("| Main Menu |");
System.out.println("===================================");
System.out.println("| [1] Check Balance |");
System.out.println("| [2] Withdraw |");
System.out.println("| [3] Deposit |");
System.out.println("| [4] Display User Information |");
System.out.println("| [5] Exist |");
System.out.println("===================================");
System.out.println("Please select your choice now!!");
}
}
this is the account class
public class Account
{
private int ID;// this is the id variable
private double balance;
private Person owner;
public Account()
{
//no arg constructor
}
//constructor method with
public Account(int ID, double balance, Person owner)
{
this.ID = ID;
this.balance = balance;
this.owner = owner;
}
public int getID()
{
return ID;
}
public double getbalance()
{
return balance;
}
public Person getowner()
{
return owner;
}
public void setID(int ID)
{
this.ID = ID;
}
public void setbalance(double balance)
{
this.balance = balance;
}
public void setowner(Person owner)
{
this.owner = owner;
}
public void deposit(double amt)
{
balance = balance + amt;
}
public void withdraw(double amt)
{
balance = balance - amt;
}
@Override
public String toString()
{
String getdetails = super.toString()+
"/nID: "+ID+" "
+ "\nBalance: "+balance;
return getdetails;
}
}
this is the person
public class Person {
private String FirstName;
private String LastName;
private String address;
private String contact;
public Person(String f, String l, String a, String c) {
FirstName = f;
LastName = l;
address = a;
contact = c;
}
//get first name
public String getFirstName() {
return FirstName;
}
//get last name
public String getLastName() {
return LastName;
}
//get address
public String getaddress() {
return address;
}
//get telephone number
public String getcontact() {
return contact;
}
//accessor method with the person name and with parameters
public void setFirstName(String FirstName) {
this.FirstName = FirstName;
}
//accessor method with the person last name with parameters
public void setLastName(String LastName) {
this.LastName = LastName;
}
//accessor method the person address with parameters
public void setaddress(String address) {
this.address = address;
}
//accessor method that take one parameter
public void setcontact(String contact) {
this.contact = contact;
}
@Override
public String toString() {
String getdetails = super.toString()
+ "First Name " + FirstName + " "
+ "Last Name " + LastName + " "
+ "Address " + address + " "
+ " Contact " + contact;
return getdetails;
}
}
amt = input.nextDouble()
Account@3570b0/nID: 1 Balance: 35.0
System.out.println(acc.getowner().toString());
Person@21b220First Name joy Last Name joyeau Address arouca Contact 6223535