Problem Description: Dominion Gas Corporation would like you to develop an appli
ID: 3752944 • Letter: P
Question
Problem Description:
Dominion Gas Corporation would like you to develop an application that helps them calculate the gas consumption bill of their customers. The application would first ask for the customer account number, the customer name and the type of account (residential or commercial). Then the application asks for the gas consumed during the past month by the customer in MCF (the unit used to indicate the amount of gas consumed). After gathering all this information the application calculates the bill based on the type of account (residential or commercial) and prints out the bill.
The code must be in line with the programming standards covered in class and should provide sufficient comments to explain the code elements.
Technical Specifications:
The application will have two classes: Account and AccountTest
The Account class will have the following elements in it:
INSTANCE VARIABLES:
Instance variable for account number and its property
Instance variable customer name and its property
Instance variable balance and its property
Instance variable to store mcf
Instance variable to store the rate of the account ($8.99 for residential, $11.99 for commercial)
Instance variable to store usage charge for consumption of gas (mcf * rate)
Instance variable to store municipal charge (2% of usage charge)
Instance variable to store excise tax (5% of usage charge)
CONSTRUCTOR
A constructor that accepts the account number and the customer name and uses those two values to initialize the appropriate instance variables (account number, customer name)
METHODS
A method that calculates the bill.
This method asks the user for the type of account (residential/commercial) for which the bill is to be calculated.
It also asks the user for the MCF used.
Based on these two pieces of information, it calculates the usage charge, municipal charge, excise tax and balance. It stores all these figures in their appropriate instance variables.
A method that displays the bill.
This method simply prints out all the information about the bill such as the customer name, account number, the usage charge, municipal charge, excise tax and balance (see figures for samples of output)
The AccountTest class will have the following elements in it:
The Main method, which performs the following actions:
Asks for the account number, reads it in and stores it in a variable.
Asks for the customer name, reads it in and stores it in a variable.
Uses these two pieces of information to create an object using the Account class’s constructor.
Calls the method that calculates the bill for the object created.
Calls the method that displays the bill for the object created.
Explanation / Answer
Account.java
import java.util.Scanner;
public class Account {
//Declaring instance variables
private int accNo;
private String name;
private double balance;
private double mcf;
private double rate;
private double usageCharge;
private double municipalCharge;
private double excisetax;
//Parameterized constructor
public Account(int accNo, String name) {
this.accNo = accNo;
this.name = name;
}
public void calculateBill() {
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
//Getting the input entered by the user
System.out.print("Enter the type of account (r = residential/c = commercial):");
char ch = sc.next(".").charAt(0);
if(ch=='R' || ch=='r')
rate=8.99;
else if(ch=='c' || ch=='C')
rate=11.99;
System.out.print("Amount of gas used (in MCF) :");
mcf=sc.nextDouble();
usageCharge=mcf*rate;
municipalCharge=0.02*usageCharge;
excisetax=0.05*usageCharge;
balance=usageCharge+municipalCharge+excisetax;
}
public void displayBill()
{
System.out.println(":: BILL ::");
System.out.println("Customer Name :"+name);
System.out.println("Account Number :"+accNo);
System.out.println("Usage Charge :$"+usageCharge);
System.out.println("Municipal Charge :$"+municipalCharge);
System.out.println("Excise Charge :$"+excisetax);
System.out.println("Balance :$"+balance);
}
}
___________________
AccountTest.java
import java.util.Scanner;
public class AccountTest {
public static void main(String[] args) {
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
//Getting the input entered by the user
System.out.print("Enter Name :");
String name=sc.nextLine();
System.out.print("Enter Account Number :");
int accNo=sc.nextInt();
//Creating an instance of Accountr class
Account acc=new Account(accNo, name);
//calling the methods
acc.calculateBill();
acc.displayBill();
}
}
_________________
Output:
Enter Name :Kane Williams
Enter Account Number :2343
Enter the type of account (r = residential/c = commercial):c
Amount of gas used (in MCF) :345
:: BILL ::
Customer Name :Kane Williams
Account Number :2343
Usage Charge :$4136.55
Municipal Charge :$82.73100000000001
Excise Charge :$206.82750000000001
Balance :$4426.1085
_______________Could you plz rate me well.Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.