1. Member Join Date
Nov 2012
Posts
2
Rep Power
0

## Adding 2

In the code I am trying to add "2" if you enter a higher number than 10 (in package A). I want to add "2" to the value of "one" for example
if you enter:
11 you get 11.95 (since one = 9.95 + 2)
12 you get 13.95 (since two = 11.95+2)
etc
Im trying to do this WITHOUT using a loop i know how to do it with a loop but i am trying to find a way to do an algorithm instead.
Any help would be great thanks.
Java Code:
```package months;

import java.io.IOException;
import java.util.Scanner;

public class Months
{

public static void main(String[] args) throws IOException
{
Scanner user_input = new Scanner( System.in );

String Name,LetterAsString;
char packages;
int hours;
double one = 9.95;
double two = 14.95;
double three = 19.95;

//input
System.out.print("Customer Name:");
Name = user_input.next();
System.out.print("Which package was purchased:");

if(packages == 'A' || packages == 'B' || packages == 'C' || packages == 'a' || packages == 'b' || packages == 'c')
{
System.out.print("How Many hours were used:");
hours = user_input.nextInt();

if (packages == 'A' || packages == 'a')
{
if (hours <= 10)
{
System.out.println("Customer Name: " + Name);
System.out.println("Package: " + packages);
System.out.println("The total amount due is: \$" + one);
}

else if (hours > 10)
{
double num = 0;
hours= (int) (one +2);

System.out.println("The total amount due is: \$" + hours);
}
}

if (packages == 'B' || packages == 'b')
{
if (hours <= 20)
{
System.out.println("Customer Name: " + Name);
System.out.println("Package: " + packages);
System.out.println("The total amount due is: \$" + two);
}

else if (hours > 20)
{
System.out.println("The total amount due is: \$" + two);
}

}
if (packages == 'C' || packages == 'c')
{
System.out.println("Customer Name: " + Name);
System.out.println("Package: " + packages);
System.out.println("The total amount due is: \$" + three);
}

}

else  if(packages != 'A' || packages != 'B' || packages != 'C' || packages != 'a' || packages != 'b' || packages != 'c')
{
System.out.println("Invalid Entry");
}

}
}```  Reply With Quote

2. ## Re: Adding 2

So... what's the problem? Does it give an error? Does it not do what you want it to do? If so, what did it do, and what did you expect it to do?  Reply With Quote

3. ## Re: Adding 2

If I understand correctly then perhaps you need: (n-10) * 2 + 9.95  Reply With Quote

4. Member Join Date
Nov 2012
Posts
2
Rep Power
0

## Re: Adding 2

^That's exactly it! thank you! Been trying to figure it out for a couple days.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•