More Info:
if (previousMeterReading < 0)
throw new RuntimeException(“The value for the previous meter reading is “ + “ invalid, it must be greater than or equal to zero”);
Rate Schedule |
|
gallons/month |
rate |
first 5,000 |
$10.90 per 1,000 gallons |
next 5, 000 |
$10.55 per 1,000 gallons |
next 10,000 |
$10.00 per 1, 000 gallons |
next 10,000 |
$9.45 per 1,000 gallons |
all Over 30,000 |
$8.60 per 1,000 gallons |
The minimum customer bill is $31.54
Use String.format OR printf so that the bill is displayed correctly as dollars and cents with 2 decimal places.
public class TestWaterBills{ public static void main(String[] args){ Customer accountOne = new Customer("Sam", "Lewis", "123 Lane Crossing", "Fairmont", "WV", "26554", 912333); Customer accountTwo = new Customer("Terry", "Samuels", "12 Morgan Run Rd", "Fairmont", "WV", "26554", 845714); Customer accountThree = new Customer("Anne", "Thomas", "88 Bailey Creek Rd.", "Fairmont", "WV", "26554", 125223); Customer accountFour = new Customer("Frank", "Barns", "210 Bailey Creek Rd.", "Fairmont", "WV", "26554", 125987); accountOne.setCurrentMeterReading(925412); accountOne.calculateBill(); // the next statement should print out all of the information for account one // Sam Lewis, billed amount should be: $138.04 System.out.println( accountOne.toString()); // now do account two accountTwo.setCurrentMeterReading(851236); accountTwo.calculateBill(); // the next statement should print out all of the information for account Two // Terry Samuels, billed amount should be: $60.01 System.out.println( accountTwo.toString()); accountThree.setCurrentMeterReading(130001); accountThree.calculateBill(); // the next statement should print out all of the information for account Three // Anne Thomas, billed amount should be: $52.08 System.out.println( accountThree.toString()); accountFour.setCurrentMeterReading(127250); accountFour.calculateBill(); // the next statement should print out all of the information for account Four // Frank Barns, billed amount should be: $31.54 System.out.println( accountFour.toString()); } }
Please let me know if you have any doubts or you want me to modify the answer. And if you find this answer useful then don't forget to rate my answer as thumps up. Thank you! :)
public class TestWaterBills{
public static void main(String[] args){
Customer accountOne =
new Customer("Sam", "Lewis", "123 Lane Crossing", "Fairmont",
"WV",
"26554", 912333);
Customer accountTwo =
new Customer("Terry", "Samuels", "12 Morgan Run Rd", "Fairmont",
"WV",
"26554", 845714);
Customer accountThree =
new Customer("Anne", "Thomas", "88 Bailey Creek Rd.", "Fairmont",
"WV",
"26554", 125223);
accountOne.setCurrentMeterReading(925412);
accountOne.calculateBill();
System.out.println(
accountOne.toString());
accountTwo.setCurrentMeterReading(851236);
accountTwo.calculateBill();
System.out.println(
accountTwo.toString());
accountThree.setCurrentMeterReading(130001);
accountThree.calculateBill();
System.out.println(
accountThree.toString());
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class Customer{
private String firstName;
private String lastName;
private String city;
private String state;
private String zip;
private int previousMeterReading=0;
private int currentMeterReading=0;
private int gallonsUsed=0;
private double currentCharges=0.0;
private double previousBalance=0;
private double lastPayment=0;
private double penalty=0;
public Customer(String sam, String first,
String last, String city, String state, String zip, int
previousReading){
this.firstName =
first;
this.lastName =
last;
this.city = city;
this.state =
state;
this.zip = zip;
this.previousMeterReading = previousReading;
}
public void setCurrentMeterReading(int
reading){
currentMeterReading =
reading;
if(currentMeterReading>0 ||
currentMeterReading>previousMeterReading){
calculateGallonsUsed();
}
else{
throw new ArithmeticException("Please input a valid input.");
}
}
public void calculatePenalty(){
}
private void calculateGallonsUsed(){
gallonsUsed=this.currentMeterReading -
this.previousMeterReading;
}
public void calculateBill(){
if(this.gallonsUsed
<= 5000){
this.currentCharges = 10.90*this.gallonsUsed/1000;
}
else
if(this.gallonsUsed>5000 &&
this.gallonsUsed<=10000){
this.currentCharges =10.55*(this.gallonsUsed-5000)/1000 +
10.90*5000/1000;
}
else
if(this.gallonsUsed>10000 &&
this.gallonsUsed<=20000){
this.currentCharges = 10.00*(this.gallonsUsed-10000)/1000 +
10.55*5000/1000 + 10.90*5000/1000;
}
else
if(this.gallonsUsed>20000 &&
this.gallonsUsed<=30000){
this.currentCharges = 9.45*(this.gallonsUsed-20000)/1000 +
10.00*10000/1000 + 10.55*5000/1000 + 10.90*5000/1000;
}
else{
this.currentCharges = 8.60*(this.gallonsUsed-30000)/1000 +
9.45*10000/1000 + 10.00*10000/1000 + 10.55*5000/1000 +
10.90*5000/1000;
}
}
public String toString(){
String out =
String.format(this.firstName+" "+this.lastName+", "+",
"+this.city+", "+this.state+" "+this.zip+". The account bill is:
%.2f", this.currentCharges);
return out;
}
//getters listed here
public String getFirstName(){
return
this.firstName;
}
public String getLastName(){
return
this.lastName;
}
public String getCity(){
return this.city;
}
public String getState(){
return this.state;
}
public String getZip(){
return this.zip;
}
public int getPreviousMeterReading(){
return
this.previousMeterReading;
}
public int getCurrentMeterReading(){
return
this.currentMeterReading;
}
public int getGallonsUsed(){
return
this.gallonsUsed;
}
public double getCurrentCharges(){
return
this.currentCharges;
}
public double getPreviousBalance(){
return
this.previousBalance;
}
public double getLastPayment(){
return
this.lastPayment;
}
public double getPenalty(){
return
this.penalty;
}
//end of getters list
//start of setters list
public void setFirstName(String newFirst){
this.firstName =
newFirst;
}
public void setLastName(String
newLast){
this.lastName =
newLast;
}
public void setCity(String newCity){
this.city =
newCity;
}
public void setState(String newState){
this.state =
newState;
}
public void setZip(String newZip){
this.zip = newZip;
}
public void setPreviousMeterReading(int
newPreviousMeterReading){
this.previousMeterReading = newPreviousMeterReading;
}
public void setMeterReading(int
newMeterReading){
this.currentMeterReading
= newMeterReading;
}
public void setGallonsUsed(int
newGallons){
this.gallonsUsed =
newGallons;
}
public void setCurrentCharges(double
newCharges){
this.currentCharges =
newCharges;
}
public void setPreviousBalance(double
oldBalance){
this.previousBalance =
oldBalance;
}
public void setLastPayment(double
payment){
this.lastPayment =
payment;
}
public void setPenalty(double penalty){
this.penalty =
penalty;
}
}
Create a java class Customer.java that will represent a water company customer. It should contain the...
TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static constant FEE that represents the cost of clearing onecheck. Set it equal to 15 cents. Write a constructor that takes a name and an initial amount as parameters. Itshould call the constructor for the superclass. It should initializeaccountNumber to be the current value in accountNumber concatenatedwith -10 (All checking accounts at this bank are identified by the extension -10). There can be only one...
can you solve it in java please Create the following: 1. Class Invoice ( the node ) that includes three instance variables: int No; // the Invoice No String CustName; // the Customer name int Amount; // the Invoice Amount Invoice next; // points to the next Invoice Default and overloaded constructors 2. Class Shop that includes three instance variables: Invoice head; Invoice Tail; Your class should have the following: • A method that initializes the instance variables....
JAVA- Complete the code by following guidelines in comments. class CircularList { private Link current; private Link prev; public CircularList() { // implement: set both current and prev to null } public boolean isEmpty() { // implement return true; } public void insert(int id) { // implement: insert the new node behind the current node } public Link delete() { // implement: delete the node referred by current return null; } public Link delete(int id) { // implement: delete the...
Java Questions When creating a for loop, which statement will correctly initialize more than one variable? a. for a=1, b=2 c. for(a=1, b=2) b. for(a=1; b=2) d. for(a = 1&& b = 2) A method employee() is returning a double value. Which of the following is the correct way of defining this method? public double employee() c. public int employee() public double employee(int t) d. public void employee() The ____ statement is useful when you need to test a...
Problem 1 1. In the src → edu.neiu.p2 → problem1 directory, create a Java class called HW4P1 and add the following: • The main method. Leave the main method empty for now. • Create a method named xyzPeriod that takes a String as a parameter and returns a boolean. • Return true if the String parameter contains the sequential characters xyz, and false otherwise. However, a period is never allowed to immediately precede (i.e. come before) the sequential characters xyz....
Java 1. Write a getCount method in the IntArrayWorker class that returns the count of the number of times a passed integer value is found in the matrix. There is already a method to test this in IntArrayWorkerTester. Just uncomment the method testGetCount() and the call to it in the main method of IntArrayWorkerTester. 2. Write a getLargest method in the IntArrayWorker class that returns the largest value in the matrix. There is already a method to test this in...
Use inheritance to create a new class AudioRecording based on Recording class that: it will retain all the members of the Recording class, it will have an additional field bitrate (non-integer numerical; it cannot be modified once set), its constructors (non-parametrized and parametrized) will set all the attributes / fields of this class (reuse code by utilizing superclass / parent class constructors): Non-parametrized constructor should set bitrate to zero, If arguments for the parametrized constructor are illegal or null, it...
In this assignment, we will be making a program that reads in customers' information, and create a movie theatre seating with a number of rows and columns specified by a user. Then it will attempt to assign each customer to a seat in a movie theatre. 1. First, you need to add one additional constructor method into Customer.java file. Method Description of the Method public Customer (String customerInfo) Constructs a Customer object using the string containing customer's info. Use the...
Deliverable A zipped NetBeans project with 2 classes app ZipCode Address Classes Suggestion: Use Netbeans to copy your last lab (Lab 03) to a new project called Lab04. Close Lab03. Work on the new Lab04 project then. The Address Class Attributes int number String name String type ZipCode zip String state Constructors one constructor with no input parameters since it doesn't receive any input values, you need to use the default values below: number - 0 name - "N/A" type...
Create a class to represent a term in an algebraic expression. As defined here, a term consists of an integer coefficient and a nonnegative integer exponent. E.g. in the term 4x2, the coefficient is 4 and the exponent 2 in -6x8, the coefficient is -6 and the exponent 8 Your class will have a constructor that creates a Term object with a coefficient and exponent passed as parameters, and accessor methods that return the coefficient and the exponent. Your class...