Answer:
Customer.java
public class Customer {
private int customerNo;
private String customerName;
private double kwhourconsumed;
private double amountowed;
public int getCustomerNo() {
return customerNo;
}
public void setCustomerNo(int customerNo) {
this.customerNo = customerNo;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public double getKwhourconsumed() {
return kwhourconsumed;
}
public void setKwhourconsumed(double kwhourconsumed) {
this.kwhourconsumed = kwhourconsumed;
}
public double getAmountowed() {
return amountowed;
}
public void setAmountowed(double amountowed) {
this.amountowed = amountowed;
}
Override
public String toString() {return "Customer [customerNo=" + customerNo + ", customerName=" + customerName + ", kwhourconsumed=" + kwhourconsumed + ", amountowed=" + amountowed + "]";
}
}
PayrollReport.java
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class PayrollReport {
public static Customer getCustomerDetails(Scanner sc)
{
Customer cust= new Customer();
System.out.println("Enter Customer Number");
int customerNo=sc.nextInt();
cust.setCustomerNo(customerNo);
System.out.println("Enter Customer Name");
String customerName=sc.next();
cust.setCustomerName(customerName);
System.out.println("Enter Customer kilowatt hours used");
double kwhourconsumed=sc.nextDouble();
cust.setKwhourconsumed(kwhourconsumed);
return cust;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); //Used Scanner Class to take Input from User
//List to add all the customer details
//Customer POJO is created so that multiple Objects can be stored
List<Customer> list= new ArrayList<Customer>();
//User shoud Enter Y to add more customer details and N to stop Entering
while(true)
{
//Method to Input Customer Details
Customer cust=getCustomerDetails(sc);
//Getting back the object and setting to the list
list.add(cust);
System.out.println("To Add more customer Enter 'Y' or Else 'N'");
String yn=sc.next();
if(yn.equals("Y"))
continue;
else
break;
}
sc.close();
double amountOwed=0.0;
for(int i=0;i<list.size();i++)
{
double hrconsumed=list.get(i).getKwhourconsumed();
if(hrconsumed>0.0 && hrconsumed<=199.9)
{
amountOwed=(hrconsumed*0.11);
list.get(i).setAmountowed(amountOwed);}
else if(hrconsumed>= 200.0)
{
amountOwed=(double)(199.99*0.11)+(hrconsumed-200.0)*0.08;
list.get(i).setAmountowed(amountOwed);
}
}System.out.println("///////////////////////////");
System.out.println("Weekly Payroll Report");
double totalamountowed=0.0;
for(int i=0;i<list.size();i++)
{
System.out.println("CUSTOMER - "+i+1);
System.out.println("Customer No- "+list.get(i).getCustomerNo());
System.out.println("Customer Name- "+list.get(i).getCustomerName());
System.out.println("Customer kilowatt hours used
"+list.get(i).getKwhourconsumed());
System.out.println("Customer amount owed in $- "+list.get(i).getAmountowed());
totalamountowed=totalamountowed+list.get(i).getAmountowed();
}
System.out.println("///////////////////////////");
System.out.println("END Report");
System.out.println("Total Number of Customer "+list.size());
System.out.println("Total Amount Owed In $ "+totalamountowed);
}
}
Explanation:
Made some modifications for clarity and simplicity.