// Program name: MenuItem Class // Purpose: Pseudocode for defining the MenuItem
ID: 3552604 • Letter: #
Question
// Program name: MenuItem Class
// Purpose: Pseudocode for defining the MenuItem class
// Author: Bijou Jacob
// Date last modified: 17-Mar-2014
Class MenuItem
String itemName // name of menu item
String category // item categor (sandwich or drink)
Numeric item Price // price of item
// Constructor method with three arguments
Constructor Method MenuItem (String name, String cat, Numeric price)
itemName = name
category = cat
itemPrice = price
End Method
// Method to display all information about the menu item
Method displayInfo()
Display "Item name" + itemName
Display "Category" + category
Display "Price of item: " + itemPrice
End Method
End Class
Start
// Welcome the user
Display "Welcome to the Menu Maker!"
// Create four menu item objects MenuItem pastrami = new MenuItem
("Pastrami", "Sandwich", 4.95) MenuItem ham = new MenuItem ("Ham", "Sandwich", 5.25)
MenuItem milkShake = new MenuItem ("Milk shake", "Drink", 2.95)
MenuItem softDrink = new MenuItem ("Soft drink", "Drink", 1.49)
// Display the information for all menu items
pastrami.displayInfo()
ham.displayInfo()
milkShake.displayInfo()
softDrink.displayInfo()
// Thank the user
Display "Thank you!"
Stop
Explanation / Answer
Did you want it like this? where the menu items are already there? or did you want to ask the user for menu items and prices? This is the version where everything is already decided. It prints out:
Welcome to the Menu Maker!
Item name: Pastrami
Category: Sandwich
Price of item: 4.95
Item name: Ham
Category: Sandwich
Price of item: 5.25
Item name: Milk Shake
Category: Drink
Price of item: 2.95
Item name: Soft Drink
Category: Drink
Price of item: 1.49
Thank You!
public class MenuItem {
static String itemName;
static String category;
static double itemPrice;
public static void main(String args[]) {
System.out.println("Welcome to the Menu Maker!");
System.out.println();
MenuItem pastrami = new MenuItem("Pastrami", "Sandwich", 4.95);
pastrami.displayInfo();
System.out.println();
MenuItem ham = new MenuItem("Ham", "Sandwich", 5.25);
ham.displayInfo();
System.out.println();
MenuItem milkShake = new MenuItem("Milk Shake", "Drink", 2.95);
milkShake.displayInfo();
System.out.println();
MenuItem softDrink = new MenuItem("Soft Drink", "Drink", 1.49);
softDrink.displayInfo();
System.out.println();
System.out.println("Thank You!");
}
public MenuItem(String name, String catg, double price){
itemName = name;
category = catg;
itemPrice = price;
}
public void displayInfo(){
System.out.println("Item name: " + itemName);
System.out.println("Category: " + category);
System.out.println("Price of item: " + itemPrice);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.