You are on page 1of 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