Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started