import java.io.*;
public class Main {
/**
* Make by Lee Jia Ren
*/
public static void main(String[] args) throws IOException
{
BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in));
String blockNumber, flatNumber, name;
String str;
int unit;
System.out.print("Enter Your Block Number: ");
blockNumber = stdin.readLine();
System.out.print("\nEnter Your Flat Number: ");
flatNumber = stdin.readLine();
System.out.print("\nEnter Your Name: ");
name = stdin.readLine();
System.out.print("\nEnter Eletricity Unit: ");
str = stdin.readLine();
unit = Integer.parseInt(str);
EletricBillGenerator ebGen = new EletricBillGenerator();
ElectricBill eb = ebGen.getData(blockNumber, flatNumber, name, unit );
ElectricBill calcEB = ebGen.calc(eb);
ebGen.display(calcEB);
}
}
public class EletricBillGenerator {
public ElectricBill getData(String blockNumber, String flatNumber, String name, int unit){
ElectricBill eb = new ElectricBill();
eb.setBlockNumber(blockNumber);
eb.setFlatNumber(flatNumber);
eb.setName(name);
eb.setUnit(unit);
return eb;
}
public ElectricBill calc(ElectricBill inElecBill){
double billAmount;
if (inElecBill.getUnit() < 100)
{
billAmount = 0.40*inElecBill.getUnit();
}
else if (inElecBill.getUnit() < 300)
{
billAmount = 0.50*inElecBill.getUnit();
}
else
{
billAmount = 0.60*inElecBill.getUnit();
}
billAmount = billAmount>150?billAmount*1.15:billAmount;
inElecBill.setBillAmount(billAmount);
return inElecBill;
}
public void display(ElectricBill inElecBill){
System.out.println("");
System.out.println("");
System.out.println("\tElectricity Bill");
System.out.println("****************************** ************************");
System.out.println("\tName : " + inElecBill.getName());
System.out.println("\tUnits : " + inElecBill.getUnit());
System.out.println("\tTotal Charges : RM" +inElecBill.getBillAmount());
System.out.println("****************************** ************************");
}
}
public class ElectricBill {
private int unit;
private double billAmount;
private String blockNumber, flatNumber, name;
public String getBlockNumber() {
return blockNumber;
}
public void setBlockNumber(String blockNumber) {
this.blockNumber = blockNumber;
}
public String getFlatNumber() {
return flatNumber;
}
public void setFlatNumber(String flatNumber) {
this.flatNumber = flatNumber;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getUnit() {
return unit;
}
public void setUnit(int unit) {
this.unit = unit;
}
public double getBillAmount() {
return billAmount;
}
public void setBillAmount(double billAmount) {
this.billAmount = billAmount;
}
}
java.png