Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Congratulations! You have been approved to move forward with your final set of program specifications to include additional functionality in your Grocery Calculator application. As

Congratulations! You have been approved to move forward with your final set of program specifications to include additional functionality in your Grocery Calculator application. As a final incremental update to your program, you are asked to create a queue to hold the output generated for the text file. The queue will hold your object instances rather than the array and will facilitate easy processing in same sequence the grocery items were added to the queue due to queues adhering to the FIFO principle. The queue will also facilitate adding as many grocery items to your grocery list as needed without having to create a fixed-length array.

Please be reminded to revisit the Course Project UML Diagram presented in Module 01 as needed.

Your task this module is to do the following:

Class including the Main() Method:

  • Code a queue data structure to store the Grocery, Meat, and Produce object instances created during program execution.
  • Transform your code to use the queue instead of the array. It is recommended to create a new class file, however, to retain the prior version of your course project. You can copy your code from the prior module into your new class file to get started.
  • Leverage your file-processing code from the prior Module.
  • Include appropriate package import declarations as needed.
  • Output: to the console while executing the program:
    • Use System.out.printf to echo back to the user the data they input once validated.
    • Other console output as needed.
  • Output: Save to the .txt file:
    • Headings:
      • A greeting.
      • Your Name.
      • Your Class, Module/Week, and Assignment.
      • Date/Time stamps.
    • Output generated by polymorphic calls to the toString() method during queue processing.
      • After the user has signaled the termination of input and prior to exiting the program, process the queue by serving its contents and writing them to the output .txt file using a polymorphic call to the toString() method.
    • The final totals and average cost.

Grocery.java

package grocery;

/** * * @author PUR84270 */ public class Grocery { /* attributes that will be used */ String name; int quantity; double cost; double extendedCost;

public static int groceryObjectID; public static int groceryObjectCounter; public static int totalQuantity; public static double totalExtendedCost;

public Grocery() {

this.name = null; this.quantity = 0; this.cost = 0.0; this.extendedCost = 0.0; this.groceryObjectID = 0; this.groceryObjectCounter = 0; this.totalQuantity = 0; this.totalExtendedCost = 0.0; }

public Grocery(String name, int quantity, double cost) {

this.name = name; this.cost = cost; this.groceryObjectID = groceryObjectID + 1; this.groceryObjectCounter = groceryObjectCounter + 1; this.quantity = quantity; this.totalQuantity = totalQuantity + quantity; this.totalExtendedCost = totalExtendedCost + cost; }

public void setName(String name) { this.name = name; }

public String getName() { return this.name; }

public void setQuantity(int quantity) { this.quantity = quantity; }

public int getQuantity() { return this.quantity; }

public void setCost(double cost) { this.cost = cost; }

public int getTotalQuantity() { return this.totalQuantity; }

public double getExtendedCost() { return this.extendedCost; }

public double getTotalExtendedCost() { return this.totalExtendedCost; }

public String getTotalsAverage() { return "Average Cost = $" + (totalExtendedCost / totalQuantity); }

public String toString() { return " " + this.name.toUpperCase() + " | Qty: " + this.quantity + " | Cost: $" + this.cost; }

}

Meat.java

package grocery;

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */

/** * * @author PUR84270 */ public class Meat extends Grocery { private int cookingTemp; private String cookingTime; private boolean cooked;

//Constructor() public Meat() { //calls default Constructor of Grocery Class using super keyword super(); this.cookingTemp=0; this.cookingTime=""; this.cooked= false; } public Meat(String name,int quantity,double cost,int cookingTemp,String cookingTime,boolean cooked) { //Calls overload constructor of Grocery Class super(name,quantity,cost); this.cooked= cooked; this.cookingTime= cookingTime; this.cookingTemp= cookingTemp; } //getters and setters public int getCookingTemp() { return cookingTemp; }

public void setCookingTemp(int cookingTemp) { this.cookingTemp = cookingTemp; }

public String getCookingTime() { return cookingTime; }

public void setCookingTime(String cookingTime) { this.cookingTime = cookingTime; }

public boolean isCooked() { return cooked; }

public void setCooked(boolean cooked) { this.cooked = cooked; } //Overriding the toString() method of super class Grocery @Override public String toString() { return super.toString()+" Cooking Temperature: "+cookingTemp+" Cooking Time: "+cookingTime+ " Cooked: "+cooked; } }

Produce.java

package grocery;

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */

/** * * @author PUR84270 */ public class Produce extends Grocery { private boolean needsPeeling; boolean peeled; public Produce() { //calls default Constructor of Grocery Class using super keyword super(); needsPeeling= false; peeled= false; } public Produce(String name,int quantity,double cost,boolean needsPeeling, boolean peeled) { //Calls overload constructor of Grocery Class super(name,quantity,cost); this.needsPeeling= needsPeeling; this.peeled= peeled; } //getters and setters public boolean isNeedsPeeling() { return needsPeeling; }

public void setNeedsPeeling(boolean needsPeeling) { this.needsPeeling = needsPeeling; }

public boolean isPeeled() { return peeled; }

public void setPeeled(boolean peeled) { this.peeled = peeled; } //Overriding the toString() method of super class Grocery @Override public String toString() { return super.toString()+" Needs peeling: "+needsPeeling+" Peeled: "+peeled; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions

Question

=+20. What are some key SEM analytics that should be considered?

Answered: 1 week ago

Question

To what extent are entrepreneurs motivated by money?

Answered: 1 week ago

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago