Question

Implement a super class Person. Make two classes, Student and instructor, inherit from Person. A person has a name and a year of birth. A student has a major and an instructor has a salary. Write the class definitions, the constructors, and the methods toString for all classes. Supply a test program that test these classes and methods C: WINNT System321cmd.exe Student name : Haurice Dusseault Students Date of Birth: 1979 Students najor:- Computer Science Instructons name: Satyendra Narayan Instructors Birth: 1969 Instructors salar :65000.0 Press any key to continue -. . Please send me this answer using netbeans in java programming with sample output in caption shown in picture
0 0
Add a comment Improve this question Transcribed image text
Answer #1


Hi,
The following are the Java classes - Person.java, Student.java and Instructor.java. The class PersonTest.java is the test program that creates the objects of these classes.

I have added comments in the code for your reference.
The output and the screenshot is at the end of this answer.
If you have any changes or queries, let me know.
If this answer helps you, please upvote it.





///////////// File: Person.java /////////////
//Person Class
public class Person {
//Member variable - name and date of birth
protected String name;
protected int birthYear;
//Constructor
public Person(String newName, int newBirthYear) {
name = newName;
birthYear = newBirthYear;
}
//toString() method
@Override
public String toString() {
return "Person[name = " + name + ", birthYear=" + birthYear + "]";
}
}


///////////// File: Student.java /////////////
//Student class
public class Student extends Person {
//Member variable specific to this class
private String major;
//Constructor - to initialize the member variables
public Student(String newName, int newBirthYear, String newMajor) {
super(newName, newBirthYear);
major = newMajor;
}
//toString() method to return the value of the member variables
@Override
public String toString() {
return "Student's name: " + name + " Student's Date of Birth: " + birthYear + " Student's major:" + major;
}
}



///////////// File: Instructor.java /////////////
//Instructor class
public class Instructor extends Person {
//Member variable specific to this class
private float salary;
//Constructor - to initialize the member variables
public Instructor(String newName, int newBirthYear, float newSalary) {
super(newName, newBirthYear);
salary = newSalary;
}
//toString() method to return the value of the member variables
@Override
public String toString() {
return "Instructor's name: " + name + " Instructor's Birth: " + birthYear + " Instructor's salary: " + salary;
}
}




///////////// File: PersonTest.java /////////////

public class PersonTest {
public static void main(String[] args) {
//Create objects of Person, Student and Instructor with the data given in the instructions
Person newPerson = new Person("John Greenhouse", 1959);
Student newStudent = new Student("Maurice Dusseault", 1979, "Computer Science");
Instructor newInstructor = new Instructor("Satyendra Narayan", 1969, 65000.0f);
//Print the objects
System.out.println(newPerson);
System.out.println(newStudent);
System.out.println(newInstructor);
}
}






///////////// Output /////////////

