Answered step by step
Verified Expert Solution
Link Copied!

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 1:
ResturantItem.java:
public class ResturantItem implements Comparable {
// declare variable
private String Menu;
private double Prices;
// constructor
public ResturantItem(String Menu, double Prices){
this.Menu = Menu;
this.Prices = Prices;
}
// compareto Method for compare the menu attribute
@Override
public int compareTo(ResturantItem o){
int menuComparsion = this.Menu.compareToIgnoreCase(o.Menu);
if (menuComparsion !=0){
return Integer.compare(menuComparsion,0);
}
return Double.compare(this.Prices, o.Prices);
}
// testing for compareto
public static void main(String[] args){
// instantiated some resturant item for comparison
ResturantItem R1= new ResturantItem("Pizza",12);
ResturantItem R2= new ResturantItem("Soup",10);
ResturantItem R3= new ResturantItem("CheeseCake",10);
// print the result of the menu order
System.out.println(R1.compareTo(R2)); //-1
System.out.println(R3.compareTo(R1)); //-1
System.out.println(R2.compareTo(R3)); //1
}
}
ResturantItemA.java:
public class ResturantItemA extends ResturantItem {
// declare variable that has integer type
private int calories;
// implement three-arg constructor
public ResturantItemA(String Menu, double Prices, int calories){
super(Menu, Prices);
this.calories = calories;
}
// implement getter and setter for instance variable
public int getCalories(){
return calories;
}
public void setCalories(int 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.toString()+"\t"+ calories;
}
@Override
// implement equals method to check equality of the Item A instance variables
public boolean equals(Object o){
if (!super.equals(o))
return false;
ResturantItemA ItemA =(ResturantItemA) o;
return calories == ItemA.calories;
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

Under what circumstances is polygraph testing of employees legal?

Answered: 1 week ago