SlideShare a Scribd company logo
/**
* The java program that simulates ATM operations.
* The program display a menu of choices.
* The prompt to enter operation to perform
* and then print the balance after the transaction
* to console.
* */
//AtmSimDoLoop.java
import java.util.Scanner;
public class AtmSimDoLoop {
public static void main(String[] args) {
//Create a Scanner class object
Scanner scanner=new Scanner(System.in);
//declare variables
double balance=0;
int userChoice;
double deposit;
double withdrawl;
//set repeat =true
boolean repeat=true;
//prompt and repeat until user enters 4 to exit
do {
System.out.println("Enter the number of your desired transaction type.");
System.out.println("1.Balance");
System.out.println("2.Deposit");
System.out.println("3.Withdrawl");
System.out.println("4.Quit");
userChoice=Integer.parseInt(scanner.nextLine());
//using switch case to select an appropriate choice
switch (userChoice) {
case 1:
System.out.println("Your current balance is "+balance);
break;
case 2:
System.out.println("Enter the amount of the deposit ");
deposit=Double.parseDouble(scanner.nextLine());
balance+=deposit;
System.out.println("Your current balance is "+balance);
break;
case 3:
System.out.println("Enter the amount of the withdrawl ");
withdrawl=Double.parseDouble(scanner.nextLine());
if(withdrawl<=balance)
{
balance-=withdrawl;
System.out.println("Your current balance is "+balance);
}
else
System.out.println("Insufficient funds. Your current balance is "+balance+".");
break;
case 4:
System.out.println("Good-bye.");
//set repeat=false
repeat=false;
}
} while (repeat);
}//end of main
}//end of class AtmSimDoLoop
------------------------------------------------------------------------------------------------------------
Sample output:
Enter the number of your desired transaction type.
1.Balance
2.Deposit
3.Withdrawl
4.Quit
1
Your current balance is 0.0
Enter the number of your desired transaction type.
1.Balance
2.Deposit
3.Withdrawl
4.Quit
2
Enter the amount of the deposit
500
Your current balance is 500.0
Enter the number of your desired transaction type.
1.Balance
2.Deposit
3.Withdrawl
4.Quit
3
Enter the amount of the withdrawl
300
Your current balance is 200.0
Enter the number of your desired transaction type.
1.Balance
2.Deposit
3.Withdrawl
4.Quit
3
Enter the amount of the withdrawl
300
Insufficient funds. Your current balance is 200.0.
Enter the number of your desired transaction type.
1.Balance
2.Deposit
3.Withdrawl
4.Quit
4
Good-bye.
Solution
/**
* The java program that simulates ATM operations.
* The program display a menu of choices.
* The prompt to enter operation to perform
* and then print the balance after the transaction
* to console.
* */
//AtmSimDoLoop.java
import java.util.Scanner;
public class AtmSimDoLoop {
public static void main(String[] args) {
//Create a Scanner class object
Scanner scanner=new Scanner(System.in);
//declare variables
double balance=0;
int userChoice;
double deposit;
double withdrawl;
//set repeat =true
boolean repeat=true;
//prompt and repeat until user enters 4 to exit
do {
System.out.println("Enter the number of your desired transaction type.");
System.out.println("1.Balance");
System.out.println("2.Deposit");
System.out.println("3.Withdrawl");
System.out.println("4.Quit");
userChoice=Integer.parseInt(scanner.nextLine());
//using switch case to select an appropriate choice
switch (userChoice) {
case 1:
System.out.println("Your current balance is "+balance);
break;
case 2:
System.out.println("Enter the amount of the deposit ");
deposit=Double.parseDouble(scanner.nextLine());
balance+=deposit;
System.out.println("Your current balance is "+balance);
break;
case 3:
System.out.println("Enter the amount of the withdrawl ");
withdrawl=Double.parseDouble(scanner.nextLine());
if(withdrawl<=balance)
{
balance-=withdrawl;
System.out.println("Your current balance is "+balance);
}
else
System.out.println("Insufficient funds. Your current balance is "+balance+".");
break;
case 4:
System.out.println("Good-bye.");
//set repeat=false
repeat=false;
}
} while (repeat);
}//end of main
}//end of class AtmSimDoLoop
------------------------------------------------------------------------------------------------------------
Sample output:
Enter the number of your desired transaction type.
1.Balance
2.Deposit
3.Withdrawl
4.Quit
1
Your current balance is 0.0
Enter the number of your desired transaction type.
1.Balance
2.Deposit
3.Withdrawl
4.Quit
2
Enter the amount of the deposit
500
Your current balance is 500.0
Enter the number of your desired transaction type.
1.Balance
2.Deposit
3.Withdrawl
4.Quit
3
Enter the amount of the withdrawl
300
Your current balance is 200.0
Enter the number of your desired transaction type.
1.Balance
2.Deposit
3.Withdrawl
4.Quit
3
Enter the amount of the withdrawl
300
Insufficient funds. Your current balance is 200.0.
Enter the number of your desired transaction type.
1.Balance
2.Deposit
3.Withdrawl
4.Quit
4
Good-bye.

