SlideShare a Scribd company logo
1 of 8
import java.util.ArrayList;
public class Checkout{
private ArrayList checkoutList;
Checkout(){
checkoutList= new ArrayList();
}
public int numberOfItems(){
return checkoutList.size();
}
public int totalCost(){
int sum=0;
for (Item i : checkoutList){
sum+=i.getCost();
}
return sum;
}
public int totalTax(){
return (int) java.lang.Math.
round
(GroceryStore.
TAX_RATE
*totalCost()/100.0);
}
public void clear(){
checkoutList.clear();
}
public void enterItem(Item i){
checkoutList.add(i);
}
public String toString(){
;
System.
out
.println("t"+GroceryStore.
STORE_NAME
);
System.
out
.println("nt-------------------");
for (Item i : checkoutList){
System.
out
.println(i.toString());
}
System.
out
.println("nTax "+GroceryStore.
cents2dollarsAndCents
(totalTax()));
System.
out
.println("nTotal Cost "+GroceryStore.
cents2dollarsAndCents
(totalCost()+totalTax()));
return "";
}
}
// Test Check out
public class TestCheckout {
public static void main(String[] args) {
Checkout checkout = new Checkout();
checkout.enterItem(new Rice("Basmati Rice", 2.25, 399));
checkout.enterItem(new Baguette("Wheat Baguette", 105));
checkout.enterItem(new FlavoredBaguette("White Baguette",
145, "Chocolate", 50));
checkout.enterItem(new Egg("Grade A Organic Eggs", 4,
399));
System.
out
.println("nNumber of items: " + checkout.numberOfItems() +
"n");
System.
out
.println("nTotal cost: " + checkout.totalCost() + "n");
System.
out
.println("nTotal tax: " + checkout.totalTax() + "n");
System.
out
.println("nCost + Tax: " + (checkout.totalCost() +
checkout.totalTax()) + "n");
System.
out
.println(checkout);
checkout.clear();
checkout.enterItem(new Baguette("Organic Baguette", 145));
checkout.enterItem(new FlavoredBaguette("Wheat Baguette",
105, "Caramel", 50));
checkout.enterItem(new Rice("Indian Brown Rice", 1.33, 89));
checkout.enterItem(new Egg("Grade B Egg", 4, 399));
checkout.enterItem(new Rice("Arabic White Rice", 1.5, 209));
checkout.enterItem(new Rice("Spanish Yellow Rice", 3.0,
109));
System.
out
.println("nNumber of items: " + checkout.numberOfItems() +
"n");
System.
out
.println("nTotal cost: " + checkout.totalCost() + "n");
System.
out
.println("nTotal tax: " + checkout.totalTax() + "n");
System.
out
.println("nCost + Tax: " + (checkout.totalCost() +
checkout.totalTax()) + "n");
System.
out
.println(checkout);
}
//Baguette
public class Baguette extends Item {
private double cost;
public Baguette(String name, double cost) {
super(name);
this.cost = cost;
}
@Override
public int getCost()
{
return (int)Math.
ceil
(cost);
}
@Override
public String toString() {
return name+" @" + GroceryStore.
cents2dollarsAndCents
(getCost());
}
}
public class Rice extends Item {
double weight;
double price;
public Rice(String name, double weight, double price) {
super(name);
this.weight = weight;
this.price = price;
}
@Override
public int getCost() {
return (int) Math.
ceil
(weight * price);
}
@Override
public String toString() {
return "rice" + weight + "lbs @" + GroceryStore.
cents2dollarsAndCents
(getCost());
}
}

More Related Content

Similar to Checkout Class Item Cost Tax

public static ArrayListInteger doArrayListInsertAtMedian(int nu.pdf
public static ArrayListInteger doArrayListInsertAtMedian(int nu.pdfpublic static ArrayListInteger doArrayListInsertAtMedian(int nu.pdf
public static ArrayListInteger doArrayListInsertAtMedian(int nu.pdfarihanthtoysandgifts
 
20070329 Java Programing Tips
20070329 Java Programing Tips20070329 Java Programing Tips
20070329 Java Programing TipsShingo Furuyama
 
Implement the ADT stack by using an array stack to contain its entri.pdf
Implement the ADT stack by using an array stack to contain its entri.pdfImplement the ADT stack by using an array stack to contain its entri.pdf
Implement the ADT stack by using an array stack to contain its entri.pdfSIGMATAX1
 
Please review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdfPlease review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdffathimafancyjeweller
 
Beautiful java script
Beautiful java scriptBeautiful java script
Beautiful java scriptÜrgo Ringo
 
public class TrequeT extends AbstractListT { .pdf
  public class TrequeT extends AbstractListT {  .pdf  public class TrequeT extends AbstractListT {  .pdf
public class TrequeT extends AbstractListT { .pdfinfo30292
 
You are to simulate a dispatcher using a priority queue system in C+.pdf
You are to simulate a dispatcher using a priority queue system in C+.pdfYou are to simulate a dispatcher using a priority queue system in C+.pdf
You are to simulate a dispatcher using a priority queue system in C+.pdfJUSTSTYLISH3B2MOHALI
 
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdfHello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdfflashfashioncasualwe
 
Please add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxPlease add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxStewartt0kJohnstonh
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEDarwin Durand
 
Here is the codeimport java.util.; class GroceryItem { Stri.pdf
Here is the codeimport java.util.; class GroceryItem { Stri.pdfHere is the codeimport java.util.; class GroceryItem { Stri.pdf
Here is the codeimport java.util.; class GroceryItem { Stri.pdfanand1213
 
Code javascript
Code javascriptCode javascript
Code javascriptRay Ray
 
ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
 ReverseList.javaimport java.util.ArrayList;public class Rever.pdf ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
ReverseList.javaimport java.util.ArrayList;public class Rever.pdfaryan9007
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdfakkhan101
 

Similar to Checkout Class Item Cost Tax (17)

public static ArrayListInteger doArrayListInsertAtMedian(int nu.pdf
public static ArrayListInteger doArrayListInsertAtMedian(int nu.pdfpublic static ArrayListInteger doArrayListInsertAtMedian(int nu.pdf
public static ArrayListInteger doArrayListInsertAtMedian(int nu.pdf
 
20070329 Java Programing Tips
20070329 Java Programing Tips20070329 Java Programing Tips
20070329 Java Programing Tips
 
Implement the ADT stack by using an array stack to contain its entri.pdf
Implement the ADT stack by using an array stack to contain its entri.pdfImplement the ADT stack by using an array stack to contain its entri.pdf
Implement the ADT stack by using an array stack to contain its entri.pdf
 
Please review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdfPlease review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdf
 
Beautiful java script
Beautiful java scriptBeautiful java script
Beautiful java script
 
【Unity】Scriptable object 入門と活用例
【Unity】Scriptable object 入門と活用例【Unity】Scriptable object 入門と活用例
【Unity】Scriptable object 入門と活用例
 
C# labprograms
C# labprogramsC# labprograms
C# labprograms
 
public class TrequeT extends AbstractListT { .pdf
  public class TrequeT extends AbstractListT {  .pdf  public class TrequeT extends AbstractListT {  .pdf
public class TrequeT extends AbstractListT { .pdf
 
You are to simulate a dispatcher using a priority queue system in C+.pdf
You are to simulate a dispatcher using a priority queue system in C+.pdfYou are to simulate a dispatcher using a priority queue system in C+.pdf
You are to simulate a dispatcher using a priority queue system in C+.pdf
 
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdfHello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
 
Please add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxPlease add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docx
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
 
Here is the codeimport java.util.; class GroceryItem { Stri.pdf
Here is the codeimport java.util.; class GroceryItem { Stri.pdfHere is the codeimport java.util.; class GroceryItem { Stri.pdf
Here is the codeimport java.util.; class GroceryItem { Stri.pdf
 
Code javascript
Code javascriptCode javascript
Code javascript
 
ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
 ReverseList.javaimport java.util.ArrayList;public class Rever.pdf ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
 
Easy Button
Easy ButtonEasy Button
Easy Button
 

More from Abhinav816839

Clinical Reasoning Case Study Total Parenteral NutritionName ____.docx
Clinical Reasoning Case Study Total Parenteral NutritionName ____.docxClinical Reasoning Case Study Total Parenteral NutritionName ____.docx
Clinical Reasoning Case Study Total Parenteral NutritionName ____.docxAbhinav816839
 
Correctional Health Care AssignmentCourse Objective for Assignme.docx
Correctional Health Care AssignmentCourse Objective for Assignme.docxCorrectional Health Care AssignmentCourse Objective for Assignme.docx
Correctional Health Care AssignmentCourse Objective for Assignme.docxAbhinav816839
 
Class Response 1 Making or implementing policies should ultima.docx
Class Response 1 Making or implementing policies should ultima.docxClass Response 1 Making or implementing policies should ultima.docx
Class Response 1 Making or implementing policies should ultima.docxAbhinav816839
 
Chapter 3 - Evaluation Rubric Criteria Does Not Meet 0.01 .docx
Chapter 3 - Evaluation Rubric Criteria Does Not Meet 0.01 .docxChapter 3 - Evaluation Rubric Criteria Does Not Meet 0.01 .docx
Chapter 3 - Evaluation Rubric Criteria Does Not Meet 0.01 .docxAbhinav816839
 
Chapter 4 (Sexual Assault)Points Possible 20Deliverable Len.docx
Chapter 4 (Sexual Assault)Points Possible 20Deliverable Len.docxChapter 4 (Sexual Assault)Points Possible 20Deliverable Len.docx
Chapter 4 (Sexual Assault)Points Possible 20Deliverable Len.docxAbhinav816839
 
CS547 Wireless Networking and Security Exam 1 Questio.docx
CS547 Wireless Networking and Security Exam 1  Questio.docxCS547 Wireless Networking and Security Exam 1  Questio.docx
CS547 Wireless Networking and Security Exam 1 Questio.docxAbhinav816839
 
Communicating professionally and ethically is an essential ski.docx
Communicating professionally and ethically is an essential ski.docxCommunicating professionally and ethically is an essential ski.docx
Communicating professionally and ethically is an essential ski.docxAbhinav816839
 
Case Study The HouseCallCompany.com Abstract The case.docx
Case Study The HouseCallCompany.com  Abstract The case.docxCase Study The HouseCallCompany.com  Abstract The case.docx
Case Study The HouseCallCompany.com Abstract The case.docxAbhinav816839
 
CHAPTER 5Risk Response and MitigationIn this chapter, you will.docx
CHAPTER 5Risk Response and MitigationIn this chapter, you will.docxCHAPTER 5Risk Response and MitigationIn this chapter, you will.docx
CHAPTER 5Risk Response and MitigationIn this chapter, you will.docxAbhinav816839
 
BiopsychologySensation and PerceptionInstructionsTake a mom.docx
BiopsychologySensation and PerceptionInstructionsTake a mom.docxBiopsychologySensation and PerceptionInstructionsTake a mom.docx
BiopsychologySensation and PerceptionInstructionsTake a mom.docxAbhinav816839
 
Chapter 2Historical Perspectives on Case ManagementChapter In.docx
Chapter 2Historical Perspectives on Case ManagementChapter In.docxChapter 2Historical Perspectives on Case ManagementChapter In.docx
Chapter 2Historical Perspectives on Case ManagementChapter In.docxAbhinav816839
 
Compare and Contrast Systems Development Life Cycle (SDLC Mo.docx
Compare and Contrast Systems Development Life Cycle (SDLC Mo.docxCompare and Contrast Systems Development Life Cycle (SDLC Mo.docx
Compare and Contrast Systems Development Life Cycle (SDLC Mo.docxAbhinav816839
 
C H A P T E R F O U R PROBLEMS OF COMMUNICATIONCri.docx
C H A P T E R  F O U R  PROBLEMS OF COMMUNICATIONCri.docxC H A P T E R  F O U R  PROBLEMS OF COMMUNICATIONCri.docx
C H A P T E R F O U R PROBLEMS OF COMMUNICATIONCri.docxAbhinav816839
 
By Day 6 of Week Due 917Respond to at least two of your c.docx
By Day 6 of Week Due 917Respond to at least two of your c.docxBy Day 6 of Week Due 917Respond to at least two of your c.docx
By Day 6 of Week Due 917Respond to at least two of your c.docxAbhinav816839
 
ASSIGNMENT 3 (CHAPTERS 8-9) QUESTIONS Name .docx
ASSIGNMENT 3 (CHAPTERS 8-9) QUESTIONS Name                .docxASSIGNMENT 3 (CHAPTERS 8-9) QUESTIONS Name                .docx
ASSIGNMENT 3 (CHAPTERS 8-9) QUESTIONS Name .docxAbhinav816839
 
3 pages excluding the title and reference page.Describe how Ph.docx
3 pages excluding the title and reference page.Describe how Ph.docx3 pages excluding the title and reference page.Describe how Ph.docx
3 pages excluding the title and reference page.Describe how Ph.docxAbhinav816839
 
91422, 1134 AM Printhttpscontent.uagc.eduprintMcNe.docx
91422, 1134 AM Printhttpscontent.uagc.eduprintMcNe.docx91422, 1134 AM Printhttpscontent.uagc.eduprintMcNe.docx
91422, 1134 AM Printhttpscontent.uagc.eduprintMcNe.docxAbhinav816839
 
All details are posted in the documentPlease use this topics for.docx
All details are posted in the documentPlease use this topics for.docxAll details are posted in the documentPlease use this topics for.docx
All details are posted in the documentPlease use this topics for.docxAbhinav816839
 
1, Describe the mind as a stream of consciousness, and what it revea.docx
1, Describe the mind as a stream of consciousness, and what it revea.docx1, Describe the mind as a stream of consciousness, and what it revea.docx
1, Describe the mind as a stream of consciousness, and what it revea.docxAbhinav816839
 
2Some of the ways that students are diverse in todays schools .docx
2Some of the ways that students are diverse in todays schools .docx2Some of the ways that students are diverse in todays schools .docx
2Some of the ways that students are diverse in todays schools .docxAbhinav816839
 

More from Abhinav816839 (20)

Clinical Reasoning Case Study Total Parenteral NutritionName ____.docx
Clinical Reasoning Case Study Total Parenteral NutritionName ____.docxClinical Reasoning Case Study Total Parenteral NutritionName ____.docx
Clinical Reasoning Case Study Total Parenteral NutritionName ____.docx
 
Correctional Health Care AssignmentCourse Objective for Assignme.docx
Correctional Health Care AssignmentCourse Objective for Assignme.docxCorrectional Health Care AssignmentCourse Objective for Assignme.docx
Correctional Health Care AssignmentCourse Objective for Assignme.docx
 
Class Response 1 Making or implementing policies should ultima.docx
Class Response 1 Making or implementing policies should ultima.docxClass Response 1 Making or implementing policies should ultima.docx
Class Response 1 Making or implementing policies should ultima.docx
 
Chapter 3 - Evaluation Rubric Criteria Does Not Meet 0.01 .docx
Chapter 3 - Evaluation Rubric Criteria Does Not Meet 0.01 .docxChapter 3 - Evaluation Rubric Criteria Does Not Meet 0.01 .docx
Chapter 3 - Evaluation Rubric Criteria Does Not Meet 0.01 .docx
 
Chapter 4 (Sexual Assault)Points Possible 20Deliverable Len.docx
Chapter 4 (Sexual Assault)Points Possible 20Deliverable Len.docxChapter 4 (Sexual Assault)Points Possible 20Deliverable Len.docx
Chapter 4 (Sexual Assault)Points Possible 20Deliverable Len.docx
 
CS547 Wireless Networking and Security Exam 1 Questio.docx
CS547 Wireless Networking and Security Exam 1  Questio.docxCS547 Wireless Networking and Security Exam 1  Questio.docx
CS547 Wireless Networking and Security Exam 1 Questio.docx
 
Communicating professionally and ethically is an essential ski.docx
Communicating professionally and ethically is an essential ski.docxCommunicating professionally and ethically is an essential ski.docx
Communicating professionally and ethically is an essential ski.docx
 
Case Study The HouseCallCompany.com Abstract The case.docx
Case Study The HouseCallCompany.com  Abstract The case.docxCase Study The HouseCallCompany.com  Abstract The case.docx
Case Study The HouseCallCompany.com Abstract The case.docx
 
CHAPTER 5Risk Response and MitigationIn this chapter, you will.docx
CHAPTER 5Risk Response and MitigationIn this chapter, you will.docxCHAPTER 5Risk Response and MitigationIn this chapter, you will.docx
CHAPTER 5Risk Response and MitigationIn this chapter, you will.docx
 
BiopsychologySensation and PerceptionInstructionsTake a mom.docx
BiopsychologySensation and PerceptionInstructionsTake a mom.docxBiopsychologySensation and PerceptionInstructionsTake a mom.docx
BiopsychologySensation and PerceptionInstructionsTake a mom.docx
 
Chapter 2Historical Perspectives on Case ManagementChapter In.docx
Chapter 2Historical Perspectives on Case ManagementChapter In.docxChapter 2Historical Perspectives on Case ManagementChapter In.docx
Chapter 2Historical Perspectives on Case ManagementChapter In.docx
 
Compare and Contrast Systems Development Life Cycle (SDLC Mo.docx
Compare and Contrast Systems Development Life Cycle (SDLC Mo.docxCompare and Contrast Systems Development Life Cycle (SDLC Mo.docx
Compare and Contrast Systems Development Life Cycle (SDLC Mo.docx
 
C H A P T E R F O U R PROBLEMS OF COMMUNICATIONCri.docx
C H A P T E R  F O U R  PROBLEMS OF COMMUNICATIONCri.docxC H A P T E R  F O U R  PROBLEMS OF COMMUNICATIONCri.docx
C H A P T E R F O U R PROBLEMS OF COMMUNICATIONCri.docx
 
By Day 6 of Week Due 917Respond to at least two of your c.docx
By Day 6 of Week Due 917Respond to at least two of your c.docxBy Day 6 of Week Due 917Respond to at least two of your c.docx
By Day 6 of Week Due 917Respond to at least two of your c.docx
 
ASSIGNMENT 3 (CHAPTERS 8-9) QUESTIONS Name .docx
ASSIGNMENT 3 (CHAPTERS 8-9) QUESTIONS Name                .docxASSIGNMENT 3 (CHAPTERS 8-9) QUESTIONS Name                .docx
ASSIGNMENT 3 (CHAPTERS 8-9) QUESTIONS Name .docx
 
3 pages excluding the title and reference page.Describe how Ph.docx
3 pages excluding the title and reference page.Describe how Ph.docx3 pages excluding the title and reference page.Describe how Ph.docx
3 pages excluding the title and reference page.Describe how Ph.docx
 
91422, 1134 AM Printhttpscontent.uagc.eduprintMcNe.docx
91422, 1134 AM Printhttpscontent.uagc.eduprintMcNe.docx91422, 1134 AM Printhttpscontent.uagc.eduprintMcNe.docx
91422, 1134 AM Printhttpscontent.uagc.eduprintMcNe.docx
 
All details are posted in the documentPlease use this topics for.docx
All details are posted in the documentPlease use this topics for.docxAll details are posted in the documentPlease use this topics for.docx
All details are posted in the documentPlease use this topics for.docx
 
1, Describe the mind as a stream of consciousness, and what it revea.docx
1, Describe the mind as a stream of consciousness, and what it revea.docx1, Describe the mind as a stream of consciousness, and what it revea.docx
1, Describe the mind as a stream of consciousness, and what it revea.docx
 
2Some of the ways that students are diverse in todays schools .docx
2Some of the ways that students are diverse in todays schools .docx2Some of the ways that students are diverse in todays schools .docx
2Some of the ways that students are diverse in todays schools .docx
 

Recently uploaded

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
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 ConsultingTechSoup
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
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 ModeThiyagu K
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 

Recently uploaded (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
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
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
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
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 

Checkout Class Item Cost Tax

  • 1. import java.util.ArrayList; public class Checkout{ private ArrayList checkoutList; Checkout(){ checkoutList= new ArrayList(); } public int numberOfItems(){ return checkoutList.size(); } public int totalCost(){ int sum=0; for (Item i : checkoutList){ sum+=i.getCost(); } return sum; } public int totalTax(){
  • 2. return (int) java.lang.Math. round (GroceryStore. TAX_RATE *totalCost()/100.0); } public void clear(){ checkoutList.clear(); } public void enterItem(Item i){ checkoutList.add(i); } public String toString(){ ; System. out .println("t"+GroceryStore. STORE_NAME ); System. out .println("nt-------------------"); for (Item i : checkoutList){
  • 3. System. out .println(i.toString()); } System. out .println("nTax "+GroceryStore. cents2dollarsAndCents (totalTax())); System. out .println("nTotal Cost "+GroceryStore. cents2dollarsAndCents (totalCost()+totalTax())); return ""; } } // Test Check out public class TestCheckout { public static void main(String[] args) { Checkout checkout = new Checkout(); checkout.enterItem(new Rice("Basmati Rice", 2.25, 399));
  • 4. checkout.enterItem(new Baguette("Wheat Baguette", 105)); checkout.enterItem(new FlavoredBaguette("White Baguette", 145, "Chocolate", 50)); checkout.enterItem(new Egg("Grade A Organic Eggs", 4, 399)); System. out .println("nNumber of items: " + checkout.numberOfItems() + "n"); System. out .println("nTotal cost: " + checkout.totalCost() + "n"); System. out .println("nTotal tax: " + checkout.totalTax() + "n"); System. out .println("nCost + Tax: " + (checkout.totalCost() + checkout.totalTax()) + "n"); System. out .println(checkout); checkout.clear(); checkout.enterItem(new Baguette("Organic Baguette", 145)); checkout.enterItem(new FlavoredBaguette("Wheat Baguette",
  • 5. 105, "Caramel", 50)); checkout.enterItem(new Rice("Indian Brown Rice", 1.33, 89)); checkout.enterItem(new Egg("Grade B Egg", 4, 399)); checkout.enterItem(new Rice("Arabic White Rice", 1.5, 209)); checkout.enterItem(new Rice("Spanish Yellow Rice", 3.0, 109)); System. out .println("nNumber of items: " + checkout.numberOfItems() + "n"); System. out .println("nTotal cost: " + checkout.totalCost() + "n"); System. out .println("nTotal tax: " + checkout.totalTax() + "n"); System. out .println("nCost + Tax: " + (checkout.totalCost() + checkout.totalTax()) + "n"); System. out .println(checkout); } //Baguette
  • 6. public class Baguette extends Item { private double cost; public Baguette(String name, double cost) { super(name); this.cost = cost; } @Override public int getCost() { return (int)Math. ceil (cost); } @Override public String toString() { return name+" @" + GroceryStore. cents2dollarsAndCents (getCost()); } }
  • 7. public class Rice extends Item { double weight; double price; public Rice(String name, double weight, double price) { super(name); this.weight = weight; this.price = price; } @Override public int getCost() { return (int) Math. ceil (weight * price); } @Override public String toString() { return "rice" + weight + "lbs @" + GroceryStore. cents2dollarsAndCents