Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Purpose: To learn how to create a class, instantiate an object of the class in another class, and use that object to call methods. Prep

Purpose: To learn how to create a class, instantiate an object of the class in another class, and use that object to call methods.

Prep Work: Read chapter 7. Refer to any available demo code from IS 2033.

Lab Exercise 7.1 Instructions: Name your program as YourLastNameFirstInitialLE71.java. From the code in LE 6.2, do the following:

1. You will NOT be changing any of the logic in the code for LE 6.2

2. Create a separate class called Restaurant. This class will have NO main().

3. Insert a default constructor in the Restaurant class. This is a method that is empty and its header looks like this: public NameOfClass()

4. Code an overloaded constructor that will receive an owner's name when an object for Restaurant is created in the main().

1. In the Restaurant class store the owner's name in a field (class variable) called ownerName.

2. You will insert the owner name in the header of the output.

5. Except, for the main(), take all the other methods in LE 6.2 and put them in the Restaurant class.

6. Transfer the fields from LE 6.2 to Restaurant.

7. Strip the word static from the fields and the method headers in the Restaurant class.

8. Cut and paste the main() from LE 6.2 into your program file for LE 7.1.

1. Prompt for the owner name.

2. Create an object of the Restaurant class.

1. Format: NameOfClass objectName = new NameOfClass(capture of keyboard entry);

3. Use that object for the method calls in the main().

1. Format: objectName.methodName()

Make sure both classes are in the same directory.

To run both programs, you must run the class with the main().

Sample Output: The output is exactly the same as LE 6.2 except, there is a prompt for the company's name which also shows up in the output header. SAMPLE OUTPUT LE 7.1.pdf

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions