Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Creating and Working with Interfaces

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Thanked 0 Times in 0 Posts

    Default Creating and Working with Interfaces

    I need help with this problem.

    1) Add an interface named DepartmentConstants
    2)An interface named Displayable. This interface should contain a single method named getDisplayText that returns a string.
    3)Edit the Product class so it implements the Displayable interface. the getDisplayText method in this class should format a string that can be used to display the product information.
    4) Edit the Employee class so it implements the DepartmentConstants and Displayable interfaces. The getDisplayText method in this class should work like the one in the Product class and it should use the constants in the DepatmentConstants interface to include the department name in the return.
    5)Open the DisplayableTestApp class and add code to it that creates an employee objecy, assigns it to a displayble variable, and displays the information in the Employee object at the console. To get information for an employee, you will need to use the getDisplayText method of the Displayble interface.
    6)Rub the application to make sure that it displays the employee information.
    7)Repat steps 5 and 6 for a Product Object
    8)Open the DisplayableTestApp and add a method with this signature:
    private static String displayMultiple (Displayable d, int count)

    9)Modify the code in the main method so it uses the displayMultiple method to display the employee info once and the product information twice

    here are the given code.

    Class DisplayableTest App
    public class DisplayableTestApp
        public static void main(String args[])
            System.out.println("Welcome to the Displayable Test application\n");
            // create an Employee object
            // display the employee information
            // create a Product object
            // display the product information

    Class Employee
    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;

    Class Product

    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);

  2. #2
    Super Moderator
    Join Date
    Jun 2013
    So. Maryland, USA
    My Mood
    Thanked 688 Times in 675 Posts

    Default Re: Creating and Working with Interfaces

    What help do you need? Be specific, ask a question, describe what you don't understand.

Similar Threads

  1. Interfaces...
    By eggpulusu in forum Java Theory & Questions
    Replies: 1
    Last Post: September 17th, 2013, 10:52 AM
  2. [SOLVED] What good are interfaces?
    By summit45 in forum Object Oriented Programming
    Replies: 2
    Last Post: August 18th, 2013, 09:39 PM
  3. Working with Interfaces
    By imamess in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 13th, 2012, 08:52 PM
  4. Interfaces
    By TP-Oreilly in forum Java Theory & Questions
    Replies: 13
    Last Post: December 7th, 2011, 06:58 PM
  5. Interfaces
    By leyland in forum Java Theory & Questions
    Replies: 4
    Last Post: April 5th, 2011, 08:51 PM