Академический Документы
Профессиональный Документы
Культура Документы
Given the following Curtain and Dress subclasses are inherited from TailorHouse
superclass.
Superclass : TailorHouse
Attributes:
String custNo // customer I/C number
String custName // customer Name
String date // date of order
char Cust_type // regular customer or new customer
// regular customer will be given 15% discount
// from total charges
Abstract Method:
public abstract double calCharges() // method to calculate the
// charges
Subclass : Dress
Attributes:
String dressType // Type of dress, Kebaya or Kurung or Jubah
boolean silk; // either Yes or No to silk
Subclass : Curtain
Attributes:
int windows; // total number of windows
int doors; // total number of doors
a) Write the normal constructors for both sub classes (exclude the constants).
(4 marks)
b) Write an abstract methods of calCharges() to calculate the total charges for both
subclasses.
(7 marks)
c) Assume the following code has been defined :
Write a program fragment to determine and display the number of “kebaya “, “kurung”
and “jubah” made by the tailor at TailorHouse.
(5 marks)
d) Write a program fragment to calculate and display the total charges of all regular
customer who sent their curtain to the TailorHouse.
(4 marks)
e) Assume that all classes have toString() methods, write a program fragment to
display the details information of TailorHouse customers.
(2 marks)
public TailorHouse()
{
custNo = null;
custName = null;
date = null;
Cust_type = '0';
}
public Curtain()
{
super();
windows = 0;
doors = 0;
}
public Curtain(String no,String name,String d,char type,int w,
int dr)
{
super(no, name, d, type);
windows = w;
doors = dr;
}
public int getWindows() { return windows; } // total
number of windows
public int getDoors() { return doors; }
public Dress()
{
super();
dressType = null;
silk = true;
}
if (super.getCust_type()== 'R')
return (0.85 * cost);
else
return cost;
}
//Sample of application
//Please write a complete task based on question
import java.util.*;
public class TailorHousApp
{
public static void main (String[] args)
{
String custNo, classType, dummy;
String custName, ct;
String date;
char Cust_type, select;
String dressType;
boolean silk;
int windows;
int doors;
Scanner s = new Scanner (System.in);
Scanner ss = new Scanner (System.in);
if (select == 'D')
{
System.out.println ("Enter customer number ");
custNo = ss.next(); // customer I/C number
System.out.println ("Enter customer name ");
custName = ss.nextLine(); // customer Name
dummy =ss.nextLine();
System.out.println ("Enter date ");
date = ss.nextLine(); // date of order
System.out.println ("Enter customer type - R(egular)
");
ct = ss.next();
Cust_type = ct.charAt(0);
System.out.println ("Enter dress type ");
dressType = ss.next();
System.out.println ("Enter silk - true or false ");
silk = s.nextBoolean();
T[i] = new Dress(custNo, custName, date, Cust_type,
dressType, silk);
}
else
{
System.out.println ("Enter customer number ");
custNo = ss.next(); // customer I/C number
System.out.println ("Enter customer name ");
custName = ss.nextLine(); // customer Name
dummy = ss.nextLine();
System.out.println ("Enter date ");
date = ss.nextLine(); // date of order
System.out.println ("Enter customer type - R(egular)
");
ct = ss.next();
Cust_type = ct.charAt(0);
System.out.println ("Enter number of windows ");
windows = s.nextInt();
System.out.println ("Enter number of doors ");
doors = s.nextInt();