Results 1 to 4 of 4

Thread: Adding 2

  1. #1
    helpr is offline Member
    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Default 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.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");
            }
            
        }
    }

  2. #2
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    392
    Rep Power
    4

    Default 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?

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,779
    Rep Power
    7

    Default Re: Adding 2

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

  4. #4
    helpr is offline Member
    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Default Re: Adding 2

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

Similar Threads

  1. adding two objects
    By apiwowar in forum New To Java
    Replies: 4
    Last Post: 09-15-2011, 03:38 AM
  2. Replies: 1
    Last Post: 04-05-2011, 08:58 PM
  3. Adding to a HashSet
    By Neivaed in forum New To Java
    Replies: 6
    Last Post: 12-05-2010, 06:16 PM
  4. Adding folders to a Jar
    By IamKira in forum NetBeans
    Replies: 5
    Last Post: 01-22-2010, 06:03 PM
  5. Adding
    By natep67 in forum New To Java
    Replies: 2
    Last Post: 04-22-2009, 07:51 AM

Posting Permissions

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