SlideShare a Scribd company logo
Java program
I made this Account.java below. Using the attached code I need help with 10.7 (Game: ATM
machine)
Use the Account class created in Programming Exercise 9.7 to simulate an ATM machine.
Create ten accounts in an array with id 0, 1, . . . , 9, and initial balance $100.
The system prompts the user to enter an id. If the id is entered incorrectly, ask the user to enter a
correct id.
Once an id is accepted, the main menu is displayed as shown in the sample run.
You can enter a choice 1 for viewing the current balance, 2 for withdrawing money, 3 for
depositing money, and 4 for exiting the main menu.
Once you exit, the system will prompt for an id again. Thus, once the system starts, it will not
stop.
*/
import java.util.Date;
public class Account {
/**
* @param args
*/
private int id=0;
private double balance=0;
private double annualIntrestRate=0;
private Date dateCreated;
public Account() {
super();
}
public Account(int id, double balance) {
super();
this.id = id;
this.balance = balance;
}
public int getId() {
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 getAnnualIntrestRate() {
return annualIntrestRate;
}
public void setAnnualIntrestRate(double annualIntrestRate) {
this.annualIntrestRate = annualIntrestRate;
}
public Date getDateCreated() {
return dateCreated;
}
public void setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
}
public double getMonthlyInterestRate()
{
return (this.getAnnualIntrestRate()/12);
}
public double getMonthlyInterest()
{
return (getBalance() *getMonthlyInterestRate()/100);
}
public double withDraw(double balance)
{
this.setBalance(this.getBalance()-balance);
return this.getBalance();
}
public double diposite(double balance)
{
this.setBalance(this.getBalance()+balance);
return this.getBalance();
}
public double totalBalance()
{
balance =balance + getMonthlyInterest();
return balance;
}
}
//AccountTest.java
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;
public class AccountTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
Account ac=new Account(1,5000.00);
System.out.println("Enter the annual intrest rate");
double intrestRate=sc.nextDouble();
ac.setAnnualIntrestRate(intrestRate);
Date d=new Date();
Calendar currentDate = Calendar.getInstance();
ac.setDateCreated(currentDate.getTime());
System.out.println("Date id "+ac.getDateCreated());
System.out.println("Monthly intrest rate is :"+ac.getMonthlyInterestRate());
System.out.println("Monthly intrest is :"+ac.getMonthlyInterest());
System.out.println("Enter Amount for diposite ");
double dipositeAmount=sc.nextDouble();
System.out.println("The amount after diposite is :"+ac.diposite(dipositeAmount));
System.out.println("Enter Amount to withdraw :");
double withdramount= sc.nextDouble();
System.out.println("The amount remain after with draw "+ac.withDraw(withdramount));
System.out.println("The total amount is "+ac.totalBalance());
}
}
/**
Sample output :
Enter the annual intrest rate
2.5
Date id Thu Mar 07 04:55:38 IST 2013
Monthly intrest rate is :0.208
Monthly intrest is :10.42
Enter Amount for diposite
300
The amount after diposite is :5300.0
Enter Amount to withdraw :
3000
The amount remain after with draw 2300.0
The total amount is 2304.79
*/
Solution
//Account.java
//Account represents the object of Account class
import java.util.Date;
public class Account {
/**
* @param args
*/
private int id=0;
private double balance=0;
private double annualIntrestRate=0;
private Date dateCreated;
public Account() {
super();
}
public Account(int id, double balance) {
super();
this.id = id;
this.balance = balance;
}
public int getId() {
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 getAnnualIntrestRate() {
return annualIntrestRate;
}
public void setAnnualIntrestRate(double annualIntrestRate) {
this.annualIntrestRate = annualIntrestRate;
}
public Date getDateCreated() {
return dateCreated;
}
public void setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
}
public double getMonthlyInterestRate()
{
return (this.getAnnualIntrestRate()/12);
}
public double getMonthlyInterest()
{
return (getBalance() *getMonthlyInterestRate()/100);
}
public double withDraw(double balance)
{
this.setBalance(this.getBalance()-balance);
return this.getBalance();
}
public double diposite(double balance)
{
this.setBalance(this.getBalance()+balance);
return this.getBalance();
}
public double totalBalance()
{
balance =balance + getMonthlyInterest();
return balance;
}
}
--------------------------------------------------------------------------------------------------------------------
----
/**
* The java program ATMSimulation that prompts user to enter
* an id number and re prompt if user id is not valid.
* Then prints the display menu that contains user choices.
* Then prints the correspoding output. Then repeats the
* menu.
* */
//ATMSimulation.java
import java.util.Scanner;
public class ATMSimulation {
public static void main(String[] args) {
//declare an array of type Account of size=10
final int SIZE=10;
Account[] accts=new Account[SIZE];
//set id and amount
for (int id = 0; id < accts.length; id++) {
accts[id]=new Account(id, 100.0);
}
Scanner scan=new Scanner(System.in);
int userId;
boolean repeat=true;
//Run the program
while(true)
{
do
{
//promot for user id
System.out.println("Enter your id number [0-9]: ");
userId=scan.nextInt();
if(userId<0 || userId>10)
System.out.println("Invalid id number.");
}while(userId<0 || userId>10);
//Get account into holder object
Account holder=accts[userId];
double amt=0;
repeat=true;
//repeat until user enter 4 to stop
while(repeat)
{
int choice=menu();
switch(choice)
{
case 1:
System.out.println("Balance : "+holder.totalBalance());
break;
case 2:
System.out.println("Enter amount to withdraw :");
amt=scan.nextDouble();
holder.withDraw(amt);
break;
case 3:
System.out.println("Enter amount to deposit :");
amt=scan.nextDouble();
holder.diposite(amt);
break;
case 4:
repeat=false;
break;
}
}
}
}
//Method menu display a menu of choices to users to select
private static int menu() {
Scanner scan=new Scanner(System.in);
int choice;
do
{
System.out.println("1.Viewcurrent balance");
System.out.println("2.Withdrawing money");
System.out.println("3.Depositing money");
System.out.println("4.Exit menu.");
choice=scan.nextInt();
if(choice<0 || choice>4)
System.out.println("Invalid choice");
}while(choice<0 || choice>4);
return choice;
}
}
--------------------------------------------------------------------------------------------------------------------
----
Output:
Enter your id number :
1
1.Viewcurrent balance
2.Withdrawing money
3.Depositing money
4.Exit menu.
1
Balance : 100.0
1.Viewcurrent balance
2.Withdrawing money
3.Depositing money
4.Exit menu.
3
Enter amount to deposit :
2500
1.Viewcurrent balance
2.Withdrawing money
3.Depositing money
4.Exit menu.
4
Enter your id number :
5
1.Viewcurrent balance
2.Withdrawing money
3.Depositing money
4.Exit menu.
1
Balance : 100.0
1.Viewcurrent balance
2.Withdrawing money
3.Depositing money
4.Exit menu.
5
Invalid choice
1.Viewcurrent balance
2.Withdrawing money
3.Depositing money
4.Exit menu.
Ad

