SlideShare a Scribd company logo
1 of 8
Download to read offline
I need help creating a basic and simple Java program. Here is the exercise. I have included my
Account class that is referred to at the bottom, below the exercise.
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. You will need to cntrl-c to stop your program; this is ok for this
assignment. If you want your program to terminate more elegantly you can add in additional
logic, but this is not required.
Please refer to textbook for sample output pg. 401.
Account.java
import java.util.Date;
public class Account {
private int id;
private double balance;
static private double annualInterestRate = 0;
private Date dateCreated;
public Account() {
dateCreated = new Date();
}
public Account(int id, double balance) {
this.id = id;
this.balance = balance;
dateCreated = new Date();
}
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 static double getAnnualInterestRate() {
return annualInterestRate;
}
public static void setAnnualInterestRate(double annualInterestRate) {
Account.annualInterestRate = annualInterestRate;
}
public Date getDateCreated() {
return dateCreated;
}
public double getMonthlyInterestRate() {
double monthlyInterestRate = getAnnualInterestRate() / 1200;
return monthlyInterestRate;
}
public double getMonthlyInterest() {
double monthlyInterest= getBalance() * getMonthlyInterestRate();
return monthlyInterest;
}
public void withdraw(double amount) {
balance = getBalance() - amount;
}
public void deposit(double amount) {
balance = getBalance() + amount;
}
}
Solution
//This is your Account Class
package com.ATMBanking;
import java.util.Date;
public class Account {
private int id;
private double balance;
static private double annualInterestRate = 0;
private Date dateCreated;
public Account() {
dateCreated = new Date();
}
public Account(int id, double balance) {
this.id = id;
this.balance = balance;
dateCreated = new Date();
}
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 static double getAnnualInterestRate() {
return annualInterestRate;
}
public static void setAnnualInterestRate(double annualInterestRate) {
Account.annualInterestRate = annualInterestRate;
}
public Date getDateCreated() {
return dateCreated;
}
public double getMonthlyInterestRate() {
double monthlyInterestRate = getAnnualInterestRate() / 1200;
return monthlyInterestRate;
}
public double getMonthlyInterest() {
double monthlyInterest= getBalance() * getMonthlyInterestRate();
return monthlyInterest;
}
public void withdraw(double amount) {
balance = getBalance() - amount;
}
public void deposit(double amount) {
balance = getBalance() + amount;
}
}
//This is your UserTest Class
package com.ATMBanking;
import java.util.ArrayList;
import java.util.Scanner;
import javax.swing.text.html.HTMLDocument.Iterator;
public class UserTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList al=new ArrayList();
Account a1= new Account(1,100);
Account a2= new Account(2,100);
Account a3= new Account(3,100);
Account a4= new Account(4,100);
Account a5= new Account(5,100);
Account a6= new Account(6,100);
Account a7= new Account(7,100);
Account a8= new Account(8,100);
Account a9= new Account(9,100);
Account a10= new Account(10,100);
al.add(a1);
al.add(a2);
al.add(a3);
al.add(a4);
al.add(a5);
al.add(a6);
al.add(a7);
al.add(a8);
al.add(a9);
al.add(a10);
//Account a=null;
while(true){
Scanner sc=new Scanner(System.in);
System.out.print(" Enter Account no.:");
int acc = sc.nextInt();
int val;
Account aa;
if(acc<=10){
System.out.println(" Account Operations ");
System.out.println("Enter 1 for viewing the current balance");
System.out.println("Enter 2 for withdrawing money");
System.out.println("Enter 3 for depositing money");
System.out.println("Enter 4 to Exit");
//System.out.print("Enter your choice [1,2,3 & 4]: ");
while(true){
int amount;
System.out.print(" Enter your choice [1,2,3 & 4]: ");
int choice = sc.nextInt();
switch (choice)
{
case 1 :
aa=al.get(acc);
System.out.print("Your Balance is: "+aa.getBalance());;
break;
case 2 :
System.out.print("Enter the withdraw Amount: ");
amount =sc.nextInt();
aa=al.get(acc);
aa.withdraw(amount);
break;
case 3 :
System.out.print("Enter the Deposite Amount: ");
amount =sc.nextInt();
aa=al.get(acc);
aa.deposit(amount);;
/*for(Student stu:al){
stu.getDisplay();
}
*/
break;
case 4 :
//System.out.println("Bye....THANK YOU");
//System.exit(0);
break;
default :
System.out.println("Wrong Entry  ");
break;
}
if(choice==4){
System.out.println("Bye....THANK YOU");
break;
}//break;
}
}else{
System.out.println("Please enter valid Account number");
}
}
}
}
Output:
Enter Account no.:1
Account Operations
Enter 1 for viewing the current balance
Enter 2 for withdrawing money
Enter 3 for depositing money
Enter 4 to Exit
Enter your choice [1,2,3 & 4]: 1
Your Balance is: 100.0
Enter your choice [1,2,3 & 4]: 3
Enter the Deposite Amount: 400
Enter your choice [1,2,3 & 4]: 1
Your Balance is: 500.0
Enter your choice [1,2,3 & 4]: 4
Bye....THANK YOU
Enter Account no.:2
Account Operations
Enter 1 for viewing the current balance
Enter 2 for withdrawing money
Enter 3 for depositing money
Enter 4 to Exit
Enter your choice [1,2,3 & 4]: 1
Your Balance is: 100.0
Enter your choice [1,2,3 & 4]: 3
Enter the Deposite Amount: 300
Enter your choice [1,2,3 & 4]: 4
Bye....THANK YOU
Enter Account no.:1
Account Operations
Enter 1 for viewing the current balance
Enter 2 for withdrawing money
Enter 3 for depositing money
Enter 4 to Exit
Enter your choice [1,2,3 & 4]: 1
Your Balance is: 500.0
Enter your choice [1,2,3 & 4]: 2
Enter the withdraw Amount: 200
Enter your choice [1,2,3 & 4]: 1
Your Balance is: 300.0
Enter your choice [1,2,3 & 4]: 4
Bye....THANK YOU
Enter Account no.:11
Please enter valid Account number
Enter Account no.:

