Question

Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super...

Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE)

Create a class Person which is a super class. The class includes four private String instance variables: first name, last name, social security number, and state. Write a constructor and get methods for each instance variable. Also, add a toString method to print the details of the person. After that create a class Teacher which extends the class, Person. Add a private instance variable to store number of courses. Write a constructor and a get method for the number of courses and override toString method for Teacher. Then, create PersonTest class and create an object from the class Teacher and an object from the class Person. Display the details of Teacher and Person.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Person.java

public class Person {

// private instance variables

private String firstName;

private String lastName;

private String ssn;

private String state;

// parameterized constructor

public Person(String firstName, String lastName, String ssn, String state) {

this.firstName = firstName;

this.lastName = lastName;

this.ssn = ssn;

this.state = state;

}

// getter methods

public String getFirstName() {

return firstName;

}

public String getLastName() {

return lastName;

}

public String getSsn() {

return ssn;

}

public String getState() {

return state;

}

// override toString() to display person details

@Override

public String toString() {

return "Person [First Name=" + firstName + ", Last Name=" + lastName + ", SSN=" + ssn + ", State=" + state + "]";

}

}

Teacher.java

public class Teacher extends Person {

// private instance variable

private int numOfCourses;

// parameterized constructor

public Teacher(String firstName, String lastName, String ssn, String state, int numOfCourses) {

super(firstName, lastName, ssn, state); // calls super class constructor

this.numOfCourses = numOfCourses;

}

// getter method

public int getNumOfCourses() {

return numOfCourses;

}

// override toString() method to display teacher details

@Override

public String toString() {

return "Teacher [ First Name= "+getFirstName()+" Last Name= "+getLastName()+" SSN="+getSsn()+" State="+getState()+" Number Of Courses=" + numOfCourses + "]";

}

}

PersonTest.java

public class PersonTest {

public static void main(String[] args) {

// creating Teacher class object

Teacher teacher=new Teacher("Steve", "Rogers", "A12", "California", 3);

// creating Person class object

Person person=new Person("Tony", "Stark", "A13", "New York");

System.out.println(teacher);

System.out.println(person);

}

}

Output

Teacher [ First Name= Steve Last Name: Rogers SSN-A12 State-California Number of Courses-3] Person [First Name-Tony, Last Name-Stark, SSN-A13, State-New York]

Screenshot

Add a comment
Know the answer?
Add Answer to:
Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super...
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
  • Create an Item class, which is the abstract super class of all Items.           Item class...

    Create an Item class, which is the abstract super class of all Items.           Item class includes an attribute, description of type String for every item. [for eg. Book]                                                             A constructor to initialize its data member of Item class.               Override toString() method to return details about the Item class. Create the ExtraCharge interface with the following details.                       Declare a constant RATE with value 0.25   Declare a method called calculateExtraCharge(), which returns a double value. Create the...

  • Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and...

    Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and name variables (do not include topTrick). Note: The type refers to what the breed typically does; for example, a corgi would be a “cattle herding dog.” A Shiba Inu would be a “hunting dog.” Create the setTopTrick() mutator method Dog is parent class Corgi and Driver are subclasses Complete the Corgi class: Using the UML Class diagram, declare the instance variables. Create the two...

  • in java Define a class named ComparableNames thats extends Person and implements comparable Define a class...

    in java Define a class named ComparableNames thats extends Person and implements comparable Define a class named ComparableNames that extends Person (defined below) and implements Comparable. Override the compare To method to compare the person on the basis of name. Write a test class to find the order of two ComparableNames. class Person String name; Person00 Person(String n) name=n: Hint: in class ComparableName, you only need a constructor with arg to initialize the data filed defined in the super class...

  • Java code for the following inheritance hierarchy figure.. 1. Create class Point, with two private instance...

    Java code for the following inheritance hierarchy figure.. 1. Create class Point, with two private instance variables x and y that represented for the coordinates for a point. Provide constructor for initialising two instance variables. Provide set and get methods for each instance variable, Provide toString method to return formatted string for a point coordinates. 2. Create class Circle, its inheritance from Point. Provide a integer private radius instance variable. Provide constructor to initialise the center coordinates and radius for...

  • This is for Java Programming Please use comments Customer and Employee data (15 pts) Problem Description:...

    This is for Java Programming Please use comments Customer and Employee data (15 pts) Problem Description: Write a program that uses inheritance features of object-oriented programming, including method overriding and polymorphism. Console Welcome to the Person Tester application Create customer or employee? (c/e): c Enter first name: Frank Enter last name: Jones Enter email address: frank44@ hot mail. com Customer number: M10293 You entered: Name: Frank Jones Email: frank44@hot mail . com Customer number: M10293 Continue? (y/n): y Create customer...

  • Please help with a source code for C++ and also need screenshot of output: Step 1:...

    Please help with a source code for C++ and also need screenshot of output: Step 1: Create a Glasses class using a separate header file and implementation file. Add the following attributes. Color (string data type) Prescription (float data type) Create a default constructor that sets default attributes. Color should be set to unknown because it is not given. Prescription should be set to 0.0 because it is not given. Create a parameterized constructor that sets the attributes to the...

  • Write the following program in Java. Create an abstract Vehicle class - Vehicle should have a...

    Write the following program in Java. Create an abstract Vehicle class - Vehicle should have a float Speed and string Name, an abstract method Drive, and include a constructor. Create a Tesla class - Tesla inherits from Vehicle. - Tesla has an int Capacity. - Include a constructor with the variables, and use super to set the parent class members. - Override Drive to increase the speed by 1 each time. - Add a toString to print the name, speed,...

  • USING JAVA, Class Design: Person The Person class is intended to be an abstract and simplified representation of a pers...

    USING JAVA, Class Design: Person The Person class is intended to be an abstract and simplified representation of a person. Each person will have an array of "friends" - which are other "Person" instances. Data to Store (2 Points) Name private instance variable with only private setter (2 Points) Friends private instance array with neither getter nor setter Actions Constructor o 1 Point) Take in as argument the name of the person (enforce invariants) o (1 Point) Initialize the array...

  • JAVA Create a Java project to implement a simple Name class. This class will have the...

    JAVA Create a Java project to implement a simple Name class. This class will have the following class variable: First Name, Middle Name, Last Name, and Full Name Create the accessor/getter and mutator/setter methods. In addition to these methods, create a toString() method, which overrides the object class toString() method. This override method prints the current value of any of this class object. Create a main() method to test your project.

  • Here is a sample run of the tester program: Make sure your program follows the Java...

    Here is a sample run of the tester program: Make sure your program follows the Java Coding Guidelines. Consider the following class: /** * A store superclass with a Name and Sales Tax Rate */ public class Store {      public final double SALES_TAX_RATE = 0.06;      private String name;           /**      * Constructor to create a new store      * @param newName      */      public Store(String newName)      {           name = newName;      }     ...

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