More Related Content

Similar to Java programI made this Account.java below. Using the attached cod.pdf (13)

You are not setting any values for those variables(name, ID, interes.pdf
You are not setting any values for those variables(name, ID, interes.pdfYou are not setting any values for those variables(name, ID, interes.pdf
You are not setting any values for those variables(name, ID, interes.pdf
deepakangel
 
The java Payroll that prompts user to enter hourly rate .pdf
  The java Payroll that prompts user to enter  hourly rate .pdf  The java Payroll that prompts user to enter  hourly rate .pdf
The java Payroll that prompts user to enter hourly rate .pdf
angelfashions02
 
import java.util.Scanner;import java.text.DecimalFormat;import j.pdf
import java.util.Scanner;import java.text.DecimalFormat;import j.pdfimport java.util.Scanner;import java.text.DecimalFormat;import j.pdf
import java.util.Scanner;import java.text.DecimalFormat;import j.pdf
KUNALHARCHANDANI1
 
Interest.javaimport java.util.Scanner; public class Interest.pdf
 Interest.javaimport java.util.Scanner; public class Interest.pdf Interest.javaimport java.util.Scanner; public class Interest.pdf
Interest.javaimport java.util.Scanner; public class Interest.pdf
aradhana9856
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3
Dillon Lee
 
Change to oop formatimport java.util.Scanner;import java.io.;.pdf
Change to oop formatimport java.util.Scanner;import java.io.;.pdfChange to oop formatimport java.util.Scanner;import java.io.;.pdf
Change to oop formatimport java.util.Scanner;import java.io.;.pdf
MAYANKBANSAL1981
 
- the modification will be done in Main class- first, asks the use.pdf
- the modification will be done in Main class- first, asks the use.pdf- the modification will be done in Main class- first, asks the use.pdf
- the modification will be done in Main class- first, asks the use.pdf
hanumanparsadhsr
 
Tmpj3 01 201181102muhammad_tohir
Tmpj3 01 201181102muhammad_tohirTmpj3 01 201181102muhammad_tohir
Tmpj3 01 201181102muhammad_tohir
pencari buku
 
07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt
Ajenkris Kungkung
 
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdfJAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
calderoncasto9163
 
Procedure to create_the_calculator_application java
Procedure to create_the_calculator_application javaProcedure to create_the_calculator_application java
Procedure to create_the_calculator_application java
gthe
 
C# labprograms
C# labprogramsC# labprograms
C# labprograms
Jafar Nesargi
 
C++ project
C++ projectC++ project
C++ project
Sonu S S
 
You are not setting any values for those variables(name, ID, interes.pdf
You are not setting any values for those variables(name, ID, interes.pdfYou are not setting any values for those variables(name, ID, interes.pdf
You are not setting any values for those variables(name, ID, interes.pdf
deepakangel
 
The java Payroll that prompts user to enter hourly rate .pdf
  The java Payroll that prompts user to enter  hourly rate .pdf  The java Payroll that prompts user to enter  hourly rate .pdf
The java Payroll that prompts user to enter hourly rate .pdf
angelfashions02
 
import java.util.Scanner;import java.text.DecimalFormat;import j.pdf
import java.util.Scanner;import java.text.DecimalFormat;import j.pdfimport java.util.Scanner;import java.text.DecimalFormat;import j.pdf
import java.util.Scanner;import java.text.DecimalFormat;import j.pdf
KUNALHARCHANDANI1
 
Interest.javaimport java.util.Scanner; public class Interest.pdf
 Interest.javaimport java.util.Scanner; public class Interest.pdf Interest.javaimport java.util.Scanner; public class Interest.pdf
Interest.javaimport java.util.Scanner; public class Interest.pdf
aradhana9856
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3
Dillon Lee
 
Change to oop formatimport java.util.Scanner;import java.io.;.pdf
Change to oop formatimport java.util.Scanner;import java.io.;.pdfChange to oop formatimport java.util.Scanner;import java.io.;.pdf
Change to oop formatimport java.util.Scanner;import java.io.;.pdf
MAYANKBANSAL1981
 
- the modification will be done in Main class- first, asks the use.pdf
- the modification will be done in Main class- first, asks the use.pdf- the modification will be done in Main class- first, asks the use.pdf
- the modification will be done in Main class- first, asks the use.pdf
hanumanparsadhsr
 
Tmpj3 01 201181102muhammad_tohir
Tmpj3 01 201181102muhammad_tohirTmpj3 01 201181102muhammad_tohir
Tmpj3 01 201181102muhammad_tohir
pencari buku
 
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdfJAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
calderoncasto9163
 
Procedure to create_the_calculator_application java
Procedure to create_the_calculator_application javaProcedure to create_the_calculator_application java
Procedure to create_the_calculator_application java
gthe
 
C++ project
C++ projectC++ project
C++ project
Sonu S S
 

More from fathimafancy (20)

Write the program segment necessary to Test the C flag. i. If the .pdf
Write the program segment necessary to  Test the C flag.  i. If the .pdfWrite the program segment necessary to  Test the C flag.  i. If the .pdf
Write the program segment necessary to Test the C flag. i. If the .pdf
fathimafancy
 
Why must Group IV be treated with (NH4)2CO3 in basic solution What .pdf
Why must Group IV be treated with (NH4)2CO3 in basic solution What .pdfWhy must Group IV be treated with (NH4)2CO3 in basic solution What .pdf
Why must Group IV be treated with (NH4)2CO3 in basic solution What .pdf
fathimafancy
 
what is IOT what us SolutionAns. IOT stands for Internet of Th.pdf
what is IOT what us SolutionAns. IOT stands for Internet of Th.pdfwhat is IOT what us SolutionAns. IOT stands for Internet of Th.pdf
what is IOT what us SolutionAns. IOT stands for Internet of Th.pdf
fathimafancy
 
What is the difference between a BSS and a ESSSolutionBSS sta.pdf
What is the difference between a BSS and a ESSSolutionBSS sta.pdfWhat is the difference between a BSS and a ESSSolutionBSS sta.pdf
What is the difference between a BSS and a ESSSolutionBSS sta.pdf
fathimafancy
 
What is the role of capsid and nucleocapsid proteins during the life.pdf
What is the role of capsid and nucleocapsid proteins during the life.pdfWhat is the role of capsid and nucleocapsid proteins during the life.pdf
What is the role of capsid and nucleocapsid proteins during the life.pdf
fathimafancy
 
What distinguish between managerial and financial accounting as to (.pdf
What distinguish between managerial and financial accounting as to (.pdfWhat distinguish between managerial and financial accounting as to (.pdf
What distinguish between managerial and financial accounting as to (.pdf
fathimafancy
 
There is a lack of spirituality in a person that cheats because they.pdf
There is a lack of spirituality in a person that cheats because they.pdfThere is a lack of spirituality in a person that cheats because they.pdf
There is a lack of spirituality in a person that cheats because they.pdf
fathimafancy
 
select the answer a general search engine differs from a subject di.pdf
select the answer a general search engine differs from a subject di.pdfselect the answer a general search engine differs from a subject di.pdf
select the answer a general search engine differs from a subject di.pdf
fathimafancy
 
State briefly what functions an Engineering Services Department in a.pdf
State briefly what functions an Engineering Services Department in a.pdfState briefly what functions an Engineering Services Department in a.pdf
State briefly what functions an Engineering Services Department in a.pdf
fathimafancy
 
Satellites in geosynchronous orbit have the desirable property of re.pdf
Satellites in geosynchronous orbit have the desirable property of re.pdfSatellites in geosynchronous orbit have the desirable property of re.pdf
Satellites in geosynchronous orbit have the desirable property of re.pdf
fathimafancy
 
Research and discuss an incident where it was discovered that a Remo.pdf
Research and discuss an incident where it was discovered that a Remo.pdfResearch and discuss an incident where it was discovered that a Remo.pdf
Research and discuss an incident where it was discovered that a Remo.pdf
fathimafancy
 
Please review the attached casescenario. You are Bill. Feel free to.pdf
Please review the attached casescenario. You are Bill. Feel free to.pdfPlease review the attached casescenario. You are Bill. Feel free to.pdf
Please review the attached casescenario. You are Bill. Feel free to.pdf
fathimafancy
 
Please make sure it works Ive been struggling with this and so far.pdf
Please make sure it works Ive been struggling with this and so far.pdfPlease make sure it works Ive been struggling with this and so far.pdf
Please make sure it works Ive been struggling with this and so far.pdf
fathimafancy
 
Please explain the physiological mechanism for enlarged lymph nodes..pdf
Please explain the physiological mechanism for enlarged lymph nodes..pdfPlease explain the physiological mechanism for enlarged lymph nodes..pdf
Please explain the physiological mechanism for enlarged lymph nodes..pdf
fathimafancy
 
multiple choiceAssuming that the probability for each shot is .pdf
multiple choiceAssuming that the probability for each shot is .pdfmultiple choiceAssuming that the probability for each shot is .pdf
multiple choiceAssuming that the probability for each shot is .pdf
fathimafancy
 
Mathematical Statistics.....Could answer be typed (is there any link.pdf
Mathematical Statistics.....Could answer be typed (is there any link.pdfMathematical Statistics.....Could answer be typed (is there any link.pdf
Mathematical Statistics.....Could answer be typed (is there any link.pdf
fathimafancy
 
Modify the Stack class given in the book in order for it to store do.pdf
Modify the Stack class given in the book in order for it to store do.pdfModify the Stack class given in the book in order for it to store do.pdf
Modify the Stack class given in the book in order for it to store do.pdf
fathimafancy
 
Let V be a finite dimensional vector space over F with T element (V,.pdf
Let V be a finite dimensional vector space over F with T element  (V,.pdfLet V be a finite dimensional vector space over F with T element  (V,.pdf
Let V be a finite dimensional vector space over F with T element (V,.pdf
fathimafancy
 
In the follwoing double bond hydration reaction styrene + water (so.pdf
In the follwoing double bond hydration reaction styrene + water (so.pdfIn the follwoing double bond hydration reaction styrene + water (so.pdf
In the follwoing double bond hydration reaction styrene + water (so.pdf
fathimafancy
 
Indicate whether each of the following items is an asset, liability,.pdf
Indicate whether each of the following items is an asset, liability,.pdfIndicate whether each of the following items is an asset, liability,.pdf
Indicate whether each of the following items is an asset, liability,.pdf
fathimafancy
 
Write the program segment necessary to Test the C flag. i. If the .pdf
Write the program segment necessary to  Test the C flag.  i. If the .pdfWrite the program segment necessary to  Test the C flag.  i. If the .pdf
Write the program segment necessary to Test the C flag. i. If the .pdf
fathimafancy
 
Why must Group IV be treated with (NH4)2CO3 in basic solution What .pdf
Why must Group IV be treated with (NH4)2CO3 in basic solution What .pdfWhy must Group IV be treated with (NH4)2CO3 in basic solution What .pdf
Why must Group IV be treated with (NH4)2CO3 in basic solution What .pdf
fathimafancy
 
what is IOT what us SolutionAns. IOT stands for Internet of Th.pdf
what is IOT what us SolutionAns. IOT stands for Internet of Th.pdfwhat is IOT what us SolutionAns. IOT stands for Internet of Th.pdf
what is IOT what us SolutionAns. IOT stands for Internet of Th.pdf
fathimafancy
 
What is the difference between a BSS and a ESSSolutionBSS sta.pdf
What is the difference between a BSS and a ESSSolutionBSS sta.pdfWhat is the difference between a BSS and a ESSSolutionBSS sta.pdf
What is the difference between a BSS and a ESSSolutionBSS sta.pdf
fathimafancy
 
What is the role of capsid and nucleocapsid proteins during the life.pdf
What is the role of capsid and nucleocapsid proteins during the life.pdfWhat is the role of capsid and nucleocapsid proteins during the life.pdf
What is the role of capsid and nucleocapsid proteins during the life.pdf
fathimafancy
 
What distinguish between managerial and financial accounting as to (.pdf
What distinguish between managerial and financial accounting as to (.pdfWhat distinguish between managerial and financial accounting as to (.pdf
What distinguish between managerial and financial accounting as to (.pdf
fathimafancy
 
There is a lack of spirituality in a person that cheats because they.pdf
There is a lack of spirituality in a person that cheats because they.pdfThere is a lack of spirituality in a person that cheats because they.pdf
There is a lack of spirituality in a person that cheats because they.pdf
fathimafancy
 
select the answer a general search engine differs from a subject di.pdf
select the answer a general search engine differs from a subject di.pdfselect the answer a general search engine differs from a subject di.pdf
select the answer a general search engine differs from a subject di.pdf
fathimafancy
 
State briefly what functions an Engineering Services Department in a.pdf
State briefly what functions an Engineering Services Department in a.pdfState briefly what functions an Engineering Services Department in a.pdf
State briefly what functions an Engineering Services Department in a.pdf
fathimafancy
 
Satellites in geosynchronous orbit have the desirable property of re.pdf
Satellites in geosynchronous orbit have the desirable property of re.pdfSatellites in geosynchronous orbit have the desirable property of re.pdf
Satellites in geosynchronous orbit have the desirable property of re.pdf
fathimafancy
 
Research and discuss an incident where it was discovered that a Remo.pdf
Research and discuss an incident where it was discovered that a Remo.pdfResearch and discuss an incident where it was discovered that a Remo.pdf
Research and discuss an incident where it was discovered that a Remo.pdf
fathimafancy
 
Please review the attached casescenario. You are Bill. Feel free to.pdf
Please review the attached casescenario. You are Bill. Feel free to.pdfPlease review the attached casescenario. You are Bill. Feel free to.pdf
Please review the attached casescenario. You are Bill. Feel free to.pdf
fathimafancy
 
Please make sure it works Ive been struggling with this and so far.pdf
Please make sure it works Ive been struggling with this and so far.pdfPlease make sure it works Ive been struggling with this and so far.pdf
Please make sure it works Ive been struggling with this and so far.pdf
fathimafancy
 
Please explain the physiological mechanism for enlarged lymph nodes..pdf
Please explain the physiological mechanism for enlarged lymph nodes..pdfPlease explain the physiological mechanism for enlarged lymph nodes..pdf
Please explain the physiological mechanism for enlarged lymph nodes..pdf
fathimafancy
 
multiple choiceAssuming that the probability for each shot is .pdf
multiple choiceAssuming that the probability for each shot is .pdfmultiple choiceAssuming that the probability for each shot is .pdf
multiple choiceAssuming that the probability for each shot is .pdf
fathimafancy
 
Mathematical Statistics.....Could answer be typed (is there any link.pdf
Mathematical Statistics.....Could answer be typed (is there any link.pdfMathematical Statistics.....Could answer be typed (is there any link.pdf
Mathematical Statistics.....Could answer be typed (is there any link.pdf
fathimafancy
 
Modify the Stack class given in the book in order for it to store do.pdf
Modify the Stack class given in the book in order for it to store do.pdfModify the Stack class given in the book in order for it to store do.pdf
Modify the Stack class given in the book in order for it to store do.pdf
fathimafancy
 
Let V be a finite dimensional vector space over F with T element (V,.pdf
Let V be a finite dimensional vector space over F with T element  (V,.pdfLet V be a finite dimensional vector space over F with T element  (V,.pdf
Let V be a finite dimensional vector space over F with T element (V,.pdf
fathimafancy
 
In the follwoing double bond hydration reaction styrene + water (so.pdf
In the follwoing double bond hydration reaction styrene + water (so.pdfIn the follwoing double bond hydration reaction styrene + water (so.pdf
In the follwoing double bond hydration reaction styrene + water (so.pdf
fathimafancy
 
Indicate whether each of the following items is an asset, liability,.pdf
Indicate whether each of the following items is an asset, liability,.pdfIndicate whether each of the following items is an asset, liability,.pdf
Indicate whether each of the following items is an asset, liability,.pdf
fathimafancy
 
Ad

Recently uploaded (20)

One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Grade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable WorksheetGrade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable Worksheet
Sritoma Majumder
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
Contact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: OptometryContact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: Optometry
MushahidRaza8
 
Real GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for SuccessReal GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for Success
Mark Soia
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
Engage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdfEngage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdf
TechSoup
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...
Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...
Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...
National Information Standards Organization (NISO)
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFAExercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Grade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable WorksheetGrade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable Worksheet
Sritoma Majumder
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Contact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: OptometryContact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: Optometry
MushahidRaza8
 
Real GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for SuccessReal GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for Success
Mark Soia
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Engage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdfEngage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdf
TechSoup
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFAExercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
Ad

Java programI made this Account.java below. Using the attached cod.pdf

  • 1. Java program I made this Account.java below. Using the attached code I need help with 10.7 (Game: ATM machine) Use the Account class created in Programming Exercise 9.7 to simulate an ATM machine. Create ten accounts in an array with id 0, 1, . . . , 9, and initial balance $100. The system prompts the user to enter an id. If the id is entered incorrectly, ask the user to enter a correct id. Once an id is accepted, the main menu is displayed as shown in the sample run. You can enter a choice 1 for viewing the current balance, 2 for withdrawing money, 3 for depositing money, and 4 for exiting the main menu. Once you exit, the system will prompt for an id again. Thus, once the system starts, it will not stop. */ import java.util.Date; public class Account { /** * @param args */ private int id=0; private double balance=0; private double annualIntrestRate=0; private Date dateCreated; public Account() { super(); } public Account(int id, double balance) { super(); this.id = id; this.balance = balance;
  • 2. } public int getId() { 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 getAnnualIntrestRate() { return annualIntrestRate;
  • 3. } public void setAnnualIntrestRate(double annualIntrestRate) { this.annualIntrestRate = annualIntrestRate; } public Date getDateCreated() { return dateCreated; } public void setDateCreated(Date dateCreated) { this.dateCreated = dateCreated; } public double getMonthlyInterestRate() { return (this.getAnnualIntrestRate()/12); } public double getMonthlyInterest() { return (getBalance() *getMonthlyInterestRate()/100); } public double withDraw(double balance) { this.setBalance(this.getBalance()-balance); return this.getBalance(); } public double diposite(double balance)
  • 4. { this.setBalance(this.getBalance()+balance); return this.getBalance(); } public double totalBalance() { balance =balance + getMonthlyInterest(); return balance; } } //AccountTest.java import java.util.Calendar; import java.util.Date; import java.util.Scanner; public class AccountTest { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc=new Scanner(System.in); Account ac=new Account(1,5000.00); System.out.println("Enter the annual intrest rate"); double intrestRate=sc.nextDouble(); ac.setAnnualIntrestRate(intrestRate); Date d=new Date(); Calendar currentDate = Calendar.getInstance(); ac.setDateCreated(currentDate.getTime()); System.out.println("Date id "+ac.getDateCreated()); System.out.println("Monthly intrest rate is :"+ac.getMonthlyInterestRate()); System.out.println("Monthly intrest is :"+ac.getMonthlyInterest()); System.out.println("Enter Amount for diposite "); double dipositeAmount=sc.nextDouble(); System.out.println("The amount after diposite is :"+ac.diposite(dipositeAmount));
  • 5. System.out.println("Enter Amount to withdraw :"); double withdramount= sc.nextDouble(); System.out.println("The amount remain after with draw "+ac.withDraw(withdramount)); System.out.println("The total amount is "+ac.totalBalance()); } } /** Sample output : Enter the annual intrest rate 2.5 Date id Thu Mar 07 04:55:38 IST 2013 Monthly intrest rate is :0.208 Monthly intrest is :10.42 Enter Amount for diposite 300 The amount after diposite is :5300.0 Enter Amount to withdraw : 3000 The amount remain after with draw 2300.0 The total amount is 2304.79 */ Solution //Account.java //Account represents the object of Account class import java.util.Date; public class Account { /** * @param args */
  • 6. private int id=0; private double balance=0; private double annualIntrestRate=0; private Date dateCreated; public Account() { super(); } public Account(int id, double balance) { super(); this.id = id; this.balance = balance; } public int getId() { 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 getAnnualIntrestRate() { return annualIntrestRate; } public void setAnnualIntrestRate(double annualIntrestRate) { this.annualIntrestRate = annualIntrestRate; } public Date getDateCreated() { return dateCreated; } public void setDateCreated(Date dateCreated) { this.dateCreated = dateCreated; }
  • 7. public double getMonthlyInterestRate() { return (this.getAnnualIntrestRate()/12); } public double getMonthlyInterest() { return (getBalance() *getMonthlyInterestRate()/100); } public double withDraw(double balance) { this.setBalance(this.getBalance()-balance); return this.getBalance(); } public double diposite(double balance) { this.setBalance(this.getBalance()+balance); return this.getBalance(); } public double totalBalance() { balance =balance + getMonthlyInterest(); return balance; } } -------------------------------------------------------------------------------------------------------------------- ---- /** * The java program ATMSimulation that prompts user to enter * an id number and re prompt if user id is not valid. * Then prints the display menu that contains user choices. * Then prints the correspoding output. Then repeats the * menu. * */ //ATMSimulation.java import java.util.Scanner; public class ATMSimulation {
  • 8. public static void main(String[] args) { //declare an array of type Account of size=10 final int SIZE=10; Account[] accts=new Account[SIZE]; //set id and amount for (int id = 0; id < accts.length; id++) { accts[id]=new Account(id, 100.0); } Scanner scan=new Scanner(System.in); int userId; boolean repeat=true; //Run the program while(true) { do { //promot for user id System.out.println("Enter your id number [0-9]: "); userId=scan.nextInt(); if(userId<0 || userId>10) System.out.println("Invalid id number."); }while(userId<0 || userId>10); //Get account into holder object Account holder=accts[userId]; double amt=0; repeat=true; //repeat until user enter 4 to stop while(repeat) { int choice=menu(); switch(choice) { case 1: System.out.println("Balance : "+holder.totalBalance());
  • 9. break; case 2: System.out.println("Enter amount to withdraw :"); amt=scan.nextDouble(); holder.withDraw(amt); break; case 3: System.out.println("Enter amount to deposit :"); amt=scan.nextDouble(); holder.diposite(amt); break; case 4: repeat=false; break; } } } } //Method menu display a menu of choices to users to select private static int menu() { Scanner scan=new Scanner(System.in); int choice; do { System.out.println("1.Viewcurrent balance"); System.out.println("2.Withdrawing money"); System.out.println("3.Depositing money"); System.out.println("4.Exit menu."); choice=scan.nextInt(); if(choice<0 || choice>4) System.out.println("Invalid choice"); }while(choice<0 || choice>4); return choice; }
  • 10. } -------------------------------------------------------------------------------------------------------------------- ---- Output: Enter your id number : 1 1.Viewcurrent balance 2.Withdrawing money 3.Depositing money 4.Exit menu. 1 Balance : 100.0 1.Viewcurrent balance 2.Withdrawing money 3.Depositing money 4.Exit menu. 3 Enter amount to deposit : 2500 1.Viewcurrent balance 2.Withdrawing money 3.Depositing money 4.Exit menu. 4 Enter your id number : 5 1.Viewcurrent balance 2.Withdrawing money 3.Depositing money 4.Exit menu. 1 Balance : 100.0 1.Viewcurrent balance 2.Withdrawing money 3.Depositing money 4.Exit menu.
  • 11. 5 Invalid choice 1.Viewcurrent balance 2.Withdrawing money 3.Depositing money 4.Exit menu.