More Related Content

PPTX
ATM_Simulator_Complete_Presentation.pptx
PDF
Java programI made this Account.java below. Using the attached cod.pdf
PDF
I need help creating a basic and simple Java program. Here is the ex.pdf
PDF
The java class Account that simultes the Account class.pdf
PDF
Bank Program in JavaBelow is my code(havent finished, but it be .pdf
PPTX
ATM_Simulator_Mini_Project_Presentation.pptx
PPTX
Computer science engineering College in t
PDF
Create a new Java project and add the Account class into the source co.pdf
ATM_Simulator_Complete_Presentation.pptx
Java programI made this Account.java below. Using the attached cod.pdf
I need help creating a basic and simple Java program. Here is the ex.pdf
The java class Account that simultes the Account class.pdf
Bank Program in JavaBelow is my code(havent finished, but it be .pdf
ATM_Simulator_Mini_Project_Presentation.pptx
Computer science engineering College in t
Create a new Java project and add the Account class into the source co.pdf

More from poddaranand1 (20)

PDF
S02 is the only polar molecule as the other molec.pdf
PDF
Solve for the weight of all three, S1, O3, He1.pdf
PDF
Phenol is the strongest acid because Phenoxide io.pdf
PDF
homogeneous describes a solutionmixture that is .pdf
PDF
Propanol has molecular formula CH3-CH2-CH2-OH.It is a polar organi.pdf
PDF
From an ESR study of VOCl2 dissolved in toluene c.pdf
PDF
Wire framing is an important step in any screen design process. It i.pdf
PDF
The phase it is in is anaphase, chromosomes start to move toward the.pdf
PDF
The normal heartbeat is 60-72 per minute. The pumping of the blood f.pdf
PDF
the acronym of CIA is Central Intelligence Agency — it is an indep.pdf
PDF
Solution#includestdio.h#includeconio.h#includealloc.h.pdf
PDF
reaction of zirconium with water in water reactors releases hydrogen.pdf
PDF
D) IV So.pdf
PDF
In the addition of HX to an unsymmetrical alkene, the H atom bonds t.pdf
PDF
Inadequacy in Hartee theory1) It does not contain the exchange ter.pdf
PDF
Flash helps prevent more flash from forming.This also forces the m.pdf
PDF
Convolutional Neural Networks square measure terribly kind of like n.pdf
PDF
AnswerProject’s required return of 12 will be used as discount ra.pdf
PDF
A. Angelman syndrome is rare genetic disorder characterized by learn.pdf
PDF
1)increases decreases2)increaseFor others just use the p.pdf
S02 is the only polar molecule as the other molec.pdf
Solve for the weight of all three, S1, O3, He1.pdf
Phenol is the strongest acid because Phenoxide io.pdf
homogeneous describes a solutionmixture that is .pdf
Propanol has molecular formula CH3-CH2-CH2-OH.It is a polar organi.pdf
From an ESR study of VOCl2 dissolved in toluene c.pdf
Wire framing is an important step in any screen design process. It i.pdf
The phase it is in is anaphase, chromosomes start to move toward the.pdf
The normal heartbeat is 60-72 per minute. The pumping of the blood f.pdf
the acronym of CIA is Central Intelligence Agency — it is an indep.pdf
Solution#includestdio.h#includeconio.h#includealloc.h.pdf
reaction of zirconium with water in water reactors releases hydrogen.pdf
D) IV So.pdf
In the addition of HX to an unsymmetrical alkene, the H atom bonds t.pdf
Inadequacy in Hartee theory1) It does not contain the exchange ter.pdf
Flash helps prevent more flash from forming.This also forces the m.pdf
Convolutional Neural Networks square measure terribly kind of like n.pdf
AnswerProject’s required return of 12 will be used as discount ra.pdf
A. Angelman syndrome is rare genetic disorder characterized by learn.pdf
1)increases decreases2)increaseFor others just use the p.pdf
Ad

Recently uploaded (20)

PDF
Indian roads congress 037 - 2012 Flexible pavement
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Empowerment Technology for Senior High School Guide
PDF
Complications of Minimal Access Surgery at WLH
PDF
Classroom Observation Tools for Teachers
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PPTX
Unit 4 Skeletal System.ppt.pptxopresentatiom
PPTX
Digestion and Absorption of Carbohydrates, Proteina and Fats
PDF
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
Cell Types and Its function , kingdom of life
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Computing-Curriculum for Schools in Ghana
PDF
Supply Chain Operations Speaking Notes -ICLT Program
Indian roads congress 037 - 2012 Flexible pavement
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
Chinmaya Tiranga quiz Grand Finale.pdf
Empowerment Technology for Senior High School Guide
Complications of Minimal Access Surgery at WLH
Classroom Observation Tools for Teachers
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
Paper A Mock Exam 9_ Attempt review.pdf.
Final Presentation General Medicine 03-08-2024.pptx
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
Unit 4 Skeletal System.ppt.pptxopresentatiom
Digestion and Absorption of Carbohydrates, Proteina and Fats
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Cell Types and Its function , kingdom of life
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Computing-Curriculum for Schools in Ghana
Supply Chain Operations Speaking Notes -ICLT Program
Ad

The java program that simulates ATM operations. The prog.pdf

  • 1. /** * The java program that simulates ATM operations. * The program display a menu of choices. * The prompt to enter operation to perform * and then print the balance after the transaction * to console. * */ //AtmSimDoLoop.java import java.util.Scanner; public class AtmSimDoLoop { public static void main(String[] args) { //Create a Scanner class object Scanner scanner=new Scanner(System.in); //declare variables double balance=0; int userChoice; double deposit; double withdrawl; //set repeat =true boolean repeat=true; //prompt and repeat until user enters 4 to exit do { System.out.println("Enter the number of your desired transaction type."); System.out.println("1.Balance"); System.out.println("2.Deposit"); System.out.println("3.Withdrawl"); System.out.println("4.Quit"); userChoice=Integer.parseInt(scanner.nextLine());
  • 2. //using switch case to select an appropriate choice switch (userChoice) { case 1: System.out.println("Your current balance is "+balance); break; case 2: System.out.println("Enter the amount of the deposit "); deposit=Double.parseDouble(scanner.nextLine()); balance+=deposit; System.out.println("Your current balance is "+balance); break; case 3: System.out.println("Enter the amount of the withdrawl "); withdrawl=Double.parseDouble(scanner.nextLine()); if(withdrawl<=balance) { balance-=withdrawl; System.out.println("Your current balance is "+balance); } else System.out.println("Insufficient funds. Your current balance is "+balance+"."); break; case 4: System.out.println("Good-bye."); //set repeat=false repeat=false; } } while (repeat); }//end of main }//end of class AtmSimDoLoop ------------------------------------------------------------------------------------------------------------ Sample output: Enter the number of your desired transaction type.
  • 3. 1.Balance 2.Deposit 3.Withdrawl 4.Quit 1 Your current balance is 0.0 Enter the number of your desired transaction type. 1.Balance 2.Deposit 3.Withdrawl 4.Quit 2 Enter the amount of the deposit 500 Your current balance is 500.0 Enter the number of your desired transaction type. 1.Balance 2.Deposit 3.Withdrawl 4.Quit 3 Enter the amount of the withdrawl 300 Your current balance is 200.0 Enter the number of your desired transaction type. 1.Balance 2.Deposit 3.Withdrawl 4.Quit 3 Enter the amount of the withdrawl 300 Insufficient funds. Your current balance is 200.0. Enter the number of your desired transaction type. 1.Balance 2.Deposit
  • 4. 3.Withdrawl 4.Quit 4 Good-bye. Solution /** * The java program that simulates ATM operations. * The program display a menu of choices. * The prompt to enter operation to perform * and then print the balance after the transaction * to console. * */ //AtmSimDoLoop.java import java.util.Scanner; public class AtmSimDoLoop { public static void main(String[] args) { //Create a Scanner class object Scanner scanner=new Scanner(System.in); //declare variables double balance=0; int userChoice; double deposit; double withdrawl; //set repeat =true boolean repeat=true; //prompt and repeat until user enters 4 to exit do { System.out.println("Enter the number of your desired transaction type."); System.out.println("1.Balance");
  • 5. System.out.println("2.Deposit"); System.out.println("3.Withdrawl"); System.out.println("4.Quit"); userChoice=Integer.parseInt(scanner.nextLine()); //using switch case to select an appropriate choice switch (userChoice) { case 1: System.out.println("Your current balance is "+balance); break; case 2: System.out.println("Enter the amount of the deposit "); deposit=Double.parseDouble(scanner.nextLine()); balance+=deposit; System.out.println("Your current balance is "+balance); break; case 3: System.out.println("Enter the amount of the withdrawl "); withdrawl=Double.parseDouble(scanner.nextLine()); if(withdrawl<=balance) { balance-=withdrawl; System.out.println("Your current balance is "+balance); } else System.out.println("Insufficient funds. Your current balance is "+balance+"."); break; case 4: System.out.println("Good-bye."); //set repeat=false repeat=false; } } while (repeat);
  • 6. }//end of main }//end of class AtmSimDoLoop ------------------------------------------------------------------------------------------------------------ Sample output: Enter the number of your desired transaction type. 1.Balance 2.Deposit 3.Withdrawl 4.Quit 1 Your current balance is 0.0 Enter the number of your desired transaction type. 1.Balance 2.Deposit 3.Withdrawl 4.Quit 2 Enter the amount of the deposit 500 Your current balance is 500.0 Enter the number of your desired transaction type. 1.Balance 2.Deposit 3.Withdrawl 4.Quit 3 Enter the amount of the withdrawl 300 Your current balance is 200.0 Enter the number of your desired transaction type. 1.Balance 2.Deposit 3.Withdrawl 4.Quit 3
  • 7. Enter the amount of the withdrawl 300 Insufficient funds. Your current balance is 200.0. Enter the number of your desired transaction type. 1.Balance 2.Deposit 3.Withdrawl 4.Quit 4 Good-bye.