Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: How do you code to compare result?

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How do you code to compare result?

     
    import java.util.Scanner; //import scanner statement
     
    public class InternetServiceProvider
    {
    	public static void main(String [] args)
    	{
    		Scanner keyboard = new Scanner (System.in); //scanner object
     
    		String service; //service package choice 
    		double hours; //hours used
    		double total; //total amount due
     
     
    		System.out.println("Package A: For $9.95 per month 10 hours of access are provided." +
    			" Additional hours\nare $2.00 per hour.\n"); //print service package A rate and price
    		System.out.println("Package B: For $13.95 per month 20 hours of access are provided." +
    			" Additional hours are\n$1.00 per hour.\n"); //print service package B rate and price
    		System.out.println("Package C: For $19.95 per month unlimited access is provided.\n"); //print service package C rate and price
    		System.out.print("Please enter a package you want(A, B, C): "); //prompt service package choice
    		service = keyboard.nextLine(); //accept service package input
    		System.out.print("Please enter hours used: "); //prompt hours used
    		hours = keyboard.nextDouble(); //accept hours used input
     
     
     
    		if (service.equals("A")) //if statement for service A package
    		{
    			if(hours <= 10)
    			{
    				total = 9.95; //total
                System.out.println("You are using " + service + " and you used " + hours +
    				" hours this month. Your total charge will be $" + total + "."); //print the result for 10 hours or less used
    			}
    			else
    			{
    				total = 9.95 + ((hours-10)*2); //calculate total
                System.out.println("You are using " + service + " and you used " + hours +
    				" hours this month. Your total charge will be $" + total + "."); //pritn the result for 10+ hours used
    			}
    		}
     
     
    		else if(service.equals("B")) //if statement for service B package
          {
             if(hours <= 20)
             {
                total = 13.95; //total
                System.out.println("You are using " + service + " and you used " + hours +
    				" hours this month. Your total charge will be $" + total + "."); //print the result for 20 hours or less used
             }
             else
             {
                total = 13.95 + ((hours-20)*1); //calculate total
                System.out.println("You are using " + service + " and you used " + hours +
    				" hours this month. Your total charge will be $" + total + "."); //print the result for 20+ hours used
             }
           }
     
     
          else if(service.equals("C")) //if statement for service C package
          {
             total = 19.95; //total
             System.out.println("You are using " + service + " and you used " + hours +
    				" hours this month. Your total charge will be $" + total + "."); //print the result
          }
     
    	}
    }

    ok. This is my initial code that suppose to prompt user to choose one of 3 internet service plans which are plan A, B, C and then how many hours user used it. It then prints out the total cost.
    Now, I am having problem. How do you alter this code to compare result from A to B and A to C. for example, user would get $29.95 if he choose plan A and use for 20 hours. But if he choose plan B and use for 20 hours, he would get $13.95. So how do I make this to compare those two prices and print out the difference? I was thinking about compareTo method but I only know how to do it with basic strings like comparing names. Can anyone help me out on this?


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: How do you code to compare result?


  3. #3
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: How do you code to compare result?

    Abuse reported. Stop spamming!

  4. #4
    Junior Member
    Join Date
    Jun 2013
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How do you code to compare result?

    Quote Originally Posted by PhHein View Post
    Abuse reported. Stop spamming!
    how the heck is this spamming? you must be high or something. if you have nothing to say to help me, please just don't post. I had similar post but I was asking different question there and there was no option to remove or close previous post that i had answer to. I would report you for harrassing and trolling.

  5. #5
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: How do you code to compare result?

    That was a reply to the spammer, not to you.

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: How do you code to compare result?

    Chill out. I believe PhHein was responding to 9codeweb.

    However, you should notify us when you've posted the same problem in multiple places (crossposting) so that we don't waste our time repeating the same or providing contradictory advice to that being given somewhere else.

  7. #7
    Junior Member
    Join Date
    Jun 2013
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How do you code to compare result?

    oh i c. my bad. was just having day and it was kinda unclear who he was referring to. i am sorry. scratch what i said.

Similar Threads

  1. Replies: 15
    Last Post: December 1st, 2012, 10:13 PM
  2. image compare
    By ana0429 in forum Member Introductions
    Replies: 1
    Last Post: March 21st, 2012, 03:03 AM
  3. Don't know java ...Need help compare, explain 2 different versiosn of code.
    By asian2003k in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 9th, 2011, 12:41 PM
  4. Beginner trying to write Java code, has issue w/ printing result and 2 decimals
    By flpanthers1 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 5th, 2011, 11:11 AM
  5. Compare method
    By Evelina in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 16th, 2010, 02:07 PM