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.
What to turn in:
If you have any doubts, please give me comment...
class Customer {
private String firstName;
private String lastName;
private String streetAddress;
private String city;
private String state;
private String zip;
private int previousMeterReading;
private int currentMeterReading;
private int gallonsUsed;
private double currentCharges;
public Customer() {
firstName = null;
lastName = null;
streetAddress = null;
city = null;
state = null;
zip = null;
previousMeterReading = 0;
currentMeterReading = 0;
gallonsUsed = 0;
currentCharges = 0.0;
}
public Customer(String first, String last, String street, String city, String state, String zip,
int previousReading) {
this.firstName = first;
this.lastName = last;
this.streetAddress = street;
this.city = city;
this.state = state;
this.zip = zip;
this.previousMeterReading = previousReading;
}
/**
* @param currentMeterReading the currentMeterReading to set
*/
public void setCurrentMeterReading(int currentMeterReading) {
this.currentMeterReading = currentMeterReading;
}
public void calculateGallonsUsed() {
gallonsUsed = currentMeterReading - previousMeterReading;
}
public void calculateBill() {
if (gallonsUsed <= 5000)
currentCharges = (gallonsUsed / 1000) * 10.90;
else if (gallonsUsed > 5000 && gallonsUsed <= 10000)
currentCharges = (5 * 10.90) + ((gallonsUsed - 5000) / 1000) * 10.55;
else if (gallonsUsed > 10000 && gallonsUsed <= 20000)
currentCharges = (5 * 10.90) + (5 * 10.55) + ((gallonsUsed - 10000) / 1000) * 10.00;
else if (gallonsUsed > 20000 && gallonsUsed <= 30000)
currentCharges = (5 * 10.90) + (5 * 10.55) + (10 * 10.00) + ((gallonsUsed - 20000) / 1000) * 9.45;
else
currentCharges = (5 * 10.90) + (5 * 10.55) + (10 * 10.00) + (10 * 9.45)
+ ((gallonsUsed - 30000) / 1000) * 8.60;
currentCharges += 31.54;
}
public String toString() {
return "Name: "+firstName+", "+lastName+"\nAddress: "+streetAddress+", "+city+", "+state+", "+zip+"\n Previous Meter Reading: "+previousMeterReading+"\nCurrent Meter Reading: "+currentMeterReading+"\nGallons Used: "+gallonsUsed+"\nCurrent Charges: "+currentCharges;
}
/**
* @param firstName the firstName to set
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/**
* @param lastName the lastName to set
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}
/**
* @param streetAddress the streetAddress to set
*/
public void setStreetAddress(String streetAddress) {
this.streetAddress = streetAddress;
}
/**
* @param city the city to set
*/
public void setCity(String city) {
this.city = city;
}
/**
* @param state the state to set
*/
public void setState(String state) {
this.state = state;
}
/**
* @param zip the zip to set
*/
public void setZip(String zip) {
this.zip = zip;
}
/**
* @param previousMeterReading the previousMeterReading to set
*/
public void setPreviousMeterReading(int previousMeterReading) {
if (previousMeterReading < 0)
throw new RuntimeException("The value for the previous meter reading is “ + “ invalid, it must be greater than or equal to zero");
this.previousMeterReading = previousMeterReading;
}
/**
* @param gallonsUsed the gallonsUsed to set
*/
public void setGallonsUsed(int gallonsUsed) {
this.gallonsUsed = gallonsUsed;
}
/**
* @param currentCharges the currentCharges to set
*/
public void setCurrentCharges(doubel currentCharges) {
this.currentCharges = currentCharges;
}
/**
* @return the firstName
*/
public String getFirstName() {
return firstName;
}
/**
* @return the lastName
*/
public String getLastName() {
return lastName;
}
/**
* @return the streetAddress
*/
public String getStreetAddress() {
return streetAddress;
}
/**
* @return the city
*/
public String getCity() {
return city;
}
/**
* @return the state
*/
public String getState() {
return state;
}
/**
* @return the zip
*/
public String getZip() {
return zip;
}
/**
* @return the previousMeterReading
*/
public int getPreviousMeterReading() {
return previousMeterReading;
}
/**
* @return the currentMeterReading
*/
public int getCurrentMeterReading() {
return currentMeterReading;
}
/**
* @return the gallonsUsed
*/
public int getGallonsUsed() {
return gallonsUsed;
}
/**
* @return the currentCharges
*/
public doubel getCurrentCharges() {
return currentCharges;
}
}
If you have any doubts, please give me comment...
class Customer {
private String firstName;
private String lastName;
private String streetAddress;
private String city;
private String state;
private String zip;
private int previousMeterReading;
private int currentMeterReading;
private int gallonsUsed;
private double currentCharges;
public Customer() {
firstName = null;
lastName = null;
streetAddress = null;
city = null;
state = null;
zip = null;
previousMeterReading = 0;
currentMeterReading = 0;
gallonsUsed = 0;
currentCharges = 0.0;
}
public Customer(String first, String last, String street, String city, String state, String zip,
int previousReading) {
this.firstName = first;
this.lastName = last;
this.streetAddress = street;
this.city = city;
this.state = state;
this.zip = zip;
this.previousMeterReading = previousReading;
}
/**
* @param currentMeterReading the currentMeterReading to set
*/
public void setCurrentMeterReading(int currentMeterReading) {
this.currentMeterReading = currentMeterReading;
}
public void calculateGallonsUsed() {
gallonsUsed = currentMeterReading - previousMeterReading;
}
public void calculateBill() {
if (gallonsUsed <= 5000)
currentCharges = (gallonsUsed / 1000) * 10.90;
else if (gallonsUsed > 5000 && gallonsUsed <= 10000)
currentCharges = (5 * 10.90) + ((gallonsUsed - 5000) / 1000) * 10.55;
else if (gallonsUsed > 10000 && gallonsUsed <= 20000)
currentCharges = (5 * 10.90) + (5 * 10.55) + ((gallonsUsed - 10000) / 1000) * 10.00;
else if (gallonsUsed > 20000 && gallonsUsed <= 30000)
currentCharges = (5 * 10.90) + (5 * 10.55) + (10 * 10.00) + ((gallonsUsed - 20000) / 1000) * 9.45;
else
currentCharges = (5 * 10.90) + (5 * 10.55) + (10 * 10.00) + (10 * 9.45)
+ ((gallonsUsed - 30000) / 1000) * 8.60;
currentCharges += 31.54;
}
public String toString() {
return "Name: "+firstName+", "+lastName+"\nAddress: "+streetAddress+", "+city+", "+state+", "+zip+"\n Previous Meter Reading: "+previousMeterReading+"\nCurrent Meter Reading: "+currentMeterReading+"\nGallons Used: "+gallonsUsed+"\nCurrent Charges: "+String.format("%.2f", currentCharges);
}
/**
* @param firstName the firstName to set
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/**
* @param lastName the lastName to set
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}
/**
* @param streetAddress the streetAddress to set
*/
public void setStreetAddress(String streetAddress) {
this.streetAddress = streetAddress;
}
/**
* @param city the city to set
*/
public void setCity(String city) {
this.city = city;
}
/**
* @param state the state to set
*/
public void setState(String state) {
this.state = state;
}
/**
* @param zip the zip to set
*/
public void setZip(String zip) {
this.zip = zip;
}
/**
* @param previousMeterReading the previousMeterReading to set
*/
public void setPreviousMeterReading(int previousMeterReading) {
if (previousMeterReading < 0)
throw new RuntimeException("The value for the previous meter reading is “ + “ invalid, it must be greater than or equal to zero");
this.previousMeterReading = previousMeterReading;
}
/**
* @param gallonsUsed the gallonsUsed to set
*/
public void setGallonsUsed(int gallonsUsed) {
this.gallonsUsed = gallonsUsed;
}
/**
* @param currentCharges the currentCharges to set
*/
public void setCurrentCharges(doubel currentCharges) {
this.currentCharges = currentCharges;
}
/**
* @return the firstName
*/
public String getFirstName() {
return firstName;
}
/**
* @return the lastName
*/
public String getLastName() {
return lastName;
}
/**
* @return the streetAddress
*/
public String getStreetAddress() {
return streetAddress;
}
/**
* @return the city
*/
public String getCity() {
return city;
}
/**
* @return the state
*/
public String getState() {
return state;
}
/**
* @return the zip
*/
public String getZip() {
return zip;
}
/**
* @return the previousMeterReading
*/
public int getPreviousMeterReading() {
return previousMeterReading;
}
/**
* @return the currentMeterReading
*/
public int getCurrentMeterReading() {
return currentMeterReading;
}
/**
* @return the gallonsUsed
*/
public int getGallonsUsed() {
return gallonsUsed;
}
/**
* @return the currentCharges
*/
public doubel getCurrentCharges() {
return currentCharges;
}
}
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...
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 called Restaurant that is the base class for all restaurants. It should have attributes for the restaurant's name{protected) and seats (private attribute that represents the number of seats inside the restaurant). Use the UML below to create the methods. Note, the toString prints the name and the number of seats. Derive a class Fastfood from Restaurant This class has one attribute - String slogan (the slogan that the restaurants uses when advertising - e.g., "Best Burgers Ever!")....
Write a Java program to read customer details from an input text file corresponding to problem under PA07/Q1, Movie Ticketing System The input text file i.e. customers.txt has customer details in the following format: A sample data line is provided below. “John Doe”, 1234, “Movie 1”, 12.99, 1.99, 2.15, 13.99 Customer Name Member ID Movie Name Ticket Cost Total Discount Sales Tax Net Movie Ticket Cost Note: if a customer is non-member, then the corresponding memberID field is empty in...
Background You will create a Java class that simulates a water holding tank. The holding tank can hold volumes of water (measured in gallons) that range from 0 (empty) up to a maximum. If more than the maximum capacity is added to the holding tank, an overflow valve causes the excess to be dumped into the sewer system. Assignment The class will be named HoldingTank. The class attributes will consist of two int fields – current and maxCapacity. The fields...
Inheritance and Polymorphism (use Pet.java) You are given a class named Pet.java. Create two child classes named Cat.java and Dog.java. Cat.java should add attributes for color and breed. Dog.java should add attributes for breed and size (use String for small, medium, large). Add appropriate constructors, getter/setter methods and toString() methods. In a separate file named PetDriver.java, create a main. In the main, create an ArrayList of Pet. Add an instance of Cat and an instance of Dog to the ArrayList....
CS1180 Lab 9 Students will learn how to create a user-defined class. Part 1. Create a user-defined class. 1. Follow the UML diagram below to create a user-defined class, Automobile When implementing the constructors, use the default value of 0 for numeric types and "unknown" for VehicleMake and VehicleModel when not given as a parameter Implement the toString method in a format ofyour choosing, as long as it clearly includes information for all four member variables Make sure to include...
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...
Classes A Customer Points class maintains information about a customer. This information is the customer name (entire name as a String) and the amount of points (as an int) the customer has accrued. Methods: Constructor: Receives a name and sets the name field to the received name and sets the points field to 0 (zero). getName: Returns the customer's name getPoints: Returns the customer's current points toString: Returns a String representation of the current state in the form-name points, i.e....
You are to create a class Appointment.java that will have the following: 5 Instance variables: private String month private int day private int year private int hour private int minute 1 default constructor public Appointment() 1 non-default constructor that accepts arguments for all instance variables, your constructor must call the setter methods below to set the values of the instance variables public Appointment(String monthPassed, int dayPassed, int yearPassed, int hourPassed, int minutePassed) 5 setter methods (one for each instance variable)...