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;
}
}
![TestWaterBill /ldeaProjects TestWaterBill]- /src/TestWaterBills.java [TestWaterBill] TestWaterBill src TestWaterBills Project](http://img.homeworklib.com/questions/d8d65e60-f802-11eb-bb6f-43575b7d826c.png?x-oss-process=image/resize,w_560)
Create a java class Customer.java that will represent a water company customer. It should contain the...
Create a java class Customer.java that will represent a water company customer. It should contain the attributes, constructors, and methods listed below, and when finished should be able to allow the included file TestWaterBills.java to work correctly. Customer class Attributes firstName: String type, initial value null lastName: String type, initial value null streetAddress: String type, initial value null city: String type, initial value null state: String type, initial value null zip: String type, initial value null previousMeterReading: int type, initial...
Problem 2: based on java.util.LinkedList class, create MyStack class that should have the methods: push(), pop(), peek(), size(), isEmpty(). my linkedlist class is: public class Lab8_problem1 { private Node head, tail; private int size; public Lab8_problem1() { this.head = null; this.tail = null; this.size = 0; } //Insert a node at specifc Location public void insertAt(int value, int index) { Node newNode = new Node(); newNode.data = value; if(head == null){ head = newNode; tail = newNode; head.next...
Language Java Step 1: Design a class called Student. The Student class should contain the following data: firstName lastName studentID totalCredits gpa Your class should implement the “sets” and “gets” for the class. Include methods: equals, compareTo, toString. Change the toString method (from class) to put each member variable on a new line. Step 2: Write a driver program to test that Student works correctly. Test is with 3 students as given in class. Step 3: Write a “registration” program...
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...
Correct the mistakes public class customer { public static void main(String[] args) { D customer=new d(); d.employee(56,”ali”); d.department(7,8.6,9); } public void employee(String name, int age) { System.out.println("Your name is"+name); System.out.println(“Age is”+age); } public int department(double d, double t, int a) { System.out.println("I have java exam at 3:00"); Return(1.1); } } V. PROGRAMMING. Write a complete JAVA program to implement the following. 1. Create a class named Exponent. Its main() method accepts an integer value from a user at the keyboard,...
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...