Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

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

Information Modeling And Relational Databases

Authors: Terry Halpin, Tony Morgan

2nd Edition

0123735688, 978-0123735683

More Books

Students also viewed these Databases questions

Question

Be able to suggest some future options for human resources

Answered: 1 week ago