Can someone help me with these errors?
scjavastudent 0 Newbie Poster
//******************************************************************************
// Arthur: Confused
// Title: Class work on methods
// Date: 11/11/09
// Description: This is a program that just does not work.
//
//******************************************************************************
import java.util.*;
public class bill3
{
static Scanner console = new Scanner(System.in);
static final double R_REGULAR_SERVICE = 10.00; // 1ST 50 MIN FREE
static final double R_CHARGES_OVER_FIFTY_MIN = 0.20; //PER MIN
static final double P_PREMIUM_SERVICE = 25.00;
static final double P_SIX_AM_TO_SIX_PM = 0.00; //1ST 75 MIN FREE
static final double P_OVER_SEVENTY_FIVE_MIN = 0.10; //PER MIN
static final double P_SIX_PM_TO_SIX_AM = 0.00; //1ST 100 MIN FREE
static final double P_OVER_ONE_HUNDRED_ONE_MIN = 0.05; //PER MIN
public static void main(String[] args)
{
int acctNum;
int numOfMinUsed;
double amtDue;
double subAmtDueA;
double subAmtDueB;
int callsSixAMtoSixPM;
int callsSixPMtoSixAM;
char serviceCode;
double RegularBill;
double PremiumBill;
System.out.print("Enter the account number: ");
acctNum = console.nextInt();
System.out.println();
System.out.print("Enter the service code type: "
+ "R or r (Regular), "
+ "P or p (Premium): ");
serviceCode = console.next().charAt(0);
System.out.println();
switch (serviceCode)
{
case 'R':
case 'r':
System.out.print("Enter the number of minutes: ");
numOfMinUsed = console.nextInt();
System.out.println();
public static double amtDue(double RegularBill)
{
if (numOfMinUsed <= 50)
amtDue = R_REGULAR_SERVICE;
else
amtDue = R_REGULAR_SERVICE +
R_CHARGES_OVER_FIFTY_MIN *
(numOfMinUsed - 50);
return amtDue;
}
break;
case 'P':
case 'p':
public static double amtDue(double PremiumBill)
{
System.out.print("Enter the number of minutes used from 6:00 AM - 6:00 PM: ");
callsSixAMtoSixPM = console.nextInt();
System.out.println();
if (callsSixAMtoSixPM <= 75)
subAmtDueA = P_PREMIUM_SERVICE;
else
subAmtDueA = P_PREMIUM_SERVICE +
P_OVER_SEVENTY_FIVE_MIN * (callsSixAMtoSixPM - 75);
System.out.print("Enter the number of minutes used from 6:00 PM - 6:00 AM: ");
callsSixPMtoSixAM = console.nextInt();
System.out.println();
if (callsSixPMtoSixAM <= 100)
subAmtDueB = P_PREMIUM_SERVICE;
else
subAmtDueB = P_PREMIUM_SERVICE +
P_OVER_ONE_HUNDRED_ONE_MIN * (callsSixPMtoSixAM - 100);
amtDue = (subAmtDueA + subAmtDueB) - P_PREMIUM_SERVICE;
return amtDue;
}
break;
default:
System.out.println("Invalid service code.");
System.out.println("Account number = " + acctNum);
System.out.println("Type of service = Regular");
System.out.println("Number of minutes used = " + numOfMinUsed);
System.out.printf("Amount Due = $%.2f %n", amtDue);
System.out.println("Account number = " + acctNum);
System.out.println("Type of service = Premium");
System.out.println("Number of minutes used = " + (callsSixAMtoSixPM + callsSixPMtoSixAM));
System.out.printf("Amount Due = $%.2f %n", amtDue);
}
}
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
You can't declare methods within other methods, so those that you have crammed into the switch statement have to be moved out.
scjavastudent 0 Newbie Poster
I took the other methods out and still have errors.
import java.util.*;
public class CellPhoneBill
{
static Scanner console = new Scanner(System.in);
static final double R_REGULAR_SERVICE = 10.00; // 1ST 50 MIN FREE
static final double R_CHARGES_OVER_FIFTY_MIN = 0.20; //PER MIN
static final double P_PREMIUM_SERVICE = 25.00;
static final double P_SIX_AM_TO_SIX_PM = 0.00; //1ST 75 MIN FREE
static final double P_OVER_SEVENTY_FIVE_MIN = 0.10; //PER MIN
static final double P_SIX_PM_TO_SIX_AM = 0.00; //1ST 100 MIN FREE
static final double P_OVER_ONE_HUNDRED_ONE_MIN = 0.05; //PER MIN
public static void main(String[] args)
{
int acctNum;
int numOfMinUsed;
double amtDue;
double subAmtDueA;
double subAmtDueB;
int callsSixAMtoSixPM;
int callsSixPMtoSixAM;
char serviceCode;
System.out.print("Enter the account number: ");
acctNum = console.nextInt();
System.out.println();
System.out.print("Enter the service code type: "
+ "R or r (Regular), "
+ "P or p (Premium): ");
serviceCode = console.next().charAt(0);
System.out.println();
switch (serviceCode)
{
case 'R':
case 'r':
System.out.print("Enter the number of minutes: ");
numOfMinUsed = console.nextInt();
System.out.println();
if (numOfMinUsed <= 50)
amtDue = R_REGULAR_SERVICE;
else
amtDue = R_REGULAR_SERVICE +
R_CHARGES_OVER_FIFTY_MIN *
(numOfMinUsed - 50);
System.out.println("Account number = " + acctNum);
System.out.println("Type of service = Regular");
System.out.println("Number of minutes used = " + numOfMinUsed);
System.out.printf("Amount Due = $%.2f %n", amtDue);
break;
case 'P':
case 'p':
System.out.print("Enter the number of minutes used from 6:00 AM - 6:00 PM: ");
callsSixAMtoSixPM = console.nextInt();
System.out.println();
if (callsSixAMtoSixPM <= 75)
subAmtDueA = P_PREMIUM_SERVICE;
else
subAmtDueA = P_PREMIUM_SERVICE +
P_OVER_SEVENTY_FIVE_MIN * (callsSixAMtoSixPM - 75);
System.out.print("Enter the number of minutes used from 6:00 PM - 6:00 AM: ");
callsSixPMtoSixAM = console.nextInt();
System.out.println();
if (callsSixPMtoSixAM <= 100)
subAmtDueB = P_PREMIUM_SERVICE;
else
subAmtDueB = P_PREMIUM_SERVICE +
P_OVER_ONE_HUNDRED_ONE_MIN * (callsSixPMtoSixAM - 100);
amtDue = (subAmtDueA + subAmtDueB) - P_PREMIUM_SERVICE;
System.out.println("Account number = " + acctNum);
System.out.println("Type of service = Premium");
System.out.println("Number of minutes used = " + (callsSixAMtoSixPM + callsSixPMtoSixAM));
System.out.printf("Amount Due = $%.2f %n", amtDue);
break;
default:
System.out.println("Invalid service code.");
}
public static double amtDue(double RegularBill)
{
return amtDue;
}
public static double amtDue(double PremiumBill)
{
return amtDue;
}
}
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Walk through and match your braces. Maintaining good, consistent indentation helps a lot to see things like this.
Also be sure to read the errors carefully because they contain line numbers where the problems occur. "Illegal start of expression" is going to indicate an improperly terminated block or expression prior to the point that the compiler complains.
scjavastudent 0 Newbie Poster
From what I can tell, I have a closed brace for every open brace.
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Well, I'm going to "guess" that your error is around line 128 (you didn't post the error message) and suggest you look more closely at main().
scjavastudent 0 Newbie Poster
The error message is still the same. Illegal start of expression.
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Of course it is, unless you fixed that missing brace from main().
You know, it's getting pretty tough to see over your shoulder and know what you're doing there. You might try reposting the code if you fix something. And walk through every brace and find it's matching closing brace.
Ying_Yang 0 Newbie Poster
I'd say in line 116 rather you ended with an extra ")" or u didnt use indentation for it, check it out.
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.