12:02:00 PM
Java II
esok test
java II, di dst jam 8, mohon baca coding.
terrace is a subclass of house.
class
house{
private String renter; // renter’s name.
private String icno; // renter’s IC no.
private String address; // renter’s address.
private double payment; // payment made by the renter.
private double extra; // extra charge.
public house(){
renter="";
icno="";
address="";
payment=0.00;
extra=0.00;
}
public house(String xrenter, String xicno, String xaddress, double xpayment, double xextra){
renter=xrenter;
icno=xicno;
address=xaddress;
payment=xpayment;
extra=xextra;
}
public String getrenter(){
return renter;
}
public String geticno(){
return icno;
}
public String getaddress(){
return address;
}
public double getpayment(){
return payment;
}
public double getextra(){
return extra;
}
public void setextra(double e){
extra=e;
}
public void setpayment(double cpayment){
payment=cpayment;
}
}
public class
terrace extends
house{
private String type;
private boolean corner;
private double balance;
public terrace(){
super();
type="";
corner=false;
balance=0.00;
}
public terrace(String xrenter, String xicno, String xaddress, double xpayment, double xextra, String xtype, boolean xcorner, double xbalance){
super(xrenter, xicno, xaddress, xpayment, xextra);
type=xtype;
corner=xcorner;
balance=xbalance;
}
public String gettype(){
return type;
}
public boolean getcorner(){
return corner;
}
public double balance(){
return balance;
}
public double calculatepayment(){
boolean status=getcorner();
double cpayment=0.00;
if(type.equalsIgnoreCase("single-storey")){
if(status==true)
cpayment=250.00-super.getpayment();
else
cpayment=150.00-super.getpayment();
}
else if(type.equalsIgnoreCase("double-storey")){
if(status==true)
cpayment=650.00-super.getpayment();
else
cpayment=400.00-super.getpayment();
}
return cpayment;
}
public void calculateextra(){
double extra=0;
if(balance()<50)
extra=0;
if(balance()<350){
if(type.equalsIgnoreCase("single-storey")&&corner)
extra=0.2*250;
else if(type.equalsIgnoreCase("single-storey")&&!corner)
extra=0.2*150;
else if(type.equalsIgnoreCase("double-storey")&&corner)
extra=0.2*650;
else if(type.equalsIgnoreCase("double-storey")&&!corner)
extra=0.2*400;
}
else{
if(type.equalsIgnoreCase("single-storey")&&corner)
extra=0.5*250;
else if(type.equalsIgnoreCase("single-storey")&&!corner)
extra=0.5*150;
else if(type.equalsIgnoreCase("double-storey")&&corner)
extra=0.5*650;
else if(type.equalsIgnoreCase("double-storey")&&!corner)
extra=0.5*400;
}
super.setextra(extra);
}
public String tostring(){
return "Renter: "+super.getrenter()+
"\nIC Number: "+super.geticno()+
"\nAddress: "+super.getaddress()+
"\nPayment: "+super.getpayment()+
"\nExtra charge: "+super.getextra()+
"\nType: "+gettype()+
"\nCorner Lot houses? "+getcorner();
}
}
Write the Java application that processes the following terrace house information:
(i)Get the data of N items from the user and store them into an array object, terrace.(3.5 marks)
(ii)Display the information of renters who has been charged with the highest extra charge.(2.5 marks)
(iii)Display the total payment the company should collect if there is no outstanding amount.(1.5 marks)
* Note: all programming solutions must be solved in separate loops.*
p/s: aku tak bawa pendrive, lagipun, blogspot kan lebih interactive, hee. :D
By: [thatreservedgirl]