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

PDF
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
PDF
Here is the codeimport java.util.; class GroceryItem { Stri.pdf
PDF
This is a java lab assignment. I have added the first part java re.pdf
DOCX
c++main.cpp#include iostream#include store.h#includ.docx
PDF
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
PDF
public class FullListException extends Exception { Default .pdf
PDF
Write a program that mimics the operations of several vending machin.pdf
PDF
Hello everyone,Im actually working on a fast food order program..pdf
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
Here is the codeimport java.util.; class GroceryItem { Stri.pdf
This is a java lab assignment. I have added the first part java re.pdf
c++main.cpp#include iostream#include store.h#includ.docx
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
public class FullListException extends Exception { Default .pdf
Write a program that mimics the operations of several vending machin.pdf
Hello everyone,Im actually working on a fast food order program..pdf

Similar to import java.util.ArrayList;public class Checkout{private.docx (14)

PDF
MenuItemvpublic class MenuItem .pdf
PDF
Hello everyone,Im working on my fast food order project program..pdf
PDF
import entity.Product; 012. import java.util.; 013. 014..pdf
DOCX
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx
PDF
C++ help finish my code Topics class definitions, arrays of objec.pdf
PDF
How to create an array restaurant menu out of the main class using m.pdf
PDF
#include stdafx.h#include iostreamusing namespace std;cl.pdf
PDF
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
PDF
AnswerNote programming specifications and the printing statement.pdf
PDF
operating system ubuntu,Linux,Macpublic class SuperMarket {   .pdf
TXT
Code
DOCX
1 – Implementing the Decorator Design Pattern (with St.docx
PDF
Array ============ 1. In array, elements can be accessed using .pdf
PDF
database propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdf
MenuItemvpublic class MenuItem .pdf
Hello everyone,Im working on my fast food order project program..pdf
import entity.Product; 012. import java.util.; 013. 014..pdf
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx
C++ help finish my code Topics class definitions, arrays of objec.pdf
How to create an array restaurant menu out of the main class using m.pdf
#include stdafx.h#include iostreamusing namespace std;cl.pdf
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
AnswerNote programming specifications and the printing statement.pdf
operating system ubuntu,Linux,Macpublic class SuperMarket {   .pdf
Code
1 – Implementing the Decorator Design Pattern (with St.docx
Array ============ 1. In array, elements can be accessed using .pdf
database propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdf

More from Abhinav816839 (20)

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

Recently uploaded (20)

PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PPTX
Share_Module_2_Power_conflict_and_negotiation.pptx
PPTX
Virtual and Augmented Reality in Current Scenario
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
PDF
Trump Administration's workforce development strategy
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
Uderstanding digital marketing and marketing stratergie for engaging the digi...
PDF
Complications of Minimal Access-Surgery.pdf
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PPTX
20th Century Theater, Methods, History.pptx
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
B.Sc. DS Unit 2 Software Engineering.pptx
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Share_Module_2_Power_conflict_and_negotiation.pptx
Virtual and Augmented Reality in Current Scenario
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
A powerpoint presentation on the Revised K-10 Science Shaping Paper
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
Trump Administration's workforce development strategy
Chinmaya Tiranga quiz Grand Finale.pdf
FORM 1 BIOLOGY MIND MAPS and their schemes
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Uderstanding digital marketing and marketing stratergie for engaging the digi...
Complications of Minimal Access-Surgery.pdf
History, Philosophy and sociology of education (1).pptx
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
20th Century Theater, Methods, History.pptx

import java.util.ArrayList;public class Checkout{private.docx

  • 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