Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Why am I having a error on line 1 : ResturantItem.java: public class ResturantItem implements Comparable { / / declare variable private String Menu; private
Why am I having a error on line :
ResturantItem.java:
public class ResturantItem implements Comparable
declare variable
private String Menu;
private double Prices;
constructor
public ResturantItemString Menu, double Prices
this.Menu Menu;
this.Prices Prices;
compareto Method for compare the menu attribute
@Override
public int compareToResturantItem o
int menuComparsion this.Menu.compareToIgnoreCaseoMenu;
if menuComparsion
return Integer.comparemenuComparsion;
return Double.comparethisPrices, oPrices;
testing for compareto
public static void mainString args
instantiated some resturant item for comparison
ResturantItem R new ResturantItemPizza;
ResturantItem R new ResturantItemSoup;
ResturantItem R new ResturantItemCheeseCake;
print the result of the menu order
System.out.printlnRcompareToR;
System.out.printlnRcompareToR;
System.out.printlnRcompareToR;
ResturantItemA.java:
public class ResturantItemA extends ResturantItem
declare variable that has integer type
private int calories;
implement threearg constructor
public ResturantItemAString Menu, double Prices, int calories
superMenu Prices;
this.calories calories;
implement getter and setter for instance variable
public int getCalories
return calories;
public void setCaloriesint calories
this.calories calories;
implement toString that return a string represenation of object where
instance variable are in one line and separated by tab
@Override
public String toString
return super.toStringt calories;
@Override
implement equals method to check equality of the Item A instance variables
public boolean equalsObject o
if super.equalso
return false;
ResturantItemA ItemA ResturantItemA o;
return calories ItemA.calories;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started