SlideShare a Scribd company logo
1 of 4
Download to read offline
import java.util.Scanner;
import java.math.BigInteger;
public class Money{
private int dollars;
private int cents;
public Money(){
dollars=0;
cents=0;
}
public Money(int d,int c){
dollars=d+c/100;
cents=c%100;
}
public Money(int c){
dollars=c/100;
cents=c%100;
}
public void add(int c){
cents+=c;
dollars+=cents/100;
cents=cents%100;
}
public void add(int d,int c){
cents+=c;
dollars=dollars+d+cents/100;
cents=cents%100;
}
public void remove(int c){
cents=dollars*100+cents;
if(c>cents){
cents=0;
}
else{
cents-=c;
}
dollars=cents/100;
cents=cents%100;
}
public String getMoney(){
return dollars+" dollars and "+cents+" cents";
}
public static void main(String []args){
Money h=new Money(1,75);
h.add(190);
System.out.println(h.getMoney());
}
}
Solution
import java.util.Scanner;
import java.math.BigInteger;
public class Money{
private int dollars;
private int cents;
public Money(){
dollars=0;
cents=0;
}
public Money(int d,int c){
dollars=d+c/100;
cents=c%100;
}
public Money(int c){
dollars=c/100;
cents=c%100;
}
public void add(int c){
cents+=c;
dollars+=cents/100;
cents=cents%100;
}
public void add(int d,int c){
cents+=c;
dollars=dollars+d+cents/100;
cents=cents%100;
}
public void remove(int c){
cents=dollars*100+cents;
if(c>cents){
cents=0;
}
else{
cents-=c;
}
dollars=cents/100;
cents=cents%100;
}
public String getMoney(){
return dollars+" dollars and "+cents+" cents";
}
public static void main(String []args){
Money h=new Money(1,75);
h.add(190);
System.out.println(h.getMoney());
}
}

More Related Content

Similar to import java.util.Scanner; import java.math.BigInteger; public cl.pdf

Ejercicios de programacion
Ejercicios de programacionEjercicios de programacion
Ejercicios de programacion
Jeff Tu Pechito
 
import java.util.;public class Main{public static void main(S.pdf
import java.util.;public class Main{public static void main(S.pdfimport java.util.;public class Main{public static void main(S.pdf
import java.util.;public class Main{public static void main(S.pdf
deepua8
 
Hey, looking to do the following with this programFill in the multip.pdf
Hey, looking to do the following with this programFill in the multip.pdfHey, looking to do the following with this programFill in the multip.pdf
Hey, looking to do the following with this programFill in the multip.pdf
rupeshmehta151
 
Please help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdfPlease help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdf
JUSTSTYLISH3B2MOHALI
 
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdfJAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
karymadelaneyrenne19
 

Similar to import java.util.Scanner; import java.math.BigInteger; public cl.pdf (20)

Ejercicios de programacion
Ejercicios de programacionEjercicios de programacion
Ejercicios de programacion
 
import java.util.;public class Main{public static void main(S.pdf
import java.util.;public class Main{public static void main(S.pdfimport java.util.;public class Main{public static void main(S.pdf
import java.util.;public class Main{public static void main(S.pdf
 
The Effective Developer - Work Smarter, Not Harder
The Effective Developer - Work Smarter, Not HarderThe Effective Developer - Work Smarter, Not Harder
The Effective Developer - Work Smarter, Not Harder
 
RAILWAY RESERWATION PROJECT PROGRAM
RAILWAY RESERWATION PROJECT PROGRAMRAILWAY RESERWATION PROJECT PROGRAM
RAILWAY RESERWATION PROJECT PROGRAM
 
Assignment_URI_Code_Solution_Roll_2010052 (1).pdf
Assignment_URI_Code_Solution_Roll_2010052 (1).pdfAssignment_URI_Code_Solution_Roll_2010052 (1).pdf
Assignment_URI_Code_Solution_Roll_2010052 (1).pdf
 
Hey, looking to do the following with this programFill in the multip.pdf
Hey, looking to do the following with this programFill in the multip.pdfHey, looking to do the following with this programFill in the multip.pdf
Hey, looking to do the following with this programFill in the multip.pdf
 
Railwaynew
RailwaynewRailwaynew
Railwaynew
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2
 
Ccc
CccCcc
Ccc
 
Vcs17
Vcs17Vcs17
Vcs17
 
Please help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdfPlease help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdf
 
Blocks+gcd入門
Blocks+gcd入門Blocks+gcd入門
Blocks+gcd入門
 
C++ TUTORIAL 9
C++ TUTORIAL 9C++ TUTORIAL 9
C++ TUTORIAL 9
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdfJAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
 
Caropro
CaroproCaropro
Caropro
 
Vcs5
Vcs5Vcs5
Vcs5
 

More from annucommunication1

41.Ans. Ans,Sarcoplasmic reticulumSarcoplasmic reticulum is a type.pdf
41.Ans. Ans,Sarcoplasmic reticulumSarcoplasmic reticulum is a type.pdf41.Ans. Ans,Sarcoplasmic reticulumSarcoplasmic reticulum is a type.pdf
41.Ans. Ans,Sarcoplasmic reticulumSarcoplasmic reticulum is a type.pdf
annucommunication1
 
package patienttest;import java.util.Comparator; import java..pdf
 package patienttest;import java.util.Comparator; import java..pdf package patienttest;import java.util.Comparator; import java..pdf
package patienttest;import java.util.Comparator; import java..pdf
annucommunication1
 
Eukaryotic Chromosome Structure The length of DN.pdf
                     Eukaryotic Chromosome Structure  The length of DN.pdf                     Eukaryotic Chromosome Structure  The length of DN.pdf
Eukaryotic Chromosome Structure The length of DN.pdf
annucommunication1
 
The various ways to finance a project are 1)Debt financing-One ca.pdf
The various ways to finance a project are 1)Debt financing-One ca.pdfThe various ways to finance a project are 1)Debt financing-One ca.pdf
The various ways to finance a project are 1)Debt financing-One ca.pdf
annucommunication1
 

More from annucommunication1 (20)

4r = 2 L2r = L2thats none of the above, since you didnt wrote t.pdf
4r = 2 L2r = L2thats none of the above, since you didnt wrote t.pdf4r = 2 L2r = L2thats none of the above, since you didnt wrote t.pdf
4r = 2 L2r = L2thats none of the above, since you didnt wrote t.pdf
 
41.Ans. Ans,Sarcoplasmic reticulumSarcoplasmic reticulum is a type.pdf
41.Ans. Ans,Sarcoplasmic reticulumSarcoplasmic reticulum is a type.pdf41.Ans. Ans,Sarcoplasmic reticulumSarcoplasmic reticulum is a type.pdf
41.Ans. Ans,Sarcoplasmic reticulumSarcoplasmic reticulum is a type.pdf
 
1.c. developers2.e. A and B3.c. Land and Built space4. Money a.pdf
1.c. developers2.e. A and B3.c. Land and Built space4. Money a.pdf1.c. developers2.e. A and B3.c. Land and Built space4. Money a.pdf
1.c. developers2.e. A and B3.c. Land and Built space4. Money a.pdf
 
package patienttest;import java.util.Comparator; import java..pdf
 package patienttest;import java.util.Comparator; import java..pdf package patienttest;import java.util.Comparator; import java..pdf
package patienttest;import java.util.Comparator; import java..pdf
 
ZnO + H2O = Zn(OH)2 .pdf
                     ZnO + H2O = Zn(OH)2                             .pdf                     ZnO + H2O = Zn(OH)2                             .pdf
ZnO + H2O = Zn(OH)2 .pdf
 
will result in the formation of a soluble complex.pdf
                     will result in the formation of a soluble complex.pdf                     will result in the formation of a soluble complex.pdf
will result in the formation of a soluble complex.pdf
 
What types of elements are involved in metallic b.pdf
                     What types of elements are involved in metallic b.pdf                     What types of elements are involved in metallic b.pdf
What types of elements are involved in metallic b.pdf
 
The correct statements are When two atoms of app.pdf
                     The correct statements are  When two atoms of app.pdf                     The correct statements are  When two atoms of app.pdf
The correct statements are When two atoms of app.pdf
 
Sure can There you go. .pdf
                     Sure can  There you go.                         .pdf                     Sure can  There you go.                         .pdf
Sure can There you go. .pdf
 
One P2O5 contains five oxygen 3.45 x 5 = 17.3 mol.pdf
                     One P2O5 contains five oxygen 3.45 x 5 = 17.3 mol.pdf                     One P2O5 contains five oxygen 3.45 x 5 = 17.3 mol.pdf
One P2O5 contains five oxygen 3.45 x 5 = 17.3 mol.pdf
 
Na2O is basic NO2 is acidic SO2 is acidic CO2 is .pdf
                     Na2O is basic NO2 is acidic SO2 is acidic CO2 is .pdf                     Na2O is basic NO2 is acidic SO2 is acidic CO2 is .pdf
Na2O is basic NO2 is acidic SO2 is acidic CO2 is .pdf
 
moles of CO2 = moles of NaHCO3 = 284 =0.0238 .pdf
                     moles of CO2 = moles of NaHCO3 = 284 =0.0238    .pdf                     moles of CO2 = moles of NaHCO3 = 284 =0.0238    .pdf
moles of CO2 = moles of NaHCO3 = 284 =0.0238 .pdf
 
Eukaryotic Chromosome Structure The length of DN.pdf
                     Eukaryotic Chromosome Structure  The length of DN.pdf                     Eukaryotic Chromosome Structure  The length of DN.pdf
Eukaryotic Chromosome Structure The length of DN.pdf
 
Fe + S ---- FeS moles of Fe = 9.4256 = 0.1682 m.pdf
                     Fe + S ---- FeS moles of Fe = 9.4256 = 0.1682 m.pdf                     Fe + S ---- FeS moles of Fe = 9.4256 = 0.1682 m.pdf
Fe + S ---- FeS moles of Fe = 9.4256 = 0.1682 m.pdf
 
D. is correct. Solution .pdf
                     D. is correct.  Solution                     .pdf                     D. is correct.  Solution                     .pdf
D. is correct. Solution .pdf
 
The various ways to finance a project are 1)Debt financing-One ca.pdf
The various ways to finance a project are 1)Debt financing-One ca.pdfThe various ways to finance a project are 1)Debt financing-One ca.pdf
The various ways to finance a project are 1)Debt financing-One ca.pdf
 
boiling point 1-propanol propanone note there.pdf
                     boiling point 1-propanol  propanone note there.pdf                     boiling point 1-propanol  propanone note there.pdf
boiling point 1-propanol propanone note there.pdf
 
The organs of urinary system includesPaired kidneys, paired ureter.pdf
The organs of urinary system includesPaired kidneys, paired ureter.pdfThe organs of urinary system includesPaired kidneys, paired ureter.pdf
The organs of urinary system includesPaired kidneys, paired ureter.pdf
 
The incorrect statement ise. Glucose is a stereoisomer of ribose..pdf
The incorrect statement ise. Glucose is a stereoisomer of ribose..pdfThe incorrect statement ise. Glucose is a stereoisomer of ribose..pdf
The incorrect statement ise. Glucose is a stereoisomer of ribose..pdf
 
The answer is a. The intermolecular forces are much greater in wate.pdf
The answer is a. The intermolecular forces are much greater in wate.pdfThe answer is a. The intermolecular forces are much greater in wate.pdf
The answer is a. The intermolecular forces are much greater in wate.pdf
 

Recently uploaded

SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MysoreMuleSoftMeetup
 

Recently uploaded (20)

SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 

import java.util.Scanner; import java.math.BigInteger; public cl.pdf

  • 1. import java.util.Scanner; import java.math.BigInteger; public class Money{ private int dollars; private int cents; public Money(){ dollars=0; cents=0; } public Money(int d,int c){ dollars=d+c/100; cents=c%100; } public Money(int c){ dollars=c/100; cents=c%100; } public void add(int c){ cents+=c; dollars+=cents/100; cents=cents%100; } public void add(int d,int c){ cents+=c; dollars=dollars+d+cents/100; cents=cents%100; } public void remove(int c){ cents=dollars*100+cents;
  • 2. if(c>cents){ cents=0; } else{ cents-=c; } dollars=cents/100; cents=cents%100; } public String getMoney(){ return dollars+" dollars and "+cents+" cents"; } public static void main(String []args){ Money h=new Money(1,75); h.add(190); System.out.println(h.getMoney()); } } Solution import java.util.Scanner; import java.math.BigInteger; public class Money{ private int dollars; private int cents; public Money(){ dollars=0; cents=0; } public Money(int d,int c){ dollars=d+c/100; cents=c%100;
  • 3. } public Money(int c){ dollars=c/100; cents=c%100; } public void add(int c){ cents+=c; dollars+=cents/100; cents=cents%100; } public void add(int d,int c){ cents+=c; dollars=dollars+d+cents/100; cents=cents%100; } public void remove(int c){ cents=dollars*100+cents; if(c>cents){ cents=0; } else{ cents-=c; } dollars=cents/100; cents=cents%100; } public String getMoney(){ return dollars+" dollars and "+cents+" cents"; } public static void main(String []args){ Money h=new Money(1,75);