Results 1 to 9 of 9
  1. #1
    Allspark is offline Member
    Join Date
    Sep 2010
    Posts
    21
    Rep Power
    0

    Default Using the Math.ceil method

    I wrote this simple program for programming fundamentals and I was instructed to round up the results. I've been trying to use the Math.ceil method but I have not been able to corporate it into my program. Any tips?


    // Program helps student determine how many pizza and soda should
    // be purchased for student activities.

    Java Code:
    import java.util.Scanner;
    
    public class PizzaSoda
    {
    	public static void main(String[] args)
    	{ 
    		int People; 
    		double Hours;
    		double Pizza = .4; 
    		double Soda = .25;
    		double Result, Value;
    		
    		
    		Scanner keyboard = new Scanner(System.in);
    		
    		System.out.print("Enter the number of people expected to attend this activity: ");
    		People = keyboard.nextInt();
    			
    		System.out.print("Enter the duration of the activity in hours: ");
    		Hours = keyboard.nextDouble();
    			
    		System.out.println((Pizza * People) + " whole pizzas will be needed.");
    		System.out.println((Soda * People * Hours) / 2 + " 2-liter bottles of soda will be needed.");
    		
    		System.exit(0);
    	}
    	
    }
    Last edited by Eranga; 09-08-2010 at 05:09 AM. Reason: code tags added
    - Winners compare their achievements with their goals, while losers compare their achievements with those of other people. -

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Round-up sense can you explain what you exactly want to do? I cannot see that you've tried do something related to that in your code.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    And also please use code tags when you are posting again. Unformated codes are really hard to read. If you don't know how to do it, then check on my forum signature. You can find the relevant link.

  4. #4
    Allspark is offline Member
    Join Date
    Sep 2010
    Posts
    21
    Rep Power
    0

    Default

    Ok, i'll do that for next time. And nevermind about my question, I figured it out. I'm sorry for the confusion. I was attempting to use the Math.ceil method to round the output of the equations. This is what i was trying to do, here's the new code.

    Java Code:
    
    
    // Program helps student determine how many pizza and soda should 
    // be purchased for student activities.
    
    import java.util.Scanner;
    
    public class PizzaSoda
    {
    	public static void main(String[] args)
    	{ 
    		int People; 
    		double Hours;
    		double Pizza = .4; 
    		double Soda = .25;
    		
    		
    		Scanner keyboard = new Scanner(System.in);
    		
    		System.out.print("Enter the number of people expected to attend this activity: ");
    		People = keyboard.nextInt();
    		[COLOR="Red"]double Result = Math.ceil(Pizza * People);[/COLOR]	
    		
    		
    		System.out.print("Enter the duration of the activity in hours: ");
    		Hours = keyboard.nextDouble();
    		[COLOR="Red"]double Value = Math.ceil((Soda * People * Hours) / 2);[/COLOR]
    		
    			
    		System.out.println(Result + " whole pizzas will be needed.");
    		System.out.println(Value + " 2-liter bottles of soda will be needed.");
    		
    		System.exit(0);
    	}
    	
    }
    - Winners compare their achievements with their goals, while losers compare their achievements with those of other people. -

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  6. #6
    Allspark is offline Member
    Join Date
    Sep 2010
    Posts
    21
    Rep Power
    0

    Default

    Got it, thank you. Sorry I don't know these requirements. I'm new to the site, I'm learning as I go. But thank you for your help and advice.
    - Winners compare their achievements with their goals, while losers compare their achievements with those of other people. -

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    No worries. More than a requirement it's a good practice to work on in the forum. Because solved threads could be really helpful lots of there newbies specially.

  8. #8
    Allspark is offline Member
    Join Date
    Sep 2010
    Posts
    21
    Rep Power
    0

    Default

    ok, thanks. I'll remember that.
    - Winners compare their achievements with their goals, while losers compare their achievements with those of other people. -

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. Roundind up numbers using Math.ceil
    By Allspark in forum New To Java
    Replies: 1
    Last Post: 09-08-2010, 05:15 AM
  2. Math.random
    By p0rnstar in forum New To Java
    Replies: 9
    Last Post: 01-27-2010, 01:26 AM
  3. Need help with math equation
    By annabellastorm in forum New To Java
    Replies: 4
    Last Post: 01-10-2010, 05:12 PM
  4. Replies: 3
    Last Post: 12-10-2008, 01:38 AM
  5. Math Class (ceil, floor, abs)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-13-2007, 09:21 AM

Tags for this Thread

Posting Permissions

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