2. Design the Person class and its subclasses as follows: Design a class named Person...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
2. Design the Person class and its subclasses as follows: ● Design a class named Person and its two subclasses named Student and Instructor. All data members should be defined as private. All methods except constructors should be defined as public. ● ● } . O o The Person class: o Data member: name (String), address (String), phone number (long) O Method: ▪ I I The Student class: o O Additional data member: status (String) - "freshman", "sophomore", etc. Method: ▪ I no-arg constructor(body can be empty) constructor with name, address, and phone number as parameters getName(): Return name of this person toString(): Display "Person:" and this person's name (hint: the method header is "public String toString()") The Instructor class: o o no-arg constructor(body can be empty) constructor with name, address, and phone number, and status as parameters toString() -- override: Display "Student:", this student's name, and status. (hint: use super.getName() to get the name of this student) Additional data member: rank (String) - "lecturer", "professor", etc. Method: no-arg constructor(body can be empty) constructor with name, address, and phone number, and rank as parameters toString() override: Display "Instructor:", this professor's name and rank. 3. You can copy the following code to the main method to test the classes or create your own data to test the classes. ■ ■ public static void main(String[] args) { Person person = new Person ("Peter", "111 Main St.", 2223333); System.out.println (person); person new Student ("Susan", "123 2nd Ave.", 3334444, "Sophomore"); System.out.println (person); person new Instructor ("Frank", "4315 Walnut Ct.", 4445555, "Professor"); System.out.println (person); 4. Your output should be similar as follows: Sample Run: Person: Peter Student: Susan (Sophomore) Instructor: Frank (Professor) 1/2 2. Design the Person class and its subclasses as follows: ● Design a class named Person and its two subclasses named Student and Instructor. All data members should be defined as private. All methods except constructors should be defined as public. ● ● } . O o The Person class: o Data member: name (String), address (String), phone number (long) O Method: ▪ I I The Student class: o O Additional data member: status (String) - "freshman", "sophomore", etc. Method: ▪ I no-arg constructor(body can be empty) constructor with name, address, and phone number as parameters getName(): Return name of this person toString(): Display "Person:" and this person's name (hint: the method header is "public String toString()") The Instructor class: o o no-arg constructor(body can be empty) constructor with name, address, and phone number, and status as parameters toString() -- override: Display "Student:", this student's name, and status. (hint: use super.getName() to get the name of this student) Additional data member: rank (String) - "lecturer", "professor", etc. Method: no-arg constructor(body can be empty) constructor with name, address, and phone number, and rank as parameters toString() override: Display "Instructor:", this professor's name and rank. 3. You can copy the following code to the main method to test the classes or create your own data to test the classes. ■ ■ public static void main(String[] args) { Person person = new Person ("Peter", "111 Main St.", 2223333); System.out.println (person); person new Student ("Susan", "123 2nd Ave.", 3334444, "Sophomore"); System.out.println (person); person new Instructor ("Frank", "4315 Walnut Ct.", 4445555, "Professor"); System.out.println (person); 4. Your output should be similar as follows: Sample Run: Person: Peter Student: Susan (Sophomore) Instructor: Frank (Professor) 1/2
Expert Answer:
Answer rating: 100% (QA)
class Person private String name private String address private long phoneNumber public Person Empty ... View the full answer
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these programming questions
-
In each of the questions below the first option is priced correctly. Indicate how the second option should be priced in relation to the first call. Question la Price Expiry Exercise Stock Beta of...
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
Using Java: Create an application for managing inventory data, consisting of two classes: InvTracker and InvItem, both contained in the InvTracker.java file. Submit your source code: the...
-
Evaluate the integral (4e* + 2 In (2))dx.
-
You have been sitting in the waiting room of your mechanic's shop for more than an hour. With the knowledge that products are different from services, develop a list of the things the shop manager...
-
Sala Co. is contemplating the replacement of an old machine with a new one. The following information has been gathered: If the old machine is replaced, it can be sold for $20,000. 1. Which of the...
-
Explain how search can be used to solve constraint satisfaction problems, such as the eight-queens problem. What difficulties arise when such problems become extremely large (e.g., the...
-
On January 1, Paisley, Inc., paid $560,000 for all of Skyler Corporations outstanding stock. This cash payment was based on a price of $180 per share for Skylers $100 par value preferred stock and...
-
6. A jellyfish is floating in a water-filled aquarium 1.00 m behind a flat plane of glass 6.00 cm thick and having an index of refraction of 1.50. a. Where is the image of the jellyfish located? b....
-
Sports of All Sorts produces, distributes, and sells high-quality skateboards. Its supply chain consists of three factories (located in Detroit, Los Angeles, and Austin) that produce skateboards. The...
-
Write a Python script that demonstrates the use of threading to perform multiple tasks concurrently.
-
What are three provisions in many corporate charters that deter takeovers?
-
What factors improve the effectiveness of a board of directors?
-
What are the two primary forms of corporate governance provisions that correspond to the stick and the carrot?
-
Which project would each method select? (IRR: A; MIRR: B; NPV: B)
-
What factors can lead to an increasing marginal cost of capital? How might this affect capital budgeting?
-
Sunland Company manufactures bowling balls through two processes: Molding and Packaging. In the Molding Department, the urethane, rubber, plastics, and other materials are molded into bowling balls....
-
Find a least expensive route, in monthly lease charges, between the pairs of computer centers in Exercise 11 using the lease charges given in Figure 2. a) Boston and Los Angeles b) New York and San...
-
Write a program to animate the enqueue and dequeue operations on a queue, as shown in Figure 24.20b. Stack Anmation www.cs.armstrong.edulang/animatlon/vrab/Queus html head tail 45 3 3 13 Enter a...
-
Suppose a file named Exercise17_07.dat has been created using the ObjectOutputStream. The file contains Loan objects. The Loan class in Listing 10.2 does not implement Serializable. Rewrite the Loan...
-
Suppose you shop for rice in two different packages. You would like to write a program to compare the cost. The program prompts the user to enter the weight and price of the each package and displays...
-
Pegasus Veterinary Hospital (PVH) is a partnership of five veterinarian surgeons who specialize in treating horses. PVH is located in a $25 million facility on 20 acres of land, employing over 40...
-
A tender evaluation method specifies 60% price and 40% quality. What is the weighted score of a tender that scored 80 points (out of 100) for price and 60 for quality?
-
You are a recently appointed purchasing manager who is overseeing terms and con- ditions of contract for an important international purchase with a UN country. What rules should you be particularly...
Study smarter with the SolutionInn App