More Related Content

Similar to I need help creating a basic and simple Java program. Here is the ex.pdf

public class NegativeAmountException extends Exception {    .pdf
public class NegativeAmountException extends Exception {     .pdfpublic class NegativeAmountException extends Exception {     .pdf
public class NegativeAmountException extends Exception {    .pdfARYAN20071
 
1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the orgAbbyWhyte974
 
1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the orgMartineMccracken314
 
C# Programming. Using methods to call results to display. The code i.pdf
C# Programming. Using methods to call results to display. The code i.pdfC# Programming. Using methods to call results to display. The code i.pdf
C# Programming. Using methods to call results to display. The code i.pdffatoryoutlets
 
Can you fix the problem with the following code #include -iostream- #.pdf
Can you fix the problem with the following code  #include -iostream- #.pdfCan you fix the problem with the following code  #include -iostream- #.pdf
Can you fix the problem with the following code #include -iostream- #.pdfvinaythemodel
 
Create a new Java project and add the Account class into the source co.pdf
Create a new Java project and add the Account class into the source co.pdfCreate a new Java project and add the Account class into the source co.pdf
Create a new Java project and add the Account class into the source co.pdfadmin618513
 
Banks offer various types of accounts, such as savings, checking, cer.pdf
Banks offer various types of accounts, such as savings, checking, cer.pdfBanks offer various types of accounts, such as savings, checking, cer.pdf
Banks offer various types of accounts, such as savings, checking, cer.pdfrajeshjain2109
 
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.pdfKUNALHARCHANDANI1
 
Rajeev oops 2nd march
Rajeev oops 2nd marchRajeev oops 2nd march
Rajeev oops 2nd marchRajeev Sharan
 
IP project for class 12 cbse
IP project for class 12 cbseIP project for class 12 cbse
IP project for class 12 cbsesiddharthjha34
 
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.pdfaradhana9856
 
#include iostream #include BankAccountClass.cpp #include .pdf
#include iostream #include BankAccountClass.cpp #include .pdf#include iostream #include BankAccountClass.cpp #include .pdf
#include iostream #include BankAccountClass.cpp #include .pdfANJANEYAINTERIOURGAL
 
C++ coding for Banking System program
C++ coding for Banking System programC++ coding for Banking System program
C++ coding for Banking System programHarsh Solanki
 

Similar to I need help creating a basic and simple Java program. Here is the ex.pdf (14)

public class NegativeAmountException extends Exception {    .pdf
public class NegativeAmountException extends Exception {     .pdfpublic class NegativeAmountException extends Exception {     .pdf
public class NegativeAmountException extends Exception {    .pdf
 
1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org
 
1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org
 
C# Programming. Using methods to call results to display. The code i.pdf
C# Programming. Using methods to call results to display. The code i.pdfC# Programming. Using methods to call results to display. The code i.pdf
C# Programming. Using methods to call results to display. The code i.pdf
 
Can you fix the problem with the following code #include -iostream- #.pdf
Can you fix the problem with the following code  #include -iostream- #.pdfCan you fix the problem with the following code  #include -iostream- #.pdf
Can you fix the problem with the following code #include -iostream- #.pdf
 
Create a new Java project and add the Account class into the source co.pdf
Create a new Java project and add the Account class into the source co.pdfCreate a new Java project and add the Account class into the source co.pdf
Create a new Java project and add the Account class into the source co.pdf
 
Banks offer various types of accounts, such as savings, checking, cer.pdf
Banks offer various types of accounts, such as savings, checking, cer.pdfBanks offer various types of accounts, such as savings, checking, cer.pdf
Banks offer various types of accounts, such as savings, checking, cer.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
 
Rajeev oops 2nd march
Rajeev oops 2nd marchRajeev oops 2nd march
Rajeev oops 2nd march
 
IP project for class 12 cbse
IP project for class 12 cbseIP project for class 12 cbse
IP project for class 12 cbse
 
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
 
#include iostream #include BankAccountClass.cpp #include .pdf
#include iostream #include BankAccountClass.cpp #include .pdf#include iostream #include BankAccountClass.cpp #include .pdf
#include iostream #include BankAccountClass.cpp #include .pdf
 
C++ coding for Banking System program
C++ coding for Banking System programC++ coding for Banking System program
C++ coding for Banking System program
 
Inheritance
InheritanceInheritance
Inheritance
 

More from rajeshjangid1865

write Ocaml programe to add all numbers in a list the solution .pdf
write Ocaml programe to add all numbers in a list the solution .pdfwrite Ocaml programe to add all numbers in a list the solution .pdf
write Ocaml programe to add all numbers in a list the solution .pdfrajeshjangid1865
 
why is lifelong learning important for Engineers Give an example to.pdf
why is lifelong learning important for Engineers Give an example to.pdfwhy is lifelong learning important for Engineers Give an example to.pdf
why is lifelong learning important for Engineers Give an example to.pdfrajeshjangid1865
 
Which of the following is true of aldol reactions1.The thermodyna.pdf
Which of the following is true of aldol reactions1.The thermodyna.pdfWhich of the following is true of aldol reactions1.The thermodyna.pdf
Which of the following is true of aldol reactions1.The thermodyna.pdfrajeshjangid1865
 
Using at least two examples (whenever applicable), concisely discuss .pdf
Using at least two examples (whenever applicable), concisely discuss .pdfUsing at least two examples (whenever applicable), concisely discuss .pdf
Using at least two examples (whenever applicable), concisely discuss .pdfrajeshjangid1865
 
Transforming Cultures from Consumerism to Sustainability - Essay.pdf
Transforming Cultures from Consumerism to Sustainability - Essay.pdfTransforming Cultures from Consumerism to Sustainability - Essay.pdf
Transforming Cultures from Consumerism to Sustainability - Essay.pdfrajeshjangid1865
 
Trane has 145 marbles. He gives 20 to Katie, 52 to Gwen, and 31 to Yu.pdf
Trane has 145 marbles. He gives 20 to Katie, 52 to Gwen, and 31 to Yu.pdfTrane has 145 marbles. He gives 20 to Katie, 52 to Gwen, and 31 to Yu.pdf
Trane has 145 marbles. He gives 20 to Katie, 52 to Gwen, and 31 to Yu.pdfrajeshjangid1865
 
This project should be done in C# using Visual Studio - Windows Form.pdf
This project should be done in C# using Visual Studio - Windows Form.pdfThis project should be done in C# using Visual Studio - Windows Form.pdf
This project should be done in C# using Visual Studio - Windows Form.pdfrajeshjangid1865
 
The table below gives the probabilities of combinations of religion a.pdf
The table below gives the probabilities of combinations of religion a.pdfThe table below gives the probabilities of combinations of religion a.pdf
The table below gives the probabilities of combinations of religion a.pdfrajeshjangid1865
 
The effects Poverty in SocietySolution Poor children are at gre.pdf
The effects Poverty in SocietySolution  Poor children are at gre.pdfThe effects Poverty in SocietySolution  Poor children are at gre.pdf
The effects Poverty in SocietySolution Poor children are at gre.pdfrajeshjangid1865
 
Suppose 1.01g of FeCl3 is placed in a 10.0ml volumetric glass, water.pdf
Suppose 1.01g of FeCl3 is placed in a 10.0ml volumetric glass, water.pdfSuppose 1.01g of FeCl3 is placed in a 10.0ml volumetric glass, water.pdf
Suppose 1.01g of FeCl3 is placed in a 10.0ml volumetric glass, water.pdfrajeshjangid1865
 
Specialized regions on the cell surface through which cells are joine.pdf
Specialized regions on the cell surface through which cells are joine.pdfSpecialized regions on the cell surface through which cells are joine.pdf
Specialized regions on the cell surface through which cells are joine.pdfrajeshjangid1865
 
Section 404 of the Sarbanes Oxley Act requires auditors of a public .pdf
Section 404 of the Sarbanes Oxley Act requires auditors of a public .pdfSection 404 of the Sarbanes Oxley Act requires auditors of a public .pdf
Section 404 of the Sarbanes Oxley Act requires auditors of a public .pdfrajeshjangid1865
 
Reiji and Tuneko Okazaki conducted a now classic experiment in 1968 .pdf
Reiji and Tuneko Okazaki conducted a now classic experiment in 1968 .pdfReiji and Tuneko Okazaki conducted a now classic experiment in 1968 .pdf
Reiji and Tuneko Okazaki conducted a now classic experiment in 1968 .pdfrajeshjangid1865
 
Problem 2-1A Suppose the following items are taken from the 2017 bala.pdf
Problem 2-1A Suppose the following items are taken from the 2017 bala.pdfProblem 2-1A Suppose the following items are taken from the 2017 bala.pdf
Problem 2-1A Suppose the following items are taken from the 2017 bala.pdfrajeshjangid1865
 
Prepare a 2017 income statement for Shanta Corporation based on the f.pdf
Prepare a 2017 income statement for Shanta Corporation based on the f.pdfPrepare a 2017 income statement for Shanta Corporation based on the f.pdf
Prepare a 2017 income statement for Shanta Corporation based on the f.pdfrajeshjangid1865
 
Organizations need to have a pool of managerial talent to take on jo.pdf
Organizations need to have a pool of managerial talent to take on jo.pdfOrganizations need to have a pool of managerial talent to take on jo.pdf
Organizations need to have a pool of managerial talent to take on jo.pdfrajeshjangid1865
 
Objective Manipulate the Linked List Pointer.Make acopy of LList..pdf
Objective Manipulate the Linked List Pointer.Make acopy of LList..pdfObjective Manipulate the Linked List Pointer.Make acopy of LList..pdf
Objective Manipulate the Linked List Pointer.Make acopy of LList..pdfrajeshjangid1865
 
Militarism Alliances Imperialism Nationalism Class, the powder keg.pdf
Militarism Alliances Imperialism Nationalism Class, the powder keg.pdfMilitarism Alliances Imperialism Nationalism Class, the powder keg.pdf
Militarism Alliances Imperialism Nationalism Class, the powder keg.pdfrajeshjangid1865
 
In the subject of cryptography, what policy or organizational challe.pdf
In the subject of cryptography, what policy or organizational challe.pdfIn the subject of cryptography, what policy or organizational challe.pdf
In the subject of cryptography, what policy or organizational challe.pdfrajeshjangid1865
 
is Google making us stupid Nicholas Carr Summarize Article. https.pdf
is Google making us stupid Nicholas Carr Summarize Article. https.pdfis Google making us stupid Nicholas Carr Summarize Article. https.pdf
is Google making us stupid Nicholas Carr Summarize Article. https.pdfrajeshjangid1865
 

More from rajeshjangid1865 (20)

write Ocaml programe to add all numbers in a list the solution .pdf
write Ocaml programe to add all numbers in a list the solution .pdfwrite Ocaml programe to add all numbers in a list the solution .pdf
write Ocaml programe to add all numbers in a list the solution .pdf
 
why is lifelong learning important for Engineers Give an example to.pdf
why is lifelong learning important for Engineers Give an example to.pdfwhy is lifelong learning important for Engineers Give an example to.pdf
why is lifelong learning important for Engineers Give an example to.pdf
 
Which of the following is true of aldol reactions1.The thermodyna.pdf
Which of the following is true of aldol reactions1.The thermodyna.pdfWhich of the following is true of aldol reactions1.The thermodyna.pdf
Which of the following is true of aldol reactions1.The thermodyna.pdf
 
Using at least two examples (whenever applicable), concisely discuss .pdf
Using at least two examples (whenever applicable), concisely discuss .pdfUsing at least two examples (whenever applicable), concisely discuss .pdf
Using at least two examples (whenever applicable), concisely discuss .pdf
 
Transforming Cultures from Consumerism to Sustainability - Essay.pdf
Transforming Cultures from Consumerism to Sustainability - Essay.pdfTransforming Cultures from Consumerism to Sustainability - Essay.pdf
Transforming Cultures from Consumerism to Sustainability - Essay.pdf
 
Trane has 145 marbles. He gives 20 to Katie, 52 to Gwen, and 31 to Yu.pdf
Trane has 145 marbles. He gives 20 to Katie, 52 to Gwen, and 31 to Yu.pdfTrane has 145 marbles. He gives 20 to Katie, 52 to Gwen, and 31 to Yu.pdf
Trane has 145 marbles. He gives 20 to Katie, 52 to Gwen, and 31 to Yu.pdf
 
This project should be done in C# using Visual Studio - Windows Form.pdf
This project should be done in C# using Visual Studio - Windows Form.pdfThis project should be done in C# using Visual Studio - Windows Form.pdf
This project should be done in C# using Visual Studio - Windows Form.pdf
 
The table below gives the probabilities of combinations of religion a.pdf
The table below gives the probabilities of combinations of religion a.pdfThe table below gives the probabilities of combinations of religion a.pdf
The table below gives the probabilities of combinations of religion a.pdf
 
The effects Poverty in SocietySolution Poor children are at gre.pdf
The effects Poverty in SocietySolution  Poor children are at gre.pdfThe effects Poverty in SocietySolution  Poor children are at gre.pdf
The effects Poverty in SocietySolution Poor children are at gre.pdf
 
Suppose 1.01g of FeCl3 is placed in a 10.0ml volumetric glass, water.pdf
Suppose 1.01g of FeCl3 is placed in a 10.0ml volumetric glass, water.pdfSuppose 1.01g of FeCl3 is placed in a 10.0ml volumetric glass, water.pdf
Suppose 1.01g of FeCl3 is placed in a 10.0ml volumetric glass, water.pdf
 
Specialized regions on the cell surface through which cells are joine.pdf
Specialized regions on the cell surface through which cells are joine.pdfSpecialized regions on the cell surface through which cells are joine.pdf
Specialized regions on the cell surface through which cells are joine.pdf
 
Section 404 of the Sarbanes Oxley Act requires auditors of a public .pdf
Section 404 of the Sarbanes Oxley Act requires auditors of a public .pdfSection 404 of the Sarbanes Oxley Act requires auditors of a public .pdf
Section 404 of the Sarbanes Oxley Act requires auditors of a public .pdf
 
Reiji and Tuneko Okazaki conducted a now classic experiment in 1968 .pdf
Reiji and Tuneko Okazaki conducted a now classic experiment in 1968 .pdfReiji and Tuneko Okazaki conducted a now classic experiment in 1968 .pdf
Reiji and Tuneko Okazaki conducted a now classic experiment in 1968 .pdf
 
Problem 2-1A Suppose the following items are taken from the 2017 bala.pdf
Problem 2-1A Suppose the following items are taken from the 2017 bala.pdfProblem 2-1A Suppose the following items are taken from the 2017 bala.pdf
Problem 2-1A Suppose the following items are taken from the 2017 bala.pdf
 
Prepare a 2017 income statement for Shanta Corporation based on the f.pdf
Prepare a 2017 income statement for Shanta Corporation based on the f.pdfPrepare a 2017 income statement for Shanta Corporation based on the f.pdf
Prepare a 2017 income statement for Shanta Corporation based on the f.pdf
 
Organizations need to have a pool of managerial talent to take on jo.pdf
Organizations need to have a pool of managerial talent to take on jo.pdfOrganizations need to have a pool of managerial talent to take on jo.pdf
Organizations need to have a pool of managerial talent to take on jo.pdf
 
Objective Manipulate the Linked List Pointer.Make acopy of LList..pdf
Objective Manipulate the Linked List Pointer.Make acopy of LList..pdfObjective Manipulate the Linked List Pointer.Make acopy of LList..pdf
Objective Manipulate the Linked List Pointer.Make acopy of LList..pdf
 
Militarism Alliances Imperialism Nationalism Class, the powder keg.pdf
Militarism Alliances Imperialism Nationalism Class, the powder keg.pdfMilitarism Alliances Imperialism Nationalism Class, the powder keg.pdf
Militarism Alliances Imperialism Nationalism Class, the powder keg.pdf
 
In the subject of cryptography, what policy or organizational challe.pdf
In the subject of cryptography, what policy or organizational challe.pdfIn the subject of cryptography, what policy or organizational challe.pdf
In the subject of cryptography, what policy or organizational challe.pdf
 
is Google making us stupid Nicholas Carr Summarize Article. https.pdf
is Google making us stupid Nicholas Carr Summarize Article. https.pdfis Google making us stupid Nicholas Carr Summarize Article. https.pdf
is Google making us stupid Nicholas Carr Summarize Article. https.pdf
 

Recently uploaded

MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 

Recently uploaded (20)

MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 

I need help creating a basic and simple Java program. Here is the ex.pdf

  • 1. I need help creating a basic and simple Java program. Here is the exercise. I have included my Account class that is referred to at the bottom, below the exercise. 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. You will need to cntrl-c to stop your program; this is ok for this assignment. If you want your program to terminate more elegantly you can add in additional logic, but this is not required. Please refer to textbook for sample output pg. 401. Account.java import java.util.Date; public class Account { private int id; private double balance; static private double annualInterestRate = 0; private Date dateCreated; public Account() { dateCreated = new Date(); } public Account(int id, double balance) { this.id = id; this.balance = balance; dateCreated = new Date(); } public int getId() { return id; } public void setId(int id) { this.id = id; } public double getBalance() {
  • 2. return balance; } public void setBalance(double balance) { this.balance = balance; } public static double getAnnualInterestRate() { return annualInterestRate; } public static void setAnnualInterestRate(double annualInterestRate) { Account.annualInterestRate = annualInterestRate; } public Date getDateCreated() { return dateCreated; } public double getMonthlyInterestRate() { double monthlyInterestRate = getAnnualInterestRate() / 1200; return monthlyInterestRate; } public double getMonthlyInterest() { double monthlyInterest= getBalance() * getMonthlyInterestRate(); return monthlyInterest; } public void withdraw(double amount) { balance = getBalance() - amount; } public void deposit(double amount) { balance = getBalance() + amount; } } Solution //This is your Account Class package com.ATMBanking; import java.util.Date;
  • 3. public class Account { private int id; private double balance; static private double annualInterestRate = 0; private Date dateCreated; public Account() { dateCreated = new Date(); } public Account(int id, double balance) { this.id = id; this.balance = balance; dateCreated = new Date(); } 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 static double getAnnualInterestRate() { return annualInterestRate; } public static void setAnnualInterestRate(double annualInterestRate) { Account.annualInterestRate = annualInterestRate; } public Date getDateCreated() { return dateCreated; } public double getMonthlyInterestRate() { double monthlyInterestRate = getAnnualInterestRate() / 1200;
  • 4. return monthlyInterestRate; } public double getMonthlyInterest() { double monthlyInterest= getBalance() * getMonthlyInterestRate(); return monthlyInterest; } public void withdraw(double amount) { balance = getBalance() - amount; } public void deposit(double amount) { balance = getBalance() + amount; } } //This is your UserTest Class package com.ATMBanking; import java.util.ArrayList; import java.util.Scanner; import javax.swing.text.html.HTMLDocument.Iterator; public class UserTest { public static void main(String[] args) { // TODO Auto-generated method stub ArrayList al=new ArrayList(); Account a1= new Account(1,100); Account a2= new Account(2,100); Account a3= new Account(3,100); Account a4= new Account(4,100); Account a5= new Account(5,100); Account a6= new Account(6,100); Account a7= new Account(7,100); Account a8= new Account(8,100); Account a9= new Account(9,100); Account a10= new Account(10,100); al.add(a1);
  • 5. al.add(a2); al.add(a3); al.add(a4); al.add(a5); al.add(a6); al.add(a7); al.add(a8); al.add(a9); al.add(a10); //Account a=null; while(true){ Scanner sc=new Scanner(System.in); System.out.print(" Enter Account no.:"); int acc = sc.nextInt(); int val; Account aa; if(acc<=10){ System.out.println(" Account Operations "); System.out.println("Enter 1 for viewing the current balance"); System.out.println("Enter 2 for withdrawing money"); System.out.println("Enter 3 for depositing money"); System.out.println("Enter 4 to Exit"); //System.out.print("Enter your choice [1,2,3 & 4]: "); while(true){ int amount; System.out.print(" Enter your choice [1,2,3 & 4]: "); int choice = sc.nextInt(); switch (choice) { case 1 : aa=al.get(acc);
  • 6. System.out.print("Your Balance is: "+aa.getBalance());; break; case 2 : System.out.print("Enter the withdraw Amount: "); amount =sc.nextInt(); aa=al.get(acc); aa.withdraw(amount); break; case 3 : System.out.print("Enter the Deposite Amount: "); amount =sc.nextInt(); aa=al.get(acc); aa.deposit(amount);; /*for(Student stu:al){ stu.getDisplay(); } */ break; case 4 : //System.out.println("Bye....THANK YOU"); //System.exit(0); break; default : System.out.println("Wrong Entry "); break; } if(choice==4){ System.out.println("Bye....THANK YOU"); break; }//break; }
  • 7. }else{ System.out.println("Please enter valid Account number"); } } } } Output: Enter Account no.:1 Account Operations Enter 1 for viewing the current balance Enter 2 for withdrawing money Enter 3 for depositing money Enter 4 to Exit Enter your choice [1,2,3 & 4]: 1 Your Balance is: 100.0 Enter your choice [1,2,3 & 4]: 3 Enter the Deposite Amount: 400 Enter your choice [1,2,3 & 4]: 1 Your Balance is: 500.0 Enter your choice [1,2,3 & 4]: 4 Bye....THANK YOU Enter Account no.:2 Account Operations Enter 1 for viewing the current balance Enter 2 for withdrawing money Enter 3 for depositing money Enter 4 to Exit Enter your choice [1,2,3 & 4]: 1 Your Balance is: 100.0 Enter your choice [1,2,3 & 4]: 3 Enter the Deposite Amount: 300 Enter your choice [1,2,3 & 4]: 4
  • 8. Bye....THANK YOU Enter Account no.:1 Account Operations Enter 1 for viewing the current balance Enter 2 for withdrawing money Enter 3 for depositing money Enter 4 to Exit Enter your choice [1,2,3 & 4]: 1 Your Balance is: 500.0 Enter your choice [1,2,3 & 4]: 2 Enter the withdraw Amount: 200 Enter your choice [1,2,3 & 4]: 1 Your Balance is: 300.0 Enter your choice [1,2,3 & 4]: 4 Bye....THANK YOU Enter Account no.:11 Please enter valid Account number Enter Account no.: