Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

COSC 1437 – Java I would like to open a restaurant named MegaBites with computer

ID: 3837997 • Letter: C

Question

COSC 1437 – Java

I would like to open a restaurant named MegaBites with computer-themed menu items. Starting with the main program below, do the following:

1. Write the MenuItem class so the main program below will work.


2. Have the main program calculate the total calories of all menu items, total price of all menu items, and the highest priced item. Hint: Write a for loop that steps through every item in the ArrayList to calculate these.


3. The output of the main program should be:

// main program

import java.util.*;

public class megabites

{

      public static void main(String[] args)

      {

            ArrayList<MenuItem> Menu = new ArrayList<MenuItem>();

            // parameters are Name, Category, Calories, Price

            Menu.add(new MenuItem("Tera Burger", "Entrée", 600, 7.99));  

            Menu.add(new MenuItem("Micro-Soft Tacos", "Entrée", 500, 6.99));

            Menu.add(new MenuItem("Spam", "Entrée", 1050, 2.99));

            Menu.add(new MenuItem("Fish & Micro-Chips", "Entrée", 700, 8.99));

            Menu.add(new MenuItem("Flash Fries", "Appetizer", 350, 1.99));

            Menu.add(new MenuItem("Mouse", "Appetizer", 75, 0.99));

            Menu.add(new MenuItem("Python", "Appetizer", 100, 1.99));

            Menu.add(new MenuItem("Java", "Beverage", 150, 2.99));

            Menu.add(new MenuItem("QWER-Tea", "Beverage", 50, 1.99));

            Menu.add(new MenuItem("Deleted Cookie", "Dessert", 250, 1.99));

            Menu.add(new MenuItem("Apple Crisps", "Dessert", 250, 1.99));

            // calculate total calories, total prices, and highest price here

            // output all these items here

      }

}

// add the MenuItem class here

**********************************************************************

OUTPUT OF THE MAIN PROGRAM

Total menu items = 11

Total calories of all items = 4075

Total price of all items =$40.89

Highest period item = $8.99

Explanation / Answer

MenuItems.class

public class MenuItems {
   String itemname;
   String itemtype;
   int colory;
   double price;
   MenuItems(String itemname,String itemtype,int colory,double price){
       this.itemname=itemname;
       this.itemtype=itemtype;
       this.colory=colory;
       this.price=price;
   }
   public int getcolory(){
       return colory;
   }
   public String getitemname(){
       return itemname;
   }
   public String getitemtype(){
       return itemtype;
   }
   public double getprice(){
       return price;
   }
}

Megabytes.class
import java.util.*;
import java.io.*;
public class Megabytes {
static List<MenuItems> Menu=new ArrayList<MenuItems>();
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       Menu.add(new MenuItems("Tera Burger", "Entrée", 600, 7.99));
Menu.add(new MenuItems("Micro-Soft Tacos", "Entrée", 500, 6.99));
Menu.add(new MenuItems("Spam", "Entrée", 1050, 2.99));
Menu.add(new MenuItems("Fish & Micro-Chips", "Entrée", 700, 8.99));
Menu.add(new MenuItems("Flash Fries", "Appetizer", 350, 1.99));
Menu.add(new MenuItems("Mouse", "Appetizer", 75, 0.99));
Menu.add(new MenuItems("Python", "Appetizer", 100, 1.99));
Menu.add(new MenuItems("Java", "Beverage", 150, 2.99));
Menu.add(new MenuItems("QWER-Tea", "Beverage", 50, 1.99));
Menu.add(new MenuItems("Deleted Cookie", "Dessert", 250, 1.99));
Menu.add(new MenuItems("Apple Crisps", "Dessert", 250, 1.99));
int total_items=Menu.size();
int total_colorys=0;
double total_price=0;
double miniprice=0.03;
for(int i=0;i<Menu.size();i++){
   Object o=Menu.get(i);
   MenuItems mi=(MenuItems)o;
   total_colorys+=mi.getcolory();
   total_price+=mi.getprice();
}
for(int i=0;i<Menu.size();i++){
   Object o=Menu.get(i);
   MenuItems mi=(MenuItems)o;
   double checkhigh =mi.getprice();
   if(checkhigh>miniprice){
       miniprice=checkhigh;
   }
     
}
System.out.println("Total menu items="+total_items);
   System.out.println("Total calories of all items="+total_colorys);
   System.out.println("Total price of all items =$"+total_price);
       System.out.println("Highest period item = $"+miniprice);
   }
}

output:

Total menu items=11
Total calories of all items=4075
Total price of all items =$40.89
Highest period item = $8.99