Hey guys, I am wondering if you can help me figuring out the following. Actually
ID: 3674841 • Letter: H
Question
Hey guys,
I am wondering if you can help me figuring out the following. Actually is about creating interfaces, and have the main class call methods and interfaces.
Here is the code for product class
Ok here is the code for employee class:
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;
}
}
Netx, I have a code for Product class below
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 getFormattedPrice()
{
NumberFormat currency = NumberFormat.getCurrencyInstance();
return currency.format(price);
}
public String getDisplayableString() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public String getDisplayableTextString() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void display() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
Here is the question:
Refer to the codes above I want to code for below main class
public class DisplayableTestApp
{
public static void main(String args[])
{
System.out.println("Welcome to the Displayable Test application ");
// create an Employee object
// display the employee information
System.out.println();
// create a Product object
// display the product information
}
}
I really appreciate your assistance.
Explanation / Answer
//Interface
package employees;
public interface Displayable {
public void display();
}
//main class
package employees;
public class DisplayableTestApp
{
public static void main(String args[])
{
System.out.println("Welcome to the Displayable Test application ");
// create an Employee object
Employee emp=new Employee(1, "bhabad", "shekhar", 100000);
// display the employee information
System.out.println(emp);
System.out.println();
// create a Product object
Product p=new Product("1", "this is pulse product", 12515);
System.out.println(p);
// display the product information
}
}
//Employee class
package employees;
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;
}
@Override
public String toString() {
return "Employee [department=" + department + ", firstName=" + firstName
+ ", lastName=" + lastName + ", salary=" + salary + "]";
}
}
//Product Class
package employees;
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;
}
@Override
public String toString() {
return "Product [code=" + code + ", description=" + description
+ ", price=" + price + "]";
}
public String getFormattedPrice()
{
NumberFormat currency = NumberFormat.getCurrencyInstance();
return currency.format(price);
}
public String getDisplayableString() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public String getDisplayableTextString() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void display() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}