Question

Java program. Code the following interfaces, implement them, and use the interface as a parameter, respectively:...

Java program. Code the following interfaces, implement them, and use the interface as a parameter, respectively: a. An interface called Printable with a void print() method. b. An interface called EmployeeType with FACULTY and CLASSIFIED integer data. The value of FACULTY is 1 and CLASSIFIED is 2. a. A class called Employee to implement the two interfaces. Its constructor will initialize three instance data as name, employeeType, and salary. Implementation of method print() will display name, employeeType, and salary; salary is to be displayed as a currency format. You may use an if-else construct to identify the nature of the 281 employeeType—FACULTY or CLASSIFIED—so the particular information of each category can be shown. b. Write a static method called printInfo() with a void return type in a class called Output. The first parameter is a Printable type, and it will accept the object of Employee as an argument. The second parameter is an integer type representing the quantity of printings. The method will display all employee information with the specified number of printings. c. Write a driver code to test the above code. Create at least three objects with instance data of your choice. Call printInfo() to display the information of each object, respectively. You may decide how many times to print the information.

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

The Java Code is as follows:

import java.util.*;
import java.text.*;
interface Printable // Printable Interface
{
    void print();
}

interface EmployeeType //EmpoyeeType Interface
{
    int FACULTY=1;
    int CLASSIFIED=2;
}

class Employee implements Printable,EmployeeType //Employee class implements the two interfaces
{
    String name;
    int employeeType;
    double salary;
   //Constructor
    public Employee(String n,int type,double s)
    {
        this.name = n;
        this.employeeType = type;
        this.salary = s;
    }
   //print method definition
    public void print()
    {
        System.out.println("Name = " +name);
        if(employeeType == FACULTY)
            System.out.println("Employee Type = Faculty");
        else
            System.out.println("Employee Type = Classified");
        System.out.print("Salary = ");
        Locale locale = new Locale("en", "US");    
        //Formatting Salry in Currency Format
        System.out.println(NumberFormat.getCurrencyInstance(new Locale("en", "US")).format(salary));
    }
}

class Output
{
    //printInfo Method in Ouptut class to print Employee Details
    public static void printinfo(Printable p, int num)
    {
        Employee e=(Employee) p;
        for(int i=0;i<num;i++)
            e.print();
    }

}
public class Program
{
   public static void main(String[] args) {
        Employee e1 = new Employee("Harry",1,200.2);
        Employee e2 = new Employee("Potter",2,120.00);
        Employee e3 = new Employee("James",1,160.89);
        Output.printinfo(e1,3);
        Output.printinfo(e2,2);
        Output.printinfo(e3,1);
   }
}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
Java program. Code the following interfaces, implement them, and use the interface as a parameter, respectively:...
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
  • 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 this lab you will work with abstract classes/interfaces. (Java Program) You will be implementing a...

    In this lab you will work with abstract classes/interfaces. (Java Program) You will be implementing a basic employee schema within a company. The Employee class will be an abstract class that will contain methods applicable to all employees. You will then create 2 classes called SoftwareEngineer and ProductManager. Both are different employee types based on occupation. You will create an interface called Developer which will consist of specific methods that apply to only Developers (e.g. SoftwareEngineer class will implement this,...

  • Write a java program that creates two interfaces named test1 and test2. In interface test1 the...

    Write a java program that creates two interfaces named test1 and test2. In interface test1 the member function is square. In interface test2 the member function is cube. Implement these two interfaces in "Arithmetic" class. Create one new class called ToTestInt in this class use the object of arithmetic class.

  • 0.Use Factory Design Method 1. Implement an interface called EmployeeInfo with the following constant variables: FACULTY_MONTHLY_SALARY...

    0.Use Factory Design Method 1. Implement an interface called EmployeeInfo with the following constant variables: FACULTY_MONTHLY_SALARY = 6000.00 STAFF_MONTHLY_HOURS_WORKED = 160 2. Implement an abstract class Employee with the following requirements: Attributes last name (String) first name (String) ID number (String) Sex - M or F Birth date - Use the Calendar Java class to create a date object Default argument constructor and argument constructors. Public methods toString - returning a string with the following format: ID Employee number :_________...

  • In order to do Program 6, Program 5 should bemodified.Program 6

    In order to do Program 6, Program 5 should be modified.Program 6-----------------------------------Program 4----------------------------------------------- (abstract class exception handling) Modify program4 to meet the following requirements: I. Make Person, Employee classes to abstract classes. Cl0%) 2. Add an interface interface working with a method teach() (5%) interface working void teach(String course) J 3. Modify Faculty class. (20%) a. a private data field and implement existing b. Modify Faculty class as a subclass of addition to the c. toString or print Info) method to...

  • Java Question 3 Implement a program to store the applicant's information for a visa office. You...

    Java Question 3 Implement a program to store the applicant's information for a visa office. You need to implement the following: A super class called Applicant, which has the following instance variables: A variable to store first name of type String. A variable to store last name of type String. A variable to store date of birth, should be implemented as another class to store day, month and year. A variable to store number of years working of type integer...

  • Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB....

    Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB. This interface should specify this abstract method: public abstract Product get(String productCode); Modify the ProductDB class so it implements the IProductDB interface. Write the code for the new ‘get’ method. Then remove the getProductByCode method. In the Main class, modify the code so it works with the new ProductDB class. This code should create an instance of the IProductDB interface like this: IProductDB db...

  • Code a complete Java program for the following payroll application: First, hard code the following data...

    Code a complete Java program for the following payroll application: First, hard code the following data for the object ‘Employee’ into 4 separate arrays: SSN: 478936762, 120981098, 344219081, 390846789, 345618902, 344090917 First name      : Robert, Thomas, Tim, Lee, Young, Ropal Last name       : Donal, Cook, Safrin, Matlo, Wang, Kishal Hourly rate     : 12.75, 29.12, 34.25, 9.45,   20.95, 45.10 Hours worked: 45,        40,        39,       20,      44,        10 These 4 arrays must be declared inside the class and not within any method....

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

  • I 'discovered' interfaces and I started to love them. The beauty of an interface is that...

    I 'discovered' interfaces and I started to love them. The beauty of an interface is that it is a contract, and any object that fulfills that contract can be used wherever that interface is required. The problem with an interface is that it can't have a default implementation, which is a pain for mundane properties and defeats DRY. This is also good, because it keeps the implementation and the the system decoupled. Inheritance, on the hand, maintains a tighter coupling,...

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