# Using the Math.ceil method

• 09-08-2010, 04:30 AM
Allspark
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.

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);         }         }```
• 09-08-2010, 05:10 AM
Eranga
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.
• 09-08-2010, 05:12 AM
Eranga
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.
• 09-09-2010, 12:34 AM
Allspark
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.

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);         }         }```
• 09-09-2010, 04:39 AM
Eranga