Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi! hope someone could help me with this one Exercise 9.1 from murach book, crea

ID: 3558036 • Letter: H

Question

Hi! hope someone could help me with this one Exercise 9.1 from murach book, create and work with interfaces,

the codes the gave me are the next ones:

public class DisplayableTestApp
{
public static void main(String args[])
{
System.out.println("Welcome to the Displayable Test application ");

  
public interface DepartmentsConstants
{
int ADMIN = 1;
int EDITORIAL = 2 ;
int MARKETING = 3 ;
}
public interface Displayable
{
getDisplayText();
}
// create an Employee object

// display the employee information

System.out.println();

// create a Product object

// display the product information
}
}

-----------------------------------------------------------------------

public class Employee
{
private int department;
private String firstName;
private String lastName;
private double salary;

public Employee(int department, String lastName, String firstName,
double salary)
{
this.department = department;
this.lastName = lastName;
this.firstName = firstName;
this.salary = salary;
}
}

-----------------------------------------------------------------------

import java.text.NumberFormat;

public class Product
{
private String code;
private String description;
private double price;

public Product()
{
this.code = "";
this.description = "";
this.price = 0;
}

public Product(String code, String description, double price)
{
this.code = code;
this.description = description;
this.price = price;
}

public void setCode(String code)
{
this.code = code;
}

public String getCode(){
return code;
}

public void setDescription(String description)
{
this.description = description;
}

public String getDescription()
{
return description;
}

public void setPrice(double price)
{
this.price = price;
}

public double getPrice()
{
return price;
}

public String getFormattedPrice()
{
NumberFormat currency = NumberFormat.getCurrencyInstance();
return currency.format(price);
}

}

In this aerate, you'll create and implement the interface presented m this charter. You'll also create and implement an interface named Displayable that's similar to the Printable interface.

Explanation / Answer

Interface: Displayable

    public interface Displayable {
        
       String getDisplayText();
    }

Class: Employee


    public class Employee implements DepartmentConstants, Displayable
    {
        private int department;
        private String firstName;
        private String lastName;
        private double salary;
    
        public Employee(int department, String lastName, String firstName,
            double salary)
        {
            this.department = department;
            this.lastName = lastName;
            this.firstName = firstName;
            this.salary = salary;
        }
        
        
        
        public String getDisplayText(){
            
            System.out.println("Test");
             return "Department: " + ADMIN + " "
                    + "FirstName: " + firstName + " "
                    + "LastName: " + lastName + " "
                    + "Salary: " + salary + " ";
    
        }
    }


DisplayableTestApp


    public class DisplayableTestApp
    {
        public static void main(String args[])
        {
            System.out.println("Welcome to the Displayable Test application ");
    
            int department = 1;
            String lastName = "John";
            String firstName = "Mathews";
            double salary = 12345;
            
            // create an Employee object
            Displayable displayable = new Employee (department,lastName,firstName,salary);
            
    
            // display the employee information
            displayable.getDisplayText();
    
            //System.out.println();
        }
    }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote