0% found this document useful (0 votes)
61 views

Public Interface Departmentconstants (

The document defines classes that implement a Displayable interface to display employee and product data. The DisplayableTestApp class creates Employee and Product objects, passes them to a display method, and prints their getDisplayText output. Employee returns the first name, last name, and department enum value. Product returns the description and formats the price for output.

Uploaded by

AnonymousChegg
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

Public Interface Departmentconstants (

The document defines classes that implement a Displayable interface to display employee and product data. The DisplayableTestApp class creates Employee and Product objects, passes them to a display method, and prints their getDisplayText output. Employee returns the first name, last name, and department enum value. Product returns the description and formats the price for output.

Uploaded by

AnonymousChegg
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

public interface DepartmentConstants {

enum department{

ADMIN,

EDITORIAL,

MARKETING,

public interface Displayable {

default String getDisplayText() {

return toString();

public class DisplayableTestApp {

public static void main(String args[]) {

NameHeading.getHeader("Assignment 8 - Working With Interfaces");

System.out.println("Displayable Interface Application\n");

Displayable e = new Employee(2, "Smith", "John");

display(e);

Displayable p = new Product("java", "Murach's Java Programming", 57.50);

display(p);

System.out.println();

private static void display(Displayable d) {

System.out.println(d.getDisplayText());

}
public class Employee implements Displayable,DepartmentConstants{

private int department;

private String firstName;

private String lastName;

public Employee(int department, String lastName, String firstName) {

this.department = department;

this.lastName = lastName;

this.firstName = firstName;

@Override

public String getDisplayText() {

return firstName+" "+lastName+" ("+DepartmentConstants.department.values()[department-


1]+")";

import java.text.NumberFormat;

public class Product implements Displayable{

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 getPriceFormatted() {

NumberFormat currency = NumberFormat.getCurrencyInstance();

return currency.format(price);

@Override

public String toString() {

return description;

}
import java.text.*;

import java.util.*;

public class NameHeading {

public NameHeading() {}

public static void main(String [] args)

getHeader("Testing 123");

public static void getHeader(String x) {

String date;

String assignNumber = x;

String name = "First Last";

Date now = new Date();

DateFormat longDate = DateFormat.getDateInstance(DateFormat.LONG);

date = longDate.format(now);

System.out.println("\n\n" + name);

System.out.println(assignNumber);

System.out.println(date);

System.out.println();

You might also like