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

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Recently uploaded (20)

Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
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
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 

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."); } }