-
JAVA help on file: Internet Service Provider
What to do with this JAVA code?
This is the code that I need to do:
An Internet service provider has three different subscription packages for its customers:
Package A: For $9.95 per month 10 hours of access are provided. Additional hours are $2.00 per hour.
Package B: For $13.95 per month 20 hours of access are provided. Additional hours are $1.00 per hour.
Package C: For $19.95 per month unlimited access is provided.
Write a program that calculates a customer's monthly bill. It should ask the user to enter the letter of the package the customer has purchased (A, B, or C) and the number of hours that were used. It should then display the total charges.
I keep getting either negative prices or a price that is less than the minimum access fee (when I input e.g. A and 4 --> answer will be $-2.0500000000000007 instead of $9.95).
I want the answer to be either $9.95 or $13.95 when I enter the number of hours less than the number of hours allowed to access the internet.
What am I missing in this code?
Also, what can I do to make it into 2 decimal places instead of 16 decimal places (without using printf or decimalFormatter)?
Here is my code source:
Code :
package internetserviceprovider;
import javax.swing.JOptionPane;
/**
*
* @author Home
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
char packageLetter;
int hoursUsed;
int regularHours;
int additionalHours;
double monthlyFee;
double additionalHoursFee;
double totalFee;
String inputString;
inputString = JOptionPane.showInputDialog("Enter the letter of the " +
"package you purchased (either A, B, or C.");
inputString = inputString.toUpperCase();
packageLetter = inputString.charAt(0);
inputString = JOptionPane.showInputDialog("Enter the number of hours " +
"you used.");
hoursUsed = Integer.parseInt(inputString);
switch(packageLetter)
{
case 'A':
monthlyFee = 9.95;
regularHours = 10;
additionalHours = hoursUsed - regularHours;
additionalHoursFee = additionalHours * 2.00;
totalFee = monthlyFee + additionalHoursFee;
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
break;
case 'B':
monthlyFee = 13.95;
regularHours = 20;
additionalHours = hoursUsed - regularHours;
additionalHoursFee = additionalHours * 1.00;
totalFee = monthlyFee + additionalHoursFee;
System.out.println("The total charges is " + totalFee);
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
break;
case 'C':
totalFee = 19.95;
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
break;
default:
JOptionPane.showMessageDialog(null,"Plea… enter either A,B, " +
"or C).");
}
System.exit(0);
}
}
-
Re: JAVA help on file: Internet Service Provider
Do you have any specific java programming questions?
Quote:
I keep getting either negative prices or a price that is less than the minimum access fee.
Try debugging your code by printing out the values of all the variables used as your code computes
-
Re: JAVA help on file: Internet Service Provider
Quote:
Originally Posted by
Norm
Do you have any specific java programming questions?
Try debugging your code by printing out the values of all the variables used as your code computes
What I meant was that I am able to get the value for the computations but not the minimum value:
for example, for case 'A' I enter 4 hours and I will get $-2.050000000000007 instead of $9.95.
In addition, how do I make it into 2 decimal places without using printf and decimal formatter?
-
Re: JAVA help on file: Internet Service Provider
Quote:
how do I make it into 2 decimal places without using printf and decimal formatter
Are you talking about when you format a double value to be printed?
One way to truncate a double to 2 places is multiply it by 100, cast it to an int and then divide it by 100 to get back the original significance.
Quote:
not the minimum value:
for example, for case 'A' I enter 4 hours and I will get $-2.050000000000007 instead of $9.95.
Have you tried debugging your code by print out the values as they are computed to show you where the mistake is?
-
Re: JAVA help on file: Internet Service Provider
Quote:
Originally Posted by
Norm
Are you talking about when you format a double value to be printed?
One way to truncate a double to 2 places is multiply it by 100, cast it to an int and then divide it by 100 to get back the original significance.
Have you tried debugging your code by print out the values as they are computed to show you where the mistake is?
To the first question:
I want to change the answer that would show in the message dialog as a 2 decimal value instead of the 16 decimal value.
To the second question:
Yes, I've debugged it. It has no mistakes.
The answer is supposed to be either
package A --> $9.95 for 10 hours or less; normal computation occurs
package B --> $13.95 for 20 hours or less; normal computation occurs
package C --> $19.95 for unlimited access
-
Re: JAVA help on file: Internet Service Provider
Quote:
Yes, I've debugged it. It has no mistakes.
Does that mean that the program is working?
What do you mean by mistake? What do you call this:
Quote:
for case 'A' I enter 4 hours and I will get $-2.050000000000007 instead of $9.95.
-
Re: JAVA help on file: Internet Service Provider
Yes, the program works.
As you can see, the program is suppose to compute the fee for the current month's internet service.
For the first question from my code:
It asks me to input the letter of the package.
e.g. I would enter the letter 'A'.
For the second question from my code:
It asks me to enter the amount of hours that I've accessed the internet for.
e.g. I would enter 15.
The answer would be $19.95.
On contrary, here is what I'm stuck on my code.
For the first question:
e.g. I would enter the letter 'A'.
For the second question:
e.g. I would enter 1.
The answer would be $-8.05.
It should've been $9.95 because it is less than 10 hours of access.
-
Re: JAVA help on file: Internet Service Provider
Is the program making a mistake then?
There are 5 lines of code in the area in question. Take a piece of paper and a pencil and play computer executing each statement in your mind and writing down the results for all 5 lines. See what answer you get. Is it correct?
If not what do you need to consider to correct it? hint: you may need an if
-
Re: JAVA help on file: Internet Service Provider
Quote:
Originally Posted by
Norm
Does that mean that the program is working?
What do you mean by mistake? What do you call this:
Quote:
Originally Posted by
Norm
Is the program making a mistake then?
There are 5 lines of code in the area in question. Take a piece of paper and a pencil and play computer executing each statement in your mind and writing down the results for all 5 lines. See what answer you get. Is it correct?
If not what do you need to consider to correct it? hint: you may need an if
All the answers that is above 10 hours for 'A' and 20 hours for 'B' are correct expect the ones that are under 10 hours for 'A' and under 20 hours for 'B' are incorrect.
For 'A':
I can enter any number from 1-10, it should be equal to $9.95 without any additional charges.
Whereas, any number above 10 hours starting from 11 should be $9.95 + ($2.00 per additional hour).
For 'B'
I can enter any number from 1-20, it should be equal to $13.95 without any additional charges.
Whereas, any number above 20 hours starting from 21 should be $13.95 + ($1.00 per additional hour).
I was thinking of putting an "if statement" but not sure where to insert it.
I just started using JAVA so I'm not sure if I can insert an "if statement" inside a "switch statement".
-
Re: JAVA help on file: Internet Service Provider
I was thinking about it, and there is an unnecessary step in your java code:
Code java:
int regularHours;
..
regularHours = 10;
..
regularHours = 20;
Try it without that added variable
Code java:
package internetserviceprovider;
import javax.swing.JOptionPane;
/**
*
* @author Home
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
char packageLetter;
int hoursUsed;
int additionalHours;
double monthlyFee;
double additionalHoursFee;
double totalFee;
String inputString;
inputString = JOptionPane.showInputDialog("Enter the letter of the " +
"package you purchased (either A, B, or C.");
inputString = inputString.toUpperCase();
packageLetter = inputString.charAt(0);
inputString = JOptionPane.showInputDialog("Enter the number of hours " +
"you used.");
hoursUsed = Integer.parseInt(inputString);
switch(packageLetter)
{
case 'A':
monthlyFee = 9.95;
additionalHours = hoursUsed - 10;
additionalHoursFee = additionalHours * 2.00;
totalFee = monthlyFee + additionalHoursFee;
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
break;
case 'B':
monthlyFee = 13.95;
additionalHours = hoursUsed - 20;
additionalHoursFee = additionalHours * 1.00;
totalFee = monthlyFee + additionalHoursFee;
System.out.println("The total charges is " + totalFee);
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
break;
case 'C':
totalFee = 19.95;
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
break;
default:
JOptionPane.showMessageDialog(null,"Plea… enter either A,B, " +
"or C).");
}
System.exit(0);
}
}
Also
Code java:
JOptionPane.showMessageDialog(null,"Plea… enter either A,B, " +
"or C).");
has a ) at the end inside the "", but without one in the beginning, looks a little weird
-
Re: JAVA help on file: Internet Service Provider
Quote:
Originally Posted by
Tjstretch
I was thinking about it, and there is an unnecessary step in your java code:
Code java:
int regularHours;
..
regularHours = 10;
..
regularHours = 20;
Try it without that added variable
Code java:
package internetserviceprovider;
import javax.swing.JOptionPane;
/**
*
* @author Home
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
char packageLetter;
int hoursUsed;
int additionalHours;
double monthlyFee;
double additionalHoursFee;
double totalFee;
String inputString;
inputString = JOptionPane.showInputDialog("Enter the letter of the " +
"package you purchased (either A, B, or C.");
inputString = inputString.toUpperCase();
packageLetter = inputString.charAt(0);
inputString = JOptionPane.showInputDialog("Enter the number of hours " +
"you used.");
hoursUsed = Integer.parseInt(inputString);
switch(packageLetter)
{
case 'A':
monthlyFee = 9.95;
additionalHours = hoursUsed - 10;
additionalHoursFee = additionalHours * 2.00;
totalFee = monthlyFee + additionalHoursFee;
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
break;
case 'B':
monthlyFee = 13.95;
additionalHours = hoursUsed - 20;
additionalHoursFee = additionalHours * 1.00;
totalFee = monthlyFee + additionalHoursFee;
System.out.println("The total charges is " + totalFee);
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
break;
case 'C':
totalFee = 19.95;
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
break;
default:
JOptionPane.showMessageDialog(null,"Plea… enter either A,B, " +
"or C).");
}
System.exit(0);
}
}
Also
Code java:
JOptionPane.showMessageDialog(null,"Plea… enter either A,B, " +
"or C).");
has a ) at the end inside the "", but without one in the beginning, looks a little weird
I've done the things that you've asked me to change.
The problem is pretty similar to my question.
How do I make the minimum monthly fee appear instead of it being less?
e.g. package 'A': 10 hours or less of access should be equal to $9.95, no lower than that.
e.g. package 'B': 20 hours or less of access should be equal to $13.95, no lower than that.
Computation should occur any amount of hours higher than that and charged with an additional fee.
-
Re: JAVA help on file: Internet Service Provider
So it did not fix the problem? If not than look at this:
It is always doing the statement
Code java:
additionalHoursFee = additionalHours * 2.00;
additionalHours is negative if it is below 10 (in case A) because of
Code java:
additionalHours = hoursUsed - 10;
so consider
Code java:
if(additionalHours>0){
additionalHoursFee = additionalHours * 2.00;
}
So in case A it would look like
Code java:
case 'A':
monthlyFee = 9.95;
additionalHours = hoursUsed - 10;
if(additionalHours>0)
{
additionalHoursFee = additionalHours * 2.00;
}
totalFee = monthlyFee + additionalHoursFee;
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
break;
Do that for every case, that will almost definitely fix the problem.
Oh it will give you an error, to solve that in your initial int statements make the additionalHoursFee look like
Code java:
int additionalHoursFee = 0;
-
Re: JAVA help on file: Internet Service Provider
Quote:
Originally Posted by
Tjstretch
I was thinking about it, and there is an unnecessary step in your java code:
Code java:
int regularHours;
..
regularHours = 10;
..
regularHours = 20;
Try it without that added variable
Code java:
package internetserviceprovider;
import javax.swing.JOptionPane;
/**
*
* @author Home
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
char packageLetter;
int hoursUsed;
int additionalHours;
double monthlyFee;
double additionalHoursFee;
double totalFee;
String inputString;
inputString = JOptionPane.showInputDialog("Enter the letter of the " +
"package you purchased (either A, B, or C.");
inputString = inputString.toUpperCase();
packageLetter = inputString.charAt(0);
inputString = JOptionPane.showInputDialog("Enter the number of hours " +
"you used.");
hoursUsed = Integer.parseInt(inputString);
switch(packageLetter)
{
case 'A':
monthlyFee = 9.95;
additionalHours = hoursUsed - 10;
additionalHoursFee = additionalHours * 2.00;
totalFee = monthlyFee + additionalHoursFee;
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
break;
case 'B':
monthlyFee = 13.95;
additionalHours = hoursUsed - 20;
additionalHoursFee = additionalHours * 1.00;
totalFee = monthlyFee + additionalHoursFee;
System.out.println("The total charges is " + totalFee);
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
break;
case 'C':
totalFee = 19.95;
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
break;
default:
JOptionPane.showMessageDialog(null,"Plea… enter either A,B, " +
"or C).");
}
System.exit(0);
}
}
Also
Code java:
JOptionPane.showMessageDialog(null,"Plea… enter either A,B, " +
"or C).");
has a ) at the end inside the "", but without one in the beginning, looks a little weird
Quote:
Originally Posted by
Tjstretch
So it did not fix the problem? If not than look at this:
It is always doing the statement
Code java:
additionalHoursFee = additionalHours * 2.00;
additionalHours is negative if it is below 10 (in case A) because of
Code java:
additionalHours = hoursUsed - 10;
so consider
Code java:
if(additionalHours>0){
additionalHoursFee = additionalHours * 2.00;
}
So in case A it would look like
Code java:
case 'A':
monthlyFee = 9.95;
additionalHours = hoursUsed - 10;
if(additionalHours>0)
{
additionalHoursFee = additionalHours * 2.00;
}
totalFee = monthlyFee + additionalHoursFee;
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
break;
Do that for every case, that will almost definitely fix the problem.
Oh it will give you an error, to solve that in your initial int statements make the additionalHoursFee look like
Code java:
int additionalHoursFee = 0;
The brackets for the "if statement" makes the variable "additionalHoursFee" not initialized for the statement "totalFee = monthlyFee + additionalHoursFee;"
Even when I tried it with another way, it still goes negative for some values that I input.
-
Re: JAVA help on file: Internet Service Provider
You didn't read the end did you:
Do what I said in my last post and add at the very top instead of
Code java:
double additionalHoursFee;
do
Code java:
double additionalHoursFee = 0;
That initializes the statement.
Well I accidentally put int in my last post, fail.
-
Re: JAVA help on file: Internet Service Provider
It works but now I want to change a bit instead of using the switch statement:
I'm not too familiar with using if-else if-else statements.
Here's the code source:
Code :
package javaapplication11;
import javax.swing.JOptionPane;
/**
*
* @author Home
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
char packageLetter;
int hoursUsed;
int additionalHours = 0;
double monthlyFee = 0;
double additionalHoursFee;
double totalFee;
String inputString;
inputString = JOptionPane.showInputDialog("Enter the letter of the " +
"package you purchased (either A, B, or C.)");
inputString = inputString.toUpperCase();
packageLetter = inputString.charAt(0);
inputString = JOptionPane.showInputDialog("Enter the number of hours " +
"you used.");
hoursUsed = Integer.parseInt(inputString);
{
if(packageLetter=='A')
monthlyFee = 9.95;
additionalHours = hoursUsed - 10;
{
if(additionalHours > 0 && hoursUsed > 10)
{
additionalHoursFee = additionalHours * 2.00;
totalFee = monthlyFee + additionalHoursFee;
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
}
else
{
JOptionPane.showMessageDialog(null,"The total charges is $"
+ monthlyFee + ".");
}
if (packageLetter == 'B')
monthlyFee = 13.95;
additionalHours = hoursUsed - 20;
if (additionalHours>0 && hoursUsed>20)
{
additionalHoursFee = additionalHours * 1.00;
totalFee = monthlyFee + additionalHoursFee;
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
}
else
{
JOptionPane.showMessageDialog(null,"The total charges is $"
+ monthlyFee + ".");
}
if(packageLetter == 'C')
{
totalFee = 19.95;
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
}
if(packageLetter !='A'||packageLetter !='B'||packageLetter !='C')
{
JOptionPane.showMessageDialog(null,"Please enter either A,B, " +
"or C).");
}
}
System.exit(0);
}
}
Many message dialogs pop up for the answer. How am I missing to make it just one message dialog to pop up?
-
Re: JAVA help on file: Internet Service Provider
Quote:
Many message dialogs pop up for the answer.
Can you explain which messages pop up?
You need to follow the logic of your program and see why each message is shown. What controls why each message is shown?
Your usage of { & } after an if needs to be checked. There are many that are in the wrong places.
Without the {} only the immediately following statement is controlled by the if.
-
Re: JAVA help on file: Internet Service Provider
Quote:
Originally Posted by
Norm
Can you explain which messages pop up?
You need to follow the logic of your program and see why each message is shown. What controls why each message is shown?
Your usage of { & } after an if needs to be checked. There are many that are in the wrong places.
Without the {} only the immediately following statement is controlled by the if.
After execution, the message dialog appears for:
package A
package B
the default
So...therefore, I have to use else if? When I did that the error on side says that it should be "else without if".
How do I make that separate each just like the "switch statement"?
-
Re: JAVA help on file: Internet Service Provider
Did you check and correct the problems with the { & }s?
-
Re: JAVA help on file: Internet Service Provider
Quote:
Originally Posted by
Norm
Can you explain which messages pop up?
You need to follow the logic of your program and see why each message is shown. What controls why each message is shown?
Your usage of { & } after an if needs to be checked. There are many that are in the wrong places.
Without the {} only the immediately following statement is controlled by the if.
Quote:
Originally Posted by
Norm
Did you check and correct the problems with the { & }s?
I've changed it but on the sides, it says identifier expected and I'm not too sure where to put the brackets for the "if-else if-else".
Code :
package javaapplication11;
import javax.swing.JOptionPane;
/**
*
* @author Home
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
char packageLetter;
int hoursUsed;
int additionalHours = 0;
double monthlyFee = 0;
double additionalHoursFee;
double totalFee;
String inputString;
inputString = JOptionPane.showInputDialog("Enter the letter of the " +
"package you purchased (either A, B, or C.)");
inputString = inputString.toUpperCase();
packageLetter = inputString.charAt(0);
inputString = JOptionPane.showInputDialog("Enter the number of hours " +
"you used.");
hoursUsed = Integer.parseInt(inputString);
{
if(packageLetter=='A'&& additionalHours > 0 && hoursUsed > 10)
monthlyFee = 9.95;
additionalHours = hoursUsed - 10;
additionalHoursFee = additionalHours * 2.00;
totalFee = monthlyFee + additionalHoursFee;
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
else if(packageLetter=='B' && additionalHours>0 && hoursUsed>20)
monthlyFee = 13.95;
additionalHours = hoursUsed - 20;
additionalHoursFee = additionalHours * 1.00;
totalFee = monthlyFee + additionalHoursFee;
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
else if(packageLetter=='C')
totalFee = 19.95;
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".")
else
JOptionPane.showMessageDialog(null,"Please enter either A,B, " +
"or C).");
}
System.exit(0);
}
}
-
Re: JAVA help on file: Internet Service Provider
ALWAYS put a { after the ending ) on a if statement:
if (some conditions here) {
then put the end } after the last statement(s) do be done when the if condition is true. Put it on its own line.
Your posted code doesn't have any { that I can see.
You need to add them as I stated above.
-
Re: JAVA help on file: Internet Service Provider
Quote:
Originally Posted by
Norm
ALWAYS put a { after the ending ) on a if statement:
if (some conditions here) {
then put the end } after the last statement(s) do be done when the if condition is true. Put it on its own line.
Your posted code doesn't have any { that I can see.
You need to add them as I stated above.
I've fixed those.
Now, whatever I enter...it becomes "Please enter either A, B, or C."
Code :
package javaapplication11;
import javax.swing.JOptionPane;
/**
*
* @author Home
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
char packageLetter;
int hoursUsed;
int additionalHours = 0;
double monthlyFee = 0;
double additionalHoursFee;
double totalFee;
String inputString;
inputString = JOptionPane.showInputDialog("Enter the letter of the " +
"package you purchased (either A, B, or C.)");
inputString = inputString.toUpperCase();
packageLetter = inputString.charAt(0);
inputString = JOptionPane.showInputDialog("Enter the number of hours " +
"you used.");
hoursUsed = Integer.parseInt(inputString);
{
if(packageLetter=='A'&& additionalHours > 0 && hoursUsed > 10)
{
monthlyFee = 9.95;
additionalHours = hoursUsed - 10;
additionalHoursFee = additionalHours * 2.00;
totalFee = monthlyFee + additionalHoursFee;
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
}
else if(packageLetter=='B' && additionalHours>0 && hoursUsed>20)
{
monthlyFee = 13.95;
additionalHours = hoursUsed - 20;
additionalHoursFee = additionalHours * 1.00;
totalFee = monthlyFee + additionalHoursFee;
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
}
else if(packageLetter=='C')
{
totalFee = 19.95;
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
}
else
JOptionPane.showMessageDialog(null,"Please enter either A,B, " +
"or C).");
}
System.exit(0);
}
}
-
Re: JAVA help on file: Internet Service Provider
Quote:
whatever I enter...it becomes "Please enter either A, B, or C."
Enter what?
What is the "it" that becomes?
I don't understand what you are trying to explain. Can you say what you do and what the computer does, step by step?
Code :
if(packageLetter !='A'||packageLetter !='B'||packageLetter !='C')
What if packageLetter is 'C'?
Is that not equal to 'A'
so packageLetter !='A' would be true and the if true statement would execute
You want all three conditions to be true not just one of them. Use AND vs OR logic here
-
Re: JAVA help on file: Internet Service Provider
Quote:
Originally Posted by
Norm
Enter what?
What is the "it" that becomes?
I don't understand what you are trying to explain. Can you say what you do and what the computer does, step by step?
Code :
if(packageLetter !='A'||packageLetter !='B'||packageLetter !='C')
What if packageLetter is 'C'?
Is that not equal to 'A'
so packageLetter !='A' would be true and the if true statement would execute
You want all three conditions to be true not just one of them. Use AND vs OR logic here
Code :
if(packageLetter!='A' && packageLetter!='B' && packageLetter!='C')
{
JOptionPane.showMessageDialog(null, "Please enter either A,B, "
+ "or C).");
}
After changing that part of the code, nothing pops up when I enter 'A' or 'B' along with the hours.
Only 'C' along with hours, a message dialog pops up saying "The total charges is $19.95."
This part of the code is supposed to have the result compared to the "switch statement's" default function.
For the previous question:
I entered 'A' and any number of hours --> "Please enter either A, B, or C."
I entered 'B' and any number of hours --> "Please enter either A, B, or C."
I entered 'C' and any number of hours --> "The total charges is $19.95."
A new error has also occured at the end of the entire code saying "reached end of file while parsing."
-
Re: JAVA help on file: Internet Service Provider
"reached end of file while parsing."
Check for matching pairs of {}s
Make sure they are all paired.
-
Re: JAVA help on file: Internet Service Provider
Quote:
Originally Posted by
Norm
"reached end of file while parsing."
Check for matching pairs of {}s
Make sure they are all paired.
The brackets seem to pair up nicely...
The last bracket, isn't it supposed to pair up with the one after "public static void"?
Code :
package javaapplication11;
import javax.swing.JOptionPane;
/**
*
* @author Home
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
char packageLetter;
int hoursUsed;
int additionalHours = 0;
double monthlyFee = 0;
double additionalHoursFee;
double totalFee;
String inputString;
inputString = JOptionPane.showInputDialog("Enter the letter of the " +
"package you purchased (either A, B, or C.)");
inputString = inputString.toUpperCase();
packageLetter = inputString.charAt(0);
inputString = JOptionPane.showInputDialog("Enter the number of hours " +
"you used.");
hoursUsed = Integer.parseInt(inputString);
{
if(packageLetter=='A'&& additionalHours > 0 && hoursUsed > 10)
{
monthlyFee = 9.95;
additionalHours = hoursUsed - 10;
additionalHoursFee = additionalHours * 2.00;
totalFee = monthlyFee + additionalHoursFee;
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
}
else if(packageLetter=='B' && additionalHours>0 && hoursUsed>20)
{
monthlyFee = 13.95;
additionalHours = hoursUsed - 20;
additionalHoursFee = additionalHours * 1.00;
totalFee = monthlyFee + additionalHoursFee;
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
}
else if(packageLetter=='C')
{
totalFee = 19.95;
JOptionPane.showMessageDialog(null,"The total charges is $" +
totalFee + ".");
}
if(packageLetter!='A' && packageLetter!='B' && packageLetter!='C')
{
JOptionPane.showMessageDialog(null, "Please enter either A,B, "
+ "or C).");
}
System.exit(0);
}
}