Question

In: Computer Science

CP2 Major Project #1: Design a complete system according to the below requirements.. It Includes:1) A...

CP2 Major Project #1:

Design a complete system according to the below requirements.. It Includes:1) A Class called CandyOrder which stores information about the variety of the Candy (such as Snickers), the price per bag/box (such as 2.99), and the amount of bags/boxes (such as 2) ordered. The CandyOrder class should contain a constructor and a default constructor (sets variety to "Snickers", prices to $2.99, and box amount to 1). Accessor and Mutator methods for all instance variables. A toString method returning all instance variable values for thisobject.An equals method which returns true if variety and price are the same.---------------------------------------------------------------------------------------------------------------------

2) A Class called MasterOrder:

private CandyOrder[] orders; //required instance var /** Constructs a new MasterOrder object.

*/ public MasterOrder(int len) {//Constructs array orders (above) with len for length }

public boolean addOrder(int spot, String variety, int boxes, double price) {//create a new CandyOrder object and place in position spot in array orders//validate that spot in orders is null and that spot is not >= length of array orders//if validation fails, return false -- else return true}

public int getTotalBoxes() {//returns the total of amount of boxes in CandyOrder}

public double getTotalCost() {//returns the total cost of all of boxes in CandyOrder}

public CandyOrder[] removeVariety(String candyVar) { //removes any object from CandyOrder that has a variety of candyVar, new possible decreased array of CandyOrder (minus candyVars) returned }

public String printOutInfo() {//returns a combined string of all outputs in array orders using toString method in CandyOrder -- seperate each object by a newline---------------------------------------------------------------------------------------------------------------------

3) Main Driver Class:

a) prompt user for the length of the CandyOrder Array desired.

b) create a MasterOrder object passing the length from item a above

c) enter the amount of CandyOrders objects required in length via the addOrder method

d) call getTotalBoxes to printout total of all boxes

e) call getTotalCost to printout total cost of all CandyOrders in array

f) call removeVariety on a variety you have in the CandyOrder array in MasterOrder

g) call printOutInfo to printout all info in MasterOrder

Solutions

Expert Solution

public class CandyOrder {
String variety;
double price;
int amount;
public CandyOrder(){
this.variety = "Snickers";
this.price = 2.99;
this.amount = 1;
}
public CandyOrder(String variety, double price, int amount){
this.variety = variety;
this.price = price;
this.amount = amount;
}

String getVariety(){
return this.variety;
}

double getPrice(){
return this.price;
}

int getAmount(){
return this.amount;
}

void setVariety(String variety){
this.variety = variety;
}

void setPrice(double price){
this.price = price;
}

void setAmount(int amount){
this.amount = amount;
}

boolean equals(CandyOrder obj){
if (this.variety.equals(obj.variety)) {
if (this.price == obj.price)
return true;
else
return false;
}
else
return false;
}

String tostring(){
return "Variety " + this.variety + ". Has price (per bag/box) " + this.price + ". Has amount (bags/boxes) " + this.amount;
}
}

public class MasterOrder {
private CandyOrder[] orders;
public MasterOrder(int len){
orders = new CandyOrder[len];
for (int i = 0; i <len; i++)
orders[i] = null;
}

public boolean addOrder(int spot, String variety, int boxes, double price){
if (spot >= orders.length || spot < 0)
return false;
else if (orders[spot] != null)
return false;
else {
CandyOrder or = new CandyOrder(variety, price, boxes);
this.orders[spot] = or;
return true;
}
}

public int getTotalBoxes(){
int total = 0;
for (int i = 0; i < this.orders.length; i++){
total += this.orders[i].amount;
}
return total;
}

public double getTotalCost(){
double cost = 0;
for (int i = 0; i < this.orders.length; i++){
cost += this.orders[i].price * this.orders[i].amount;
}
return cost;
}

public CandyOrder[] removeVariety(String candyVar){
CandyOrder[] newOrder;
int no = 0;

// Number of elements with variety candyVar
for (int i = 0; i < this.orders.length; i++){
if (this.orders[i].variety.equals(candyVar))
no++;
}
newOrder = new CandyOrder[this.orders.length - no];

int k =0;

for (int i = 0; i < this.orders.length; i++){
if (this.orders[i].variety.equals(candyVar))
continue;
else
newOrder[k++] = this.orders[i];
}
return newOrder;
}

public String printOutInfo(){
String master = "";
for (int i = 0; i < this.orders.length; i++){
master += this.orders[i].tostring() + "\n";
}
return master;
}
}


import java.util.Scanner;
public class Main{
public static void main(){
System.out.println("Enter the length of CandyOrder Array: ");
Scanner sc = new Scanner(System.in);
int len = sc.nextInt();
MasterOrder mo = new MasterOrder(len);
for (int i = 0; i< len; i++) {
System.out.println("\nEnter order for %d th index: ");
System.out.println("Enter Variety:");
String variety = sc.next();

System.out.println("Enter Price(Pex bag/box): ");
double price = sc.nextDouble();

System.out.println("Enter Amount of bags/boxes: ");
int amount = sc.nextInt();
mo.addOrder(i, variety, amount, price);
}
mo.getTotalBoxes();
mo.getTotalCost();
System.out.println("Enter the variety to be removed: ");
String var = sc.next();
mo.removeVariety(var);
mo.printOutInfo();
}


Related Solutions

The systems requirements in a software project includes the categories of primary requirements, derived requirements, design...
The systems requirements in a software project includes the categories of primary requirements, derived requirements, design constraints, and design goals. Briefly explain each category and how it is different from the other categories.
PROJECT 4 : DESIGN A HYDRAULIC MOBILE CRANE REQUIREMENTS: •Design the system to carry load of...
PROJECT 4 : DESIGN A HYDRAULIC MOBILE CRANE REQUIREMENTS: •Design the system to carry load of up to 5000 lb •Use a hydraulic winch(rotary actuator)to move the pulleys up and down •Use fail-safe measures to support positive loads and run-away issues •The speed of the crane shouldbe changeable •Use dampeners to prevent vibration and maintain pressure and flow where necessar
How are the requirements for a design project developed?
How are the requirements for a design project developed?
The project includes 10 required items. Complete required items 1 - 10 by entering the appropriate...
The project includes 10 required items. Complete required items 1 - 10 by entering the appropriate accounting information in your template.Please use your name as the name of the company for the purpose of completing titles in your excel documents (Ex. John Smith, Inc.).After completing items 1 - 10 save your final template using the following name format: ACCT_Project_Yourfirstname_Yourlastname, Example: ACCT_Project_John_Smith. QUESTION 1 Required: #1. Prepare journal entries to record the December transactions in the General Journal Tab in the...
Java programming. *******I Need complete the following requirements in this project: 1/ Remove the applyRandomBonus method...
Java programming. *******I Need complete the following requirements in this project: 1/ Remove the applyRandomBonus method from the test class 2/ Create a File, Printwriter for an output file yourlastnameErrorLog.txt 3/ Set your maximum array size for accounts to 10 4/ Catch InputMismatch and ArrayIndexOutOfBounds exceptions when reading data from the file: a. Skip any lines that cause an exception b. Write information about the exception to the log file, yourlastnameError.txt c. Include exception type and line number in exception...
Please see the java code below and amend it according to these requirements: * Do not...
Please see the java code below and amend it according to these requirements: * Do not remove any of the code within the public interface to the class, only add code to test the additional functionality *Limit items in each instance *Allow the last item entered to be deleted The CashRegister class should be modified to limit the number of items that can be added to an instance of the CashRegister. The limit should be declared as a constant in such a...
Follow the format shown in Exhibit 12B.1 and Exhibit 12B.2 as you complete the requirements below....
Follow the format shown in Exhibit 12B.1 and Exhibit 12B.2 as you complete the requirements below. Each of the following scenarios is independent. Assume that all cash flows are after-tax cash flows. Cuenca Company is considering the purchase of new equipment that will speed up the process for producing flash drives. The equipment will cost $7,200,000 and have a life of 5 years with no expected salvage value. The expected cash flows associated with the project follow: Year Cash Revenues...
Design a spreadsheet to calculate the class’s grades. Consider the following requirements: Each project will be...
Design a spreadsheet to calculate the class’s grades. Consider the following requirements: Each project will be graded from 0 to 10. the contribution of each grade to the final grade are ( 7 team work assignments 10%, Project 1,2,3,4= 20%, mid term 35%, final 35%.) The final test will be graded from 0 to 100, but your solution should allow different grades (i.e 80 points, 90, or 95). This flexibility is very important. Program your solution to set a numeric...
Need assitance with the below: Complete a first draft of your Website Plan, that includes the...
Need assitance with the below: Complete a first draft of your Website Plan, that includes the following: Topic of website Purpose of website Intended audience/visitors of website Content outline for homepage and at least two sub-pages A visual mockup of the website layout Your plan should be a minimum of 1 full page, not counting your cover page. Include your name and assignment title. Take your time to ensure that you have fully explained your plans. Use full sentences. Rather...
Given the information below, complete the following requirements: A. Rank the customers by their gross margin...
Given the information below, complete the following requirements: A. Rank the customers by their gross margin as a percent of sales revenue. B. Perform customer profitability analysis by generating an operating income for each customer segment through the use of activity-based costing. C. Rank segments by their respective operating income as a percent of sales. D. If the relative rankings of the segments using operating income as a percent of sales is different from the relative rankings using gross margin...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT