Question

In: Computer Science

First level CS, should not be too complex. Need in a week. You must turn in...

First level CS, should not be too complex. Need in a week.

You must turn in three java files - FoodItem.java, Order.java and MyOrder.java. In addition to these, you must include a screenshot of the output by executing the file MyOrder.java. Submissions without all these files will not be graded.

Task 1:

Design a class named FoodItem which contains the following fields:

Type of food item: Like entree, bread, soup, salad, drink or dessert to name a few

Item number: could be an alphanumeric code or just a number

Unit price: $xx.xx

You must include appropriate instance methods like constructors, getters , setters and toString for all the fields.

Task 2:

Create another class named Order which has the following fields:

Order number: It could be an alphanumeric id or numeric.

Customer Name: First and last name of the customer

Combo meal option: yes or no

DiscountAmount: If combo meal is chosen, offer a 5% discount

OrderTotal: Total bill amount

You must create the following methods for the Order class:

Constructor (s) - You may include an extra constructor that takes in the Customer name as a parameter.

Setters, getters and toString methods for the appropriate fields.

add(item,quantity) - this method adds the price of purchasing an item to the Order total.

getOrderTotal() - this method returns the total bill amount to be paid by the customer after including any discounts applicable and also a 10% sales tax on the total amount.

Task 3:

Create a class named MyOrder that displays a Menu of items available to choose from, creates an order for two different customers and reports their total bill amount. Use appropriate print statements to guide the user through the ordering process. Remember, this is the class where you are actually placing an order (action required). So, this class must contain the main method.

Solutions

Expert Solution

/**

*

* FoodItem class

*/

public class FoodItem {

   

    //Type : entree, bread, soup, salad, drink or dessert to name a few

    String itemType;

    // could be an alphanumeric code or just a number

    String itemNumber;

    // Unit price: $xx.xx

    double unitPrice;

   

    // constructors

    public FoodItem(String itemType, String itemNumber, double unitPrice) {

        this.itemType = itemType;

        this.itemNumber = itemNumber;

        this.unitPrice = unitPrice;

    }

    // getters and setters

    public String getItemType() {

        return itemType;

    }

    public void setItemType(String itemType) {

        this.itemType = itemType;

    }

    public String getItemNumber() {

        return itemNumber;

    }

    public void setItemNumber(String itemNumber) {

        this.itemNumber = itemNumber;

    }

    public double getUnitPrice() {

        return unitPrice;

    }

    public void setUnitPrice(double unitPrice) {

        this.unitPrice = unitPrice;

    }

   

    // toString for all the fields.

    @Override

    public String toString() {

        return "itemNumber = " + itemNumber + ", itemType = " + itemType + ", unitPrice = " + unitPrice;

    }

}

/*

* 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.

*/

package foodordering;

/**

*

* Order class

*/

public class Order {

    // Order number: It could be an alphanumeric id or numeric.

    String orderNumber;

    // Customer Name: First and last name of the customer

    String customerName;

    // Combo meal option: yes or no

    boolean comboMeal;

    // DiscountAmount: If combo meal is chosen, offer a 5% discount

    double discountAmount;

    // OrderTotal: Total bill amount

    double totalBill;

   

    

    //Constructor -include an extra constructor that takes in the Customer name as a parameter.

    public Order(String customerName) {

        this.customerName = customerName;

    }

    public Order(String orderNumber, String customerName, boolean comboMeal) {

        this.orderNumber = orderNumber;

        this.customerName = customerName;

        setComboMeal(comboMeal);

    }

   

    

    //Setters, getters

    public String getOrderNumber() {

        return orderNumber;

    }

    public void setOrderNumber(String orderNumber) {

        this.orderNumber = orderNumber;

    }

    public String getCustomerName() {

        return customerName;

    }

    public void setCustomerName(String customerName) {

        this.customerName = customerName;

    }

    public boolean isComboMeal() {

        return comboMeal;

    }

    public void setComboMeal(boolean comboMeal) {

        this.comboMeal = comboMeal;

        if(this.comboMeal){

            discountAmount = 5;

        }else{

            discountAmount = 0;

        }

    }

    public double getTotalBill() {

        return totalBill;

    }

    public void setTotalBill(double totalBill) {

        this.totalBill = totalBill;

    }

   

    

    //adds the price of purchasing an item to the Order total.

    void add(FoodItem item,int quantity){

        totalBill += (item.unitPrice * quantity);

    }

   

    /*getOrderTotal() - this method returns the total bill amount to be paid

    by the customer after including any discounts applicable

    and also a 10% sales tax on the total amount.*/

    double getOrderTotal(){

        double bill = totalBill;

        bill -= bill * (discountAmount /100);

        bill += bill * (10/100);

        return bill;

    }

    @Override

    public String toString() {

        return "orderNumber=" + orderNumber + ", "

                + "customerName=" + customerName + ", "

                + "comboMeal=" + comboMeal + ", totalBill=" + totalBill;

    }

   

}

package foodordering;

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

/**

*

* MyOrder class

*/

public class MyOrder {

    public static void main(String[] args) {

        //Create a list of foodItem

        ArrayList<FoodItem> foodItem = new ArrayList<>();

        // Adding new elements to the FoodItem

        foodItem.add(new FoodItem("entree", "P123", 250.20));

        foodItem.add(new FoodItem("salad", "SA123", 100.10));

        foodItem.add(new FoodItem("bread", "B123", 150.23));

        foodItem.add(new FoodItem("soup", "SO123", 200));

        foodItem.add(new FoodItem("salad", "SA123", 350));

       

        Scanner keyboard = new Scanner(System.in);

        ArrayList<Order> orders = new ArrayList<>();

        orders.add(new Order("12424", "Sara", false));

        orders.add(new Order("1234", "Prof", true));

       

        String choice;

        for(Order order : orders){

            System.out.println("Order for " + order.getCustomerName());

            do{

                for(FoodItem item : foodItem){

                    // getQualityPoint converts grade letter into grade points

                     System.out.println(item.toString());

                }

                System.out.print("Enter your item number (-1 to exit): " );

                choice = keyboard.nextLine();

                

                for(FoodItem item: foodItem){

                    if(item.getItemNumber().equalsIgnoreCase(choice)){

                        System.out.print("Enter Quantity: ");

                        int qty = keyboard.nextInt();

                        keyboard.nextLine();

                        order.add(item, qty);

                    }

                }

               

            }while(!choice.equalsIgnoreCase("-1"));

            System.out.println(order.toString());

        }

       

    }

   

}


Related Solutions

As it turns out, studying banthas is too dangerous for you, and you decide to turn...
As it turns out, studying banthas is too dangerous for you, and you decide to turn your attention to a much less hostile organism, the Ewoks. You begin another project. You find that you have to count hundreds of ewoks. You are committed to the new project, but you secretly wonder if you shouldn’t have stuck with banthas. You are studying two genes known to be linked, fur color and height. If two genes are linked, where are they located...
Is the presidency too powerful? What should be the role of the First Lady?
AMERICAN GOVERNMENTIs the presidency too powerful?What should be the role of the First Lady?Who would you nominate for president in 2020?
NEED TO DEBUG // This pseudocode should create a report that contains an // apartment complex...
NEED TO DEBUG // This pseudocode should create a report that contains an // apartment complex rental agent's commission. The // program accepts the ID number and name of the agent who // rented the apartment, and the number of bedrooms in the // apartment. The commission is $100 for renting a three-bedroom // apartment, $75 for renting a two-bedroom apartment, $55 for // renting a one-bedroom apartment, and $30 for renting a studio // (zero-bedroom) apartment. Output is the...
This week, we will focus on understanding the accounting/recording process. In our discussion you must first...
This week, we will focus on understanding the accounting/recording process. In our discussion you must first identify and discuss the steps in the recording process. Be sure to discuss what each step does and how it relates to the steps before and after it. Then, answer the following questions: Should business transactions credits and debits be recorded directly into the ledger accounts? What are the advantages of recording in the journal before posting transactions into the ledger?
Case Questions/Information: The responses to the case questions must be typed. You must turn a printed...
Case Questions/Information: The responses to the case questions must be typed. You must turn a printed copy by the beginning of class on the day that the case is due. You may work alone or in a group of up to 4 students. Only 1 copy of the case is required for any groups, but please be sure that all students’ names are included on that copy. You should use an Excel spreadsheet to show your calculations. Any text responses...
what are the principles behind facebook's interview process? Do you think it is too complex
what are the principles behind facebook's interview process? Do you think it is too complex
Each must observe your town/community condition. You should be aware of the current need of your...
Each must observe your town/community condition. You should be aware of the current need of your community. Suggest one (1) practical and feasible program/ordinance that can improve the problems of the community. Provide three (3) pros and three (3) cons for the proposed program/ ordinance to progress it.
Ethical Listening ( answers does not need to be too long) If you felt that a...
Ethical Listening ( answers does not need to be too long) If you felt that a classmate’s speech was boring, do you have an ethical obligation to lat this classmate know that the speech was boring? Why or why not? If yes, what ethical standards might apply when telling this person about your unfavorable impression of the speech? If you knew that a student in this class “borrowed” a speech from another student, do you have an ethical obligation to...
what should a teacher done in the first day and week of the school? why its...
what should a teacher done in the first day and week of the school? why its important
A recent survey asked students to rate their stress-level during the first week of classes. Students...
A recent survey asked students to rate their stress-level during the first week of classes. Students responded on a scale from 1 to 8 wherein 1 was almost no stress and 8 being stressed to the max. Students responses to the survey are illustrated in the table below.   . .. Score . x... .. Frequency . f .. 1 2 2 4 3 7 4 4 5 4 6 1 7 6 8 2 . Using the table information, answer...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT