• 11-01-2012, 01:45 AM
helpr
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.
Code:

```package months; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; 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:");         packages = (char)System.in.read();                             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");         }             } }```
• 11-01-2012, 01:48 AM
Toll