Lab Ass2 Report
Lab Ass2 Report
(CSC186)
TITLE:
LAB ASSESSMENT 2
Question 1
Source Code (Main)
import java.util.Scanner;
import java.text.*;
//STEP 2 : INPUT
//OR
//SETTER/MUTATOR
serviceObj.setPrice(pr);
serviceObj.setServiceFee(sf);
serviceObj.setAddCharge(ac);
//STEP : MANIPULATION
// b i)
System.out.println(serviceObj.ToString() + "\nTotal cost :RM " +
serviceObj.calcTotalCost());
//b ii)
2
serviceObj.setServiceFee (5);
//b iii)
double prodPrice = serviceObj.getPrice();
double dis = 0 ;
//b iv)
System.out.println("\n\n*******************************");
System.out.println("Detail price : ");
System.out.println("Product price : "+serviceObj.getPrice());
System.out.println("Service Fee : "+serviceObj.getServiceFee()+"
% ");
System.out.println("Additional Charges :RM
"+serviceObj.getAddCharge());
System.out.println("Discoutnt : RM: "+dis);
System.out.println("Total price after discount : RM
"+df.format(totCosAfter));
System.out.println("\n\n*******************************");
}
}
3
Source code (Class)
public class PersonalService {
// DATA MEMBERS
private double price ;
private double serviceFee;
private double addCharge;
//METHOD MEMBERS
//DEFAULT CONSTRUCTOR
public PersonalService(){
price = 0;
serviceFee = 0;
addCharge = 0;
}
//NORMAL CONSTRUCTOR
public PersonalService(double price ,double serviceFee, double
addCharge){
this.price = price;
this.serviceFee= serviceFee;
this.addCharge = addCharge;
}
//COPY CONSTRUCTOR
public PersonalService(PersonalService ps){
price = ps.price;
addCharge = ps.addCharge;
serviceFee = ps.serviceFee;
}
//SETTER/MUTATOR
4
addCharge = ac;
}
//GETTER/ACCESSOR/RETRIEVER
public double getPrice(){
return price ;
}
//PROCESSOR
public double calcTotalCost(){
return (price + (price * serviceFee/100) + addCharge);
//PRINTER
public String ToString(){
return "\n\nPrice: RM "+price+ "\nService Fee (%) : "
+serviceFee+ "\nAdditinal Charge : RM" + addCharge ;
}
}
Sample input
Enter price : RM 10
5
Sample Output
Price: RM 101.0
*******************************
Detail price :
6
Question 2
String citizenType;
int wardClass;
do {
System.out.print(" \nPlease enter ward class ): ");
wardClass = scanner.nextInt();
if (wardClass != 2) {
System.out.println("Sorry only Ward Class 2 allowed");
}
} while (wardClass != 2);
do {
System.out.print("\nEnter citizen type m / nm ): ");
citizenType = scanner2.nextLine();
if (!citizenType.equalsIgnoreCase("M")) {
System.out.println("Sorry , only Malaysian allowed ");
}
} while (!citizenType.equalsIgnoreCase("M"));
7
double totalPrice = patient.calcTotalPrice();
patient.display(totalPrice);
scanner.close();
scanner2.close();
}
}
public WardAdmission () {
this.PatientName=PatientName ;
this.PatientAge=PatientAge ;
this.WardClass=WardClass ;
8
this.CitizenType=CitizenType;
this.NumOfDay=NumOfDay ;
9
public int getWardClass(){
return WardClass;
}
double priceperday = 0;
10
double TotalPrice = priceperday*NumOfDay;
return TotalPrice;
}
}
}
Sample input
11
Sample output
Patient age : 19
Ward class :2
Number of Day : 2
12