Question: Is this correct(and efficient) code and if not can you please correct and explain why. These are the requirements i'm following so base your responses

Is this correct(and efficient) code and if not can you please correct and explain why. These are the requirements i'm following so base your responses on it too

Is this correct(and efficient) code and if not can you please correct

code java//

public class main {

public static void main(String[] args) { restaurant hi= new restaurant(); hi.serveCheeseBurger(9); System.out.println(); // TODO Auto-generated method stub

}

}

public class OutOfStock extends Exception { }

public class restaurant { private String name; private int order; private int stock=6;

public void setName() { this.name=name; } String getName() { return name; } void serveCheeseBurger(int order){ //if(stockUp==0) { try { for(int i=0; i

} }

The Restaurant class should have a name property, as well as a getter and setter method for the name. The class should also have a stockLevel property, which can be set either by a parameter passed to the constructor, or by calling a special stockUp(int amount) method. Your Restaurant class will need a method called serveCheeseBurger() method, which reduces the stockLevel by one, and also prints "Cheeseburger! to the console. The serveCheeseBurger() method should be defined as throwing an OutOfStockException, which it will throw if someone attempts to call serveCheese Burger() when there's no stock left. You will need to add the OutOfStockException class to the project yourself. Don't forget that this class needs to extend Exception in order to work! Add another class to the project, named Main and containing a main() method. Write the main() method such that it stocks the Restaurant with 5 cheeseburgers, but then tries to serve 6. You'll be forced to use a try and catch block in order to handle the error. Output a suitable message to stderr (System.err.println) if the exception is thrown

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!