Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help in Java using Inheritence: Write a TitledPerson class, which you derive from the Person class. The TitledPerson class has one additional String instance

Please help in Java using Inheritence:

Write a TitledPerson class, which you derive from the Person class. The TitledPerson class has one additional String instance variable for a title such as Ms., Mr., or Dr. It has two constructors, a default constructor and one that sets both the name and title. It has a writeOutput method, a reset method, an equals method, an accessor method getTitle that returns the title, and a mutator method setTitle that changes the persons title. For two titled people to be equal they must have the same name and the same title.

Person.java:

public class Person { private String name; public Person(){ name=" "; } public Person (String initialName){ name=initialName; }

//refactor-encapsulate field getSetter public String getName() { return name; }

public void setName(String name) { this.name = name; } public void WriteOutput() { System.out.println("Name: "+name); } public boolean hasSameName(Person other){ return this.name.equalsIgnoreCase(other.name); //if (this.hasSameName(other)) } }

2. Create a Sphere class that is derived from your Circle class. Add a method called volume (the volume of a sphere is 4/3 * pi*r*r*r) .

In your main method create two Spheres, print out their circumferences and volumes and then output the larger of the two (you must use compareTo).

double r1 = keyboard.nextDouble();

double r2= keyboard.nextDouble();

Sphere one=new Sphere( r1);

Sphere two = new Sphere(r2);

SYstem.out.println(one.circumference());

System.out.println(one.volume());

//repeat for two

if(r1.compareTo(r2)>0)..

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

MySQL/PHP Database Applications

Authors: Brad Bulger, Jay Greenspan, David Wall

2nd Edition

0764549634, 9780764549632

More Books

Students also viewed these Databases questions

Question

=+ 9. What is inflation and what causes it?

Answered: 1 week ago

Question

=+6. What does the invisible hand of the marketplace do?

Answered: 1 week ago