Add a comment
Know the answer?
Add Answer to:
Please send me this answer using netbeans in java programming with sample output in caption shown...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Implement a superclass Person. Make two classes, Student and Instructor, that inherit from Person. A person...

    Implement a superclass Person. Make two classes, Student and Instructor, that inherit from Person. A person has a name and a year of birth. A student has a major, and an instructor has a salary. Writhe the class definitions, the constructors, and the methods toString for all classes. For Person the constructors should include a no-arg constructor and one that accepts in the name of the person. For student there should be a no-arg constructor and a constructor that accepts...

  • **Using NetBeans** Lesson Using inheritance to reuse classes. Deliverables person.java student.java studentAthlete.java app.java Using inheritance and...

    **Using NetBeans** Lesson Using inheritance to reuse classes. Deliverables person.java student.java studentAthlete.java app.java Using inheritance and the classes (below) The person class has first name last name age hometown a method called getInfo() that returns all attributes from person as a String The student class is a person with an id and a major and a GPA student has to call super passing the parameters for the super class constructor a method called getInfo() that returns all attributes from student...

  • Computer Programming II (CS141) Q.1. Why would you use an inner class instead of regular class?...

    Computer Programming II (CS141) Q.1. Why would you use an inner class instead of regular class? Q.2. What does this code print? Why is it polymorphic? DataSet data = new DataSet(); data.add(new BankAccount(1000)); data.add(new Coin(0.1, "dime")); System.out.println(data.getAverage()); Q.3. Can you convert a superclass reference into a subclass reference? A subclass reference into a superclass reference? If so, give examples. If not, explain why not. Q.4. Implement a superclass Person. Make two classes, Student and Instructor that inherit from Person. A...

  • How do I start this Java: Inheritance problem? • person.java • student.java • studentAthlete.java • app.java...

    How do I start this Java: Inheritance problem? • person.java • student.java • studentAthlete.java • app.java • Students should apply consistent indenting in all submissions. This can be done via the NetBeans Source menu. Contents person First name Last name app Creates 1 student-athlete object Hometown Retinfo) 1-Displays the complete information about the student-athlete object student New attributes Maior attributes getinfo) method from the superlas person Student-athlete student's rankine Overrides the method from the superclass student Video from Professor Fisher...

  • Java Programming Design a class named Person and its two subclasses named Student and Employee. A...

    Java Programming Design a class named Person and its two subclasses named Student and Employee. A person has a name, address, phone number, and email address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, date hired. Define a class named MyDate that contains the fields year, month, and day. Override the toString method in each class to display the class name and the person's name....

  • This is the question about object-oriend programming(java) please show the detail comment and prefect code of...

    This is the question about object-oriend programming(java) please show the detail comment and prefect code of each class, Thank you! This question contain 7 parts(questions) Question 1 Create a class a class Cat with the following UML diagram: (the "-" means private , "+" means public) +-----------------------------------+ | Cat | +-----------------------------------+ | - name: String | | - weight: double | +-----------------------------------+ | + Cat(String name, double weight) | | + getName(): String | | + getWeight(): double | |...

  • help please Perform the following steps: a) Using NetBeans, Create a New Java Application Project with...

    help please Perform the following steps: a) Using NetBeans, Create a New Java Application Project with Project Name BasePlusCommission Employee Test with Create Main Class check box selected. Create comments to form a descriptive header that has the course name, your name, the assignment title, and a pledge that you have neither received nor provided help to any person. Assignments submitted without this pledge will not be graded. When you have completed the steps (b) and (c) below, you will...

  • this is java m. please use netbeans if you can. 7. Person and Customer Classes Design...

    this is java m. please use netbeans if you can. 7. Person and Customer Classes Design a class named Person with fields for holding a person's name, address, and telephone number. Write one or more constructors and the appropriate mutator and accessor methods for the class's fields. Next, design a class named Customer, which extends the Person class. The Customer class should have a field for a customer number and a boolean field indicating whether the cus- tomer wishes to...

  • I need help for part B and C 1) Create a new project in NetBeans called...

    I need help for part B and C 1) Create a new project in NetBeans called Lab6Inheritance. Add a new Java class to the project called Person. 2) The UML class diagram for Person is as follows: Person - name: String - id: int + Person( String name, int id) + getName(): String + getido: int + display(): void 3) Add fields to Person class. 4) Add the constructor and the getters to person class. 5) Add the display() method,...

  • Computer Science 111 Introduction to Algorithms and Programming: Java Programming Net Beans Project #4 - Classes...

    Computer Science 111 Introduction to Algorithms and Programming: Java Programming Net Beans Project #4 - Classes and Objects (15 Points) You will create 3 new classes for this project, two will be chosen (THE TWO CHOSEN ARE TENNIS SHOE AND TREE) from the list below and one will be an entirely new class you invent. Here is the list: Cellphone Clothes JuiceDrink Book MusicBand Bike GameConsole Tree Automobile Baseball MusicPlayer Laptop TennisShoe Cartoon EnergyDrink TabletComputer RealityShow HalloweenCostume Design First Create...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT