ONLINE SUMMER TRAINING Online Courses Free Tutorials 
 Placement Preparation 
Artificial Intelligence(AI) & Machine Learning(ML) Training in Jaipur
0 like 0 dislike
385 views
in VTU B.Tech (CSE-IV Sem) Design and Analysis of Algorithm Lab by Goeduhub's Expert (5.8k points)

Design a superclass called Staff with details as StaffId, Name, Phone, Salary. Extend this class by writing three subclasses namely Teaching (domain, publications), Technical (skills), and Contract (period). Write a Java program to read and display at least 3 staff objects of all three categories.

Goeduhub's Online Courses @Udemy

For Indian Students- INR 570/- || For International Students- $12.99/-

S.No.

Course Name

Apply Coupon

1.

Tensorflow 2 & Keras:Deep Learning & Artificial Intelligence

Apply Coupon

2.

Computer Vision with OpenCV | Deep Learning CNN Projects

Apply Coupon

3.

Complete Machine Learning & Data Science with Python Apply Coupon

4.

Natural Language Processing-NLP with Deep Learning in Python Apply Coupon

5.

Computer Vision OpenCV Python | YOLO| Deep Learning in Colab Apply Coupon

6.

Complete Python Programming from scratch with Projects Apply Coupon

1 Answer

0 like 0 dislike
by Goeduhub's Expert (5.8k points)
 
Best answer

Java Program

import java.util.Scanner;

class Staff {

    private String staffId;

    private String name;

    private long phone;

    private float salary;

    public void accept() {

        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter Staff Id: ");

        staffId = scanner.next();

        System.out.print("Enter Name: ");

        name = scanner.next();

        System.out.print("Enter Phone: ");

        phone = scanner.nextLong();

        System.out.print("Enter Salary: ");

        salary = scanner.nextFloat();

    }

    public void display() {

        System.out.println("Staff Id: " + staffId);

        System.out.println("Name: " + name);

        System.out.println("Phone: " + phone);

        System.out.println("Salary: " + salary);

    }

}

class Teaching extends Staff {

    private String domain;

    private String[] publications;

    public void accept() {

        super.accept();

        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter Domain: ");

        domain = scanner.next();

        System.out.print("Enter Number of Publications: ");

        int n = scanner.nextInt();

        publications = new String[n];

        System.out.print("Enter Publications: ");

        for (int i = 0; i < n; i++) {

            publications[i] = scanner.next();

        }

    }

    public void display() {

        super.display();

        System.out.println("Domain: " + domain);

        System.out.println("Publications:");

        for (int i = 0; i < publications.length; i++) {

            System.out.println(publications[i]);

        }

    }

}

class Technical extends Staff {

    private String[] skills;

    public void accept() {

        super.accept();

        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter Number of Skills: ");

        int n = scanner.nextInt();

        skills = new String[n];

        System.out.println("Enter Skills:");

        for (int i = 0; i < n; i++) {

            skills[i] = scanner.next();

        }

    }

    public void display() {

        super.display();

        System.out.println("Skills:");

        for (int i = 0; i < skills.length; i++) {

            System.out.println(skills[i]);

        }

    }

}

class Contract extends Staff {

    private int period;

    public void accept() {

        super.accept();

        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter Period: ");

        period = scanner.nextInt();

    }

    public void display() {

        super.display();

        System.out.println("Period: " + period);

    }

}

class Main {

    public static void main(String[] args) {

        Teaching teaching = new Teaching();

        Technical technical = new Technical();

        Contract contract = new Contract();

        System.out.println("Enter Details for Teaching Staff Member");

        teaching.accept();

        System.out.println("Enter Details for Technical Staff Member");

        technical.accept();

        System.out.println("Enter Details for Contract Staff Member");

        contract.accept();

        System.out.println("Details for Teaching Staff Member are");

        teaching.display();

        System.out.println("Details for Technical Staff Member are");

        technical.display();

        System.out.println("Details for Contract Staff Member are");

        contract.display();

    }

}

Output

Enter Details for Teaching Staff Member

Enter Staff Id: Abc101

Enter Name: Tom

Enter Phone: 9876543210

Enter Salary: 30000

Enter Domain: Physics

Enter Number of Publications: 2

Enter Publications: quantum

electro

Enter Details for Technical Staff Member

Enter Staff Id: Acd123

Enter Name: Campbell

Enter Phone: 1234567890

Enter Salary: 35000

Enter Number of Skills: 2

Enter Skills:

C

Java

Enter Details for Contract Staff Member

Enter Staff Id: Tmp223

Enter Name: Jhonny

Enter Phone: 1357924680

Enter Salary: 25000

Enter Period: 2

Details for Teaching Staff Member are

Staff Id: Abc101

Name: Tom

Phone: 9876543210

Salary: 30000.0

Domain: Physics

Publications:

quantum

electro

Details for Technical Staff Member are

Staff Id: Acd123

Name: Campbell

Phone: 1234567890

Salary: 35000.0

Skills:

C

Java

Details for Contract Staff Member are

Staff Id: Tmp223

Name: Jhonny

Phone: 1357924680

Salary: 25000.0

Period: 2


For more VTU IV Sem DAA Lab Experiments Click here


Our Mentors(For AI-ML)


Sharda Godara Chaudhary

Mrs. Sharda Godara Chaudhary

An alumna of MNIT-Jaipur and ACCENTURE, Pune

NISHA (IIT BHU)

Ms. Nisha

An alumna of IIT-BHU

Related questions

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 
...