Homework Help Question & Answers

in java • Create an interface called Person. In this interface create a method called printData()...

in java

• Create an interface called Person. In this interface create a method called printData()


• Implement interface Person by classes Student, Teacher, Admin. You need to think the relevant data attributes for each class. Define atleast 4 attributes for each class.


• In each class override a method toString() and create a string which holds all data


• In the method printData in each class print the data using toString() method.

Design the UML and write a code to solve the above problem.

0 0
Add a comment
Answer #1
interface Person{
    void printData();
}

class Student implements Person{
    String name,course;
    int id,grade;
    @Override
    public void printData() {
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", course='" + course + '\'' +
                ", id=" + id +
                ", grade=" + grade +
                '}';
    }
}

class Teacher implements Person{
    String name,course;
    int sal,subjects;
    @Override
    public void printData() {
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "Teacher{" +
                "name='" + name + '\'' +
                ", course='" + course + '\'' +
                ", sal=" + sal +
                ", subjects=" + subjects +
                '}';
    }
}

class Admin implements Person{
    String name,department;
    int sal,experience;
    @Override
    public void printData() {
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "Admin{" +
                "name='" + name + '\'' +
                ", department='" + department + '\'' +
                ", sal=" + sal +
                ", experience=" + experience +
                '}';
    }
}

OUTPUT :

<<interface Person +printdata0: void Student Teacher Admin +name: String +course: String +id int +grade int +name: String +co

Add a comment
Know the answer?
Add Answer to:
in java • Create an interface called Person. In this interface create a method called printData()...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coin

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
  • 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....

  • In Java (The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person and...

    In Java (The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person and its two derived classes named Student and Employee. Make Faculty and Staff derived classes of Employee. A person has a name, address, phone number, and e-mail address. A student has a class status (freshman, sophomore, junior, or senior). An employee has an office, salary, and datehired. Define a class named MyDate that contains the fields year, month, and day. A faculty member has office...

  • 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...

  • Implement an abstract class named Person and two subclasses named Student and Staff in Java. A person has a name, address, phone number and e-mail address. A student has a credit hour status (freshman...

    Implement an abstract class named Person and two subclasses named Student and Staff in Java. A person has a name, address, phone number and e-mail address. A student has a credit hour status (freshman, sophomore, junior, or senior). Define the possible status values using an enum. Staff has an office, salaray, and date-hired. Implement the above classes in Java. Provide Constructors for classes to initialize private variables. Getters and setters should only be provided if needed. Override the toString() method...

  • Java Code the following interfaces - An interface called Accountable with void withdraw(double) and double getBalance()...

    Java Code the following interfaces - An interface called Accountable with void withdraw(double) and double getBalance() methods, and an interface called AccountReceivable with a void deposit(double) method. Save these two interfaces in separate Java files. Then code a class, BusinessAccount, that implements the two interfaces defined above. Define and code the necessary instance variables and constructors. Override toString() so it will return the amount of a business account. Apply the particular operations, such as withdraw and deposit, required in implementing...

  • In Java Create an interface called Amount that includes a method called setPrice (). Create an a...

    In Java Create an interface called Amount that includes a method called setPrice (). Create an abstract class named Book that inherits from the interface Amount. Include a String field for the book’s title and a double field for the book’s Price . Within the class, include a constructor that requires the book title and add two getter methods — one that returns the title and one that returns the price. Include an abstract method named setPrice (). Create a...

  • Part I (20%) [File: Student.java] Create a class called Student that has the following stored properties:...

    Part I (20%) [File: Student.java] Create a class called Student that has the following stored properties: • StudentID • First Name • Last Name Class Student should have read/write properties, constructor(s) and should implement the Academic interface. For academic methods, return zero for average, zero for credits and false for graduate. Also implement the toString() method that returns the above information as a String. Part II (5%) [File: Academic.java] Create an interface Academic that declares three methods: 1. average -...

  • Write the following in Java Design an enum called Rating, it has the following names: bad,...

    Write the following in Java Design an enum called Rating, it has the following names: bad, okay, good, better, best Design a class called Review (reviews might be for a restaurant, movie, etc), it has two attributes: a Rating type called rating, a String type called comment. Design getters and setters for the attributes. Override the toString() method to display both the rating and the comment.

  • 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...

  • 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...

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.