SlideShare a Scribd company logo
1 of 2
Modification: Write a class that calculates and displays the conversion of an entered number of
dollars into currency denominations -- 20s, 10s, 5s, and 1s. Ask the user for the amount to be
converted using a showInputDialog(). Save the class as Dollars.java.
Solution
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
class Dollars
{
public static void main(String[] args)
{
Scanner enter = new Scanner(System.in);
System.out.println("Please enter the total amount of money >> ");
double money = enter.nextDouble();
int noTwenty = (int) money / 20;
System.out.println("You have " + noTwenty + " twenty dollar bills.");
double balanceAfterTwenty = money - (noTwenty * 20);
int noTen = (int) balanceAfterTwenty / 10;
System.out.println("You have " + noTen + " ten dollar bills.");
double balanceAfterTen = money - ((noTwenty * 20) + (noTen * 10));
int noFive = (int) balanceAfterTen / 5;
System.out.println("You have " + noFive + " five dollar bills.");
double balanceAfterFive = money - ((noTwenty * 20) + (noTen * 10) + (noFive * 5));
int noOne = (int) (balanceAfterFive / 1);
System.out.println("You have " + noOne + " one dollar bills.");
}
}
Modification- Write a class that calculates and displays the conversio.docx

More Related Content

Similar to Modification- Write a class that calculates and displays the conversio.docx

I need help creating a basic and simple Java program. Here is the ex.pdf
I need help creating a basic and simple Java program. Here is the ex.pdfI need help creating a basic and simple Java program. Here is the ex.pdf
I need help creating a basic and simple Java program. Here is the ex.pdf
rajeshjangid1865
 
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdfSummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
ARORACOCKERY2111
 
Hi,I have updated the code as per your requirement. Highlighted th.pdf
Hi,I have updated the code as per your requirement. Highlighted th.pdfHi,I have updated the code as per your requirement. Highlighted th.pdf
Hi,I have updated the code as per your requirement. Highlighted th.pdf
annaindustries
 
This project calls for the modification of the DollarFormat clas.pdf
This project calls for the modification of the DollarFormat clas.pdfThis project calls for the modification of the DollarFormat clas.pdf
This project calls for the modification of the DollarFormat clas.pdf
jibinsh
 
Change to oop formatimport java.util.Scanner;import java.io.;.pdf
Change to oop formatimport java.util.Scanner;import java.io.;.pdfChange to oop formatimport java.util.Scanner;import java.io.;.pdf
Change to oop formatimport java.util.Scanner;import java.io.;.pdf
MAYANKBANSAL1981
 
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdfJAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
calderoncasto9163
 
Working With JQuery Part1
Working With JQuery Part1Working With JQuery Part1
Working With JQuery Part1
saydin_soft
 

Similar to Modification- Write a class that calculates and displays the conversio.docx (19)

I need help creating a basic and simple Java program. Here is the ex.pdf
I need help creating a basic and simple Java program. Here is the ex.pdfI need help creating a basic and simple Java program. Here is the ex.pdf
I need help creating a basic and simple Java program. Here is the ex.pdf
 
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdfSummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
 
Hi,I have updated the code as per your requirement. Highlighted th.pdf
Hi,I have updated the code as per your requirement. Highlighted th.pdfHi,I have updated the code as per your requirement. Highlighted th.pdf
Hi,I have updated the code as per your requirement. Highlighted th.pdf
 
Java Programs
Java ProgramsJava Programs
Java Programs
 
This project calls for the modification of the DollarFormat clas.pdf
This project calls for the modification of the DollarFormat clas.pdfThis project calls for the modification of the DollarFormat clas.pdf
This project calls for the modification of the DollarFormat clas.pdf
 
07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
 
Day 5
Day 5Day 5
Day 5
 
Functional Principles for OO Developers
Functional Principles for OO DevelopersFunctional Principles for OO Developers
Functional Principles for OO Developers
 
The War is Over, and JavaScript has won: Living Under the JS Regime
The War is Over, and JavaScript has won: Living Under the JS RegimeThe War is Over, and JavaScript has won: Living Under the JS Regime
The War is Over, and JavaScript has won: Living Under the JS Regime
 
Change to oop formatimport java.util.Scanner;import java.io.;.pdf
Change to oop formatimport java.util.Scanner;import java.io.;.pdfChange to oop formatimport java.util.Scanner;import java.io.;.pdf
Change to oop formatimport java.util.Scanner;import java.io.;.pdf
 
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
 
How to Vim - for beginners
How to Vim - for beginnersHow to Vim - for beginners
How to Vim - for beginners
 
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdfJAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
 
Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
 
Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
 
Intro to functional programming - Confoo
Intro to functional programming - ConfooIntro to functional programming - Confoo
Intro to functional programming - Confoo
 
Java awt
Java awtJava awt
Java awt
 
Working With JQuery Part1
Working With JQuery Part1Working With JQuery Part1
Working With JQuery Part1
 

More from keshayoon3mu

(around 100 words summary) 20 Years of Investing Based on Academic Res.docx
(around 100 words summary) 20 Years of Investing Based on Academic Res.docx(around 100 words summary) 20 Years of Investing Based on Academic Res.docx
(around 100 words summary) 20 Years of Investing Based on Academic Res.docx
keshayoon3mu
 

More from keshayoon3mu (20)

(I have tried (9-8) & (9-10) and both were wrong) Decades of overfishi.docx
(I have tried (9-8) & (9-10) and both were wrong) Decades of overfishi.docx(I have tried (9-8) & (9-10) and both were wrong) Decades of overfishi.docx
(I have tried (9-8) & (9-10) and both were wrong) Decades of overfishi.docx
 
(i) Discuss the socio-economic impact of disasters in Botswana- Identi.docx
(i) Discuss the socio-economic impact of disasters in Botswana- Identi.docx(i) Discuss the socio-economic impact of disasters in Botswana- Identi.docx
(i) Discuss the socio-economic impact of disasters in Botswana- Identi.docx
 
(i) PROTECTED VIEW Be careful-files from the Internet can contain viru.docx
(i) PROTECTED VIEW Be careful-files from the Internet can contain viru.docx(i) PROTECTED VIEW Be careful-files from the Internet can contain viru.docx
(i) PROTECTED VIEW Be careful-files from the Internet can contain viru.docx
 
