# Thread: Using the Math.ceil method

1. Member
Join Date
Sep 2010
Posts
21
Rep Power
0

## 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

2. 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. 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. Member
Join Date
Sep 2010
Posts
21
Rep Power
0
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);
}

}```

5. Member
Join Date
Sep 2010
Posts
21
Rep Power
0
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.

6. 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.

7. Member
Join Date
Sep 2010
Posts
21
Rep Power
0
ok, thanks. I'll remember that.