SlideShare a Scribd company logo
1 of 7
Download to read offline
/**
* 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

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

Assume you have a scanner object (called input).Declare an integer.pdf
Assume you have a scanner object (called input).Declare an integer.pdfAssume you have a scanner object (called input).Declare an integer.pdf
Assume you have a scanner object (called input).Declare an integer.pdfezzi552
 
commission1Application.javacommission1Application.javaimport.docx
commission1Application.javacommission1Application.javaimport.docxcommission1Application.javacommission1Application.javaimport.docx
commission1Application.javacommission1Application.javaimport.docxmonicafrancis71118
 
The java program that prompts user to enter a string and .pdf
  The java program that prompts user to  enter a string and .pdf  The java program that prompts user to  enter a string and .pdf
The java program that prompts user to enter a string and .pdfDEEPAKSONI562
 
Digits.javapackage week04;import java.util.Scanner; public cla.pdf
Digits.javapackage week04;import java.util.Scanner; public cla.pdfDigits.javapackage week04;import java.util.Scanner; public cla.pdf
Digits.javapackage week04;import java.util.Scanner; public cla.pdfannapurnnatextailes
 
Help with Java! Can someone check my code What I am trying to accompli.docx
Help with Java! Can someone check my code What I am trying to accompli.docxHelp with Java! Can someone check my code What I am trying to accompli.docx
Help with Java! Can someone check my code What I am trying to accompli.docxgentomega
 
JAVA PROJECT REPORT.pptx
JAVA PROJECT REPORT.pptxJAVA PROJECT REPORT.pptx
JAVA PROJECT REPORT.pptxAbhiramAleti
 
JAVA Question : Programming Assignment
JAVA Question : Programming AssignmentJAVA Question : Programming Assignment
JAVA Question : Programming AssignmentCoding Assignment Help
 
Micro services from scratch - Part 1
Micro services from scratch - Part 1Micro services from scratch - Part 1
Micro services from scratch - Part 1Azrul MADISA
 
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
 
Lab101.pptx
Lab101.pptxLab101.pptx
Lab101.pptxKimVeeL
 
The java program Jumble that prompts user to enter nu.pdf
   The java program Jumble that prompts user to  enter nu.pdf   The java program Jumble that prompts user to  enter nu.pdf
The java program Jumble that prompts user to enter nu.pdfannapurnnatextailes
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfmayorothenguyenhob69
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3Dillon Lee
 
Quest 1 define a class batsman with the following specifications
Quest  1 define a class batsman with the following specificationsQuest  1 define a class batsman with the following specifications
Quest 1 define a class batsman with the following specificationsrajkumari873
 

Similar to The java program that simulates ATM operations. The prog.pdf (16)

Assume you have a scanner object (called input).Declare an integer.pdf
Assume you have a scanner object (called input).Declare an integer.pdfAssume you have a scanner object (called input).Declare an integer.pdf
Assume you have a scanner object (called input).Declare an integer.pdf
 
commission1Application.javacommission1Application.javaimport.docx
commission1Application.javacommission1Application.javaimport.docxcommission1Application.javacommission1Application.javaimport.docx
commission1Application.javacommission1Application.javaimport.docx
 
The java program that prompts user to enter a string and .pdf
  The java program that prompts user to  enter a string and .pdf  The java program that prompts user to  enter a string and .pdf
The java program that prompts user to enter a string and .pdf
 
Digits.javapackage week04;import java.util.Scanner; public cla.pdf
Digits.javapackage week04;import java.util.Scanner; public cla.pdfDigits.javapackage week04;import java.util.Scanner; public cla.pdf
Digits.javapackage week04;import java.util.Scanner; public cla.pdf
 
Help with Java! Can someone check my code What I am trying to accompli.docx
Help with Java! Can someone check my code What I am trying to accompli.docxHelp with Java! Can someone check my code What I am trying to accompli.docx
Help with Java! Can someone check my code What I am trying to accompli.docx
 
JAVA PROJECT REPORT.pptx
JAVA PROJECT REPORT.pptxJAVA PROJECT REPORT.pptx
JAVA PROJECT REPORT.pptx
 
JAVA Question : Programming Assignment
JAVA Question : Programming AssignmentJAVA Question : Programming Assignment
JAVA Question : Programming Assignment
 
Micro services from scratch - Part 1
Micro services from scratch - Part 1Micro services from scratch - Part 1
Micro services from scratch - Part 1
 
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
 
Lab101.pptx
Lab101.pptxLab101.pptx
Lab101.pptx
 
PROGRAMMING QUESTIONS.docx
PROGRAMMING QUESTIONS.docxPROGRAMMING QUESTIONS.docx
PROGRAMMING QUESTIONS.docx
 
Vo.pdf
   Vo.pdf   Vo.pdf
Vo.pdf
 
The java program Jumble that prompts user to enter nu.pdf
   The java program Jumble that prompts user to  enter nu.pdf   The java program Jumble that prompts user to  enter nu.pdf
The java program Jumble that prompts user to enter nu.pdf
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3
 
Quest 1 define a class batsman with the following specifications
Quest  1 define a class batsman with the following specificationsQuest  1 define a class batsman with the following specifications
Quest 1 define a class batsman with the following specifications
 

More from poddaranand1

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

More from poddaranand1 (20)

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

Recently uploaded

Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsNbelano25
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningMarc Dusseiller Dusjagr
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17Celine George
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesSHIVANANDaRV
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 

Recently uploaded (20)

Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food Additives
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 

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.