Hello everyone, I have been stuck on this program for about a week... I am trying to learn how to use and create my own methods and such, but I don't have a book and am just learning from random things I read. Anyway, this program is supposed to use two methods that I made (residentcust and businesscust). These are supposed to contain the math used to find the prices for each, and the main method should call these to give the answer and such. I keep getting errors about things not initialized and a friend was trying to help me saying that I need to pass noOfPremChannels to the methods, but not sure how to do that really... any help is appreciated. Here is the code...
-thank you-
import java.util.*;
import java.io.*;
public class CableCompanyBilling
{
static Scanner console = new Scanner(System.in);
//Named constants - residential customers
static final double R_BILL_PROC_FEE = 4.50;
static final double R_BASIC_SERV_COST = 20.50;
static final double R_COST_PREM_CHANNEL = 7.50;
//Named constants - business customers
static final double B_BILL_PROC_FEE = 15.00;
static final double B_BASIC_SERV_COST = 75.00;
static final double B_BASIC_CONN_COST = 5.00;
static final double B_COST_PREM_CHANNEL = 50.00;
public static void main(String[] args)
{
//Variable declaration
int accountNumber;
char customerType;
int noOfPremChannels;
int noOfBasicServConn;
double amountDue;
System.out.println("This program computes "
+ "a cable bill.");
System.out.print("Enter the account "
+ "number: "); //Step 1
accountNumber = console.nextInt(); //Step 2
System.out.println();
System.out.print("Enter the customer type: "
+ "R or r (Residential), "
+ "B or b(Business): "); //Step 3
customerType = console.next().charAt(0);
System.out.print("Enter the number of "
+ "premium channels: ");
noOfPremChannels = console.nextInt();
System.out.println();
System.out.println("Account number = "
+ accountNumber);
if (customerType == 'R' || customerType == 'r')
{
amountDue = residentcust();
}
else if (customerType == 'B' || customerType == 'b'){
amountDue = businesscust();
}
System.out.printf("Amount due = $%.2f %n",
amountDue);
}
public static double residentcust()
{
int noOfPremChannels;
double amountDue;
int accountNumber;
amountDue = R_BILL_PROC_FEE + //Step 5c
R_BASIC_SERV_COST +
noOfPremChannels *
R_COST_PREM_CHANNEL;
return amountDue;
}
public static double businesscust()
{
int noOfPremChannels;
double amountDue;
int accountNumber;
int noOfBasicServConn;
if (noOfBasicServConn <= 10) //Step 6e
amountDue = B_BILL_PROC_FEE +
B_BASIC_SERV_COST +
noOfPremChannels *
B_COST_PREM_CHANNEL;
else
amountDue = B_BILL_PROC_FEE +
B_BASIC_SERV_COST +
(noOfBasicServConn - 10) *
B_BASIC_CONN_COST +
noOfPremChannels *
B_COST_PREM_CHANNEL;
return amountDue;
}
}