Results 1 to 9 of 9
Thread: Using the Math.ceil method
 09082010, 04:30 AM #1Member
 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 + " 2liter bottles of soda will be needed."); System.exit(0); } }
Last edited by Eranga; 09082010 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. 
 09082010, 05:10 AM #2
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,370
 Blog Entries
 1
 Rep Power
 22
Roundup 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.
 09082010, 05:12 AM #3
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,370
 Blog Entries
 1
 Rep Power
 22
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.
 09092010, 12:34 AM #4Member
 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 + " 2liter 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. 
 09092010, 04:39 AM #5
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,370
 Blog Entries
 1
 Rep Power
 22
So if you've solved the problem please mark the thread solved from tools menu.
 09092010, 04:02 PM #6Member
 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.
 Winners compare their achievements with their goals, while losers compare their achievements with those of other people. 
 09092010, 08:01 PM #7
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,370
 Blog Entries
 1
 Rep Power
 22
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.
 09092010, 10:40 PM #8Member
 Join Date
 Sep 2010
 Posts
 21
 Rep Power
 0
ok, thanks. I'll remember that.
 Winners compare their achievements with their goals, while losers compare their achievements with those of other people. 
 09102010, 05:52 AM #9
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,370
 Blog Entries
 1
 Rep Power
 22
Similar Threads

Roundind up numbers using Math.ceil
By Allspark in forum New To JavaReplies: 1Last Post: 09082010, 05:15 AM 
Math.random
By p0rnstar in forum New To JavaReplies: 9Last Post: 01272010, 02:26 AM 
Need help with math equation
By annabellastorm in forum New To JavaReplies: 4Last Post: 01102010, 06:12 PM 
beginner grade 11need help with a math code involving returning values from a method
By bobmasta5 in forum New To JavaReplies: 3Last Post: 12102008, 02:38 AM 
Math Class (ceil, floor, abs)
By Java Tip in forum Java TipReplies: 0Last Post: 12132007, 10:21 AM
Bookmarks