(Hiot- The anits are inessformationg of nGiLO DNA- MichosiotoGre Labor.docx
(Hiot- The anits are inessformationg of nGiLO DNA- MichosiotoGre Labor.docx(Hiot- The anits are inessformationg of nGiLO DNA- MichosiotoGre Labor.docx
(Hiot- The anits are inessformationg of nGiLO DNA- MichosiotoGre Labor.docx
 
(Figure 8 &9) 7a- How does discrete growth factor (rd) affect the popu.docx
(Figure 8 &9) 7a- How does discrete growth factor (rd) affect the popu.docx(Figure 8 &9) 7a- How does discrete growth factor (rd) affect the popu.docx
(Figure 8 &9) 7a- How does discrete growth factor (rd) affect the popu.docx
 
(DuPont analysis) Dearborn Supplies has total sales of $196 million- a.docx
(DuPont analysis) Dearborn Supplies has total sales of $196 million- a.docx(DuPont analysis) Dearborn Supplies has total sales of $196 million- a.docx
(DuPont analysis) Dearborn Supplies has total sales of $196 million- a.docx
 
(Corporate income tax) Boisjoyy Productions had taxable income of $19-.docx
(Corporate income tax) Boisjoyy Productions had taxable income of $19-.docx(Corporate income tax) Boisjoyy Productions had taxable income of $19-.docx
(Corporate income tax) Boisjoyy Productions had taxable income of $19-.docx
 
(Click on the following icon in order to copy its contents into a spr.docx
(Click on the following icon  in order to copy its contents into a spr.docx(Click on the following icon  in order to copy its contents into a spr.docx
(Click on the following icon in order to copy its contents into a spr.docx
 
(around 100 words summary) 20 Years of Investing Based on Academic Res.docx
(around 100 words summary) 20 Years of Investing Based on Academic Res.docx(around 100 words summary) 20 Years of Investing Based on Academic Res.docx
(around 100 words summary) 20 Years of Investing Based on Academic Res.docx
 
(a) What is the mediat of variable x - The median of variable x is (Re.docx
(a) What is the mediat of variable x - The median of variable x is (Re.docx(a) What is the mediat of variable x - The median of variable x is (Re.docx
(a) What is the mediat of variable x - The median of variable x is (Re.docx
 
(a) Let ij-0- Show that there exists l1 such that pij(l)-0- (b) Assume.docx
(a) Let ij-0- Show that there exists l1 such that pij(l)-0- (b) Assume.docx(a) Let ij-0- Show that there exists l1 such that pij(l)-0- (b) Assume.docx
(a) Let ij-0- Show that there exists l1 such that pij(l)-0- (b) Assume.docx
 
(7-7) Boehm Incorporated is expected to pay a 51-50 per share dividend.docx
(7-7) Boehm Incorporated is expected to pay a 51-50 per share dividend.docx(7-7) Boehm Incorporated is expected to pay a 51-50 per share dividend.docx
(7-7) Boehm Incorporated is expected to pay a 51-50 per share dividend.docx
 
(54)45(0-30)5(0-40)s4.docx
(54)45(0-30)5(0-40)s4.docx(54)45(0-30)5(0-40)s4.docx
(54)45(0-30)5(0-40)s4.docx
 
(5 Points) If a variable is a pointer to a structure- then which of th.docx
(5 Points) If a variable is a pointer to a structure- then which of th.docx(5 Points) If a variable is a pointer to a structure- then which of th.docx
(5 Points) If a variable is a pointer to a structure- then which of th.docx
 
(5 Points) If a variable is a pointer to a float- then which of the fo.docx
(5 Points) If a variable is a pointer to a float- then which of the fo.docx(5 Points) If a variable is a pointer to a float- then which of the fo.docx
(5 Points) If a variable is a pointer to a float- then which of the fo.docx
 
(15pts) A-B tell the truth with probability p and lie with probability.docx
(15pts) A-B tell the truth with probability p and lie with probability.docx(15pts) A-B tell the truth with probability p and lie with probability.docx
(15pts) A-B tell the truth with probability p and lie with probability.docx
 
(4 pts) Suppose two objects are represented by the tuples (12-0-22-6).docx
(4 pts) Suppose two objects are represented by the tuples (12-0-22-6).docx(4 pts) Suppose two objects are represented by the tuples (12-0-22-6).docx
(4 pts) Suppose two objects are represented by the tuples (12-0-22-6).docx
 
(1) What is a budgetary slack- How to ensure the integrity of performa.docx
(1) What is a budgetary slack- How to ensure the integrity of performa.docx(1) What is a budgetary slack- How to ensure the integrity of performa.docx
(1) What is a budgetary slack- How to ensure the integrity of performa.docx
 
(1) Describe the causative organism in staphylococcus a scalded skin s.docx
(1) Describe the causative organism in staphylococcus a scalded skin s.docx(1) Describe the causative organism in staphylococcus a scalded skin s.docx
(1) Describe the causative organism in staphylococcus a scalded skin s.docx
 
(3 pts) Suppose that a cell undergoes meiosis in a phenotypically norm.docx
(3 pts) Suppose that a cell undergoes meiosis in a phenotypically norm.docx(3 pts) Suppose that a cell undergoes meiosis in a phenotypically norm.docx
(3 pts) Suppose that a cell undergoes meiosis in a phenotypically norm.docx
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Recently uploaded (20)

PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
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
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 

Modification- Write a class that calculates and displays the conversio.docx

  • 1. Modification: Write a class that calculates and displays the conversion of an entered number of dollars into currency denominations -- 20s, 10s, 5s, and 1s. Ask the user for the amount to be converted using a showInputDialog(). Save the class as Dollars.java. Solution /* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; class Dollars { public static void main(String[] args) { Scanner enter = new Scanner(System.in); System.out.println("Please enter the total amount of money >> "); double money = enter.nextDouble(); int noTwenty = (int) money / 20; System.out.println("You have " + noTwenty + " twenty dollar bills."); double balanceAfterTwenty = money - (noTwenty * 20); int noTen = (int) balanceAfterTwenty / 10; System.out.println("You have " + noTen + " ten dollar bills."); double balanceAfterTen = money - ((noTwenty * 20) + (noTen * 10)); int noFive = (int) balanceAfterTen / 5; System.out.println("You have " + noFive + " five dollar bills."); double balanceAfterFive = money - ((noTwenty * 20) + (noTen * 10) + (noFive * 5)); int noOne = (int) (balanceAfterFive / 1); System.out.println("You have " + noOne + " one dollar bills."); } }