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.

More Related Content

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

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 3Dillon 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_tohirpencari 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 javagthe
 
C++ project
C++ projectC++ project
C++ project
Sonu S S
 

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
 
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
 
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
 
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
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3
 
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
 
- 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
 
Tmpj3 01 201181102muhammad_tohir
Tmpj3 01 201181102muhammad_tohirTmpj3 01 201181102muhammad_tohir
Tmpj3 01 201181102muhammad_tohir
 
07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt
 
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
 
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
 
C# labprograms
C# labprogramsC# labprograms
C# labprograms
 
C++ project
C++ projectC++ project
C++ project
 

More from 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
 

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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 

Recently uploaded

Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 

Recently uploaded (20)

Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 

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.