Results 1 to 12 of 12
 02052012, 03:08 AM #1Member
 Join Date
 Feb 2012
 Posts
 8
 Rep Power
 0
Help with simple algorithm problem
here is the problem my teacher assigned :
For an upcoming field trip, buses are needed to take the students on a trip. Buses hold 40 students. Your
boss has given you the task of writing the code that will compute and display the number of buses needed for a field trip
with 473 students. The output should be formatted as follows, with the blank replaced with the computed answer.
Your program should do all the computations necessary.
473 students will require ___ buses
.
If you do your computation in an organized way, it should be easy to copy and paste your code, replace all the instances
of 473 with some other number of students, and have your code still work correctly. So, once you’ve written the code
for 473 students, copy and paste that code five more times, and thoroughly test your program with 5 other numbers of
students. For each test, do not change the formula you use, except that you should replace the number 473 with the
number of students you are testing. You should assume that the number of students will always be an integer that is at
least 1 and at most 1000. Don’t bother checking test cases outside this range. Test thoroughly, even if you believe with
all your heart that you’ve done the correct computation.
**** CANT USE IF STATEMENTS ******
i have the basic algorithm to calculate the number of buses. i need a code that says if the remainder > 0 then extraBus = 1
but i dont understand how to do this with out and if statement....
this is my code so far:
Java Code:public class Assign3Practice { public static void main( String [] args ) { { int busCompacity = 40; int numStudents = 473; int fullBuses = numStudents / busCompacity; int remainder = numStudents % busCompacity; // i need a code here to do what i asked int totalBuses = remainder + fullBuses; System.out.println ( + numStudents + " Students will require " + totalBuses + " buses" ); }
Last edited by Fubarable; 02052012 at 09:05 PM. Reason: moderation
 02052012, 04:28 AM #2Member
 Join Date
 Feb 2012
 Posts
 31
 Rep Power
 0
Re: Help with simple algorithm problem!!!!!????
Java Code:if(studentsRemaining > 0) { extraBus++; }
If I have helped you, + rep
 02052012, 08:38 PM #3Member
 Join Date
 Feb 2012
 Posts
 8
 Rep Power
 0
Re: Help with simple algorithm problem!!!!!????
i cant use any if statements i need an algorithm that does the same thing as:
if (studentsRemaining > 0);{
extraBuses++;
}
with out using if else or while

Re: Help with simple algorithm problem
Moderator edit: code tags added to initial post. Distracting punctuation removed from thread title.
 02062012, 12:11 AM #5Member
 Join Date
 Feb 2012
 Posts
 8
 Rep Power
 0
Re: Help with simple algorithm problem
Please some one try and figure out an algorithm for me this program is due in a couple of hours.
i cant use if statements
the algorithm has t work with any instance of student 1 to 1000
 02062012, 12:53 AM #6Member
 Join Date
 Feb 2012
 Posts
 31
 Rep Power
 0
Re: Help with simple algorithm problem
Why not ask a class mate of yours to help? We aren't here to do your homework mate.
If I have helped you, + rep
 02062012, 01:05 AM #7Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,565
 Rep Power
 12
Re: Help with simple algorithm problem
Notice that the remainder doesn't play any part in the actual question.
By focussing on remainder you have led yourself into a problem: you want to calculate whether there is a remainder, but are unwilling to use the obvious and sane method of using an if statement.
Forget the remainder, I say. Use teddybears instead! More precisely have almost a bus full of them (39) on hand, and put them onto the buses as well as the students. Put the teddybears onto the buses after the students because the teddybears are not actually going anywhere (that would be silly). The remainder can now be safely ignored because it consists of a bus with some number of teddybears (but no students) in it.
 02062012, 02:45 AM #8Member
 Join Date
 Feb 2012
 Posts
 8
 Rep Power
 0
Re: Help with simple algorithm problem
 02062012, 02:47 AM #9Member
 Join Date
 Feb 2012
 Posts
 8
 Rep Power
 0
Re: Help with simple algorithm problem
Last edited by Eaballard513; 02062012 at 02:49 AM.
 02062012, 03:41 AM #10Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,565
 Rep Power
 12
Re: Help with simple algorithm problem
i don't think i get what you trying to say. Could you give me an example?
(The example is much easier to see if you arm yourself with small tokens or pieces of paper  I'm assuming you don't have 39 teddybears or 1000 obliging students to experiment with  and shuffle them about on your desk)
0. Let's suppose we have 90 students wanting to travel on the buses. It is required to construct enough buses for them to travel, 40 per bus.
Here are the students:
Java Code:XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX
Here are my teddybears:
Java Code:.......... .......... .......... .........
By busload they look like this:
Java Code:Bus 1: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Bus 2: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Bus 3: XXXXXXXXXX.............................. The remainder: .........
We have constructed the buses required: 3 of them. (QEF, but remember to remove the teddybears before departure so they can be used for the next calculation.)
[edit] corrected the number of bears in the remainder bus. Teh codez, btw, come from step II: a single line of code which replaces 2/3 of your main method.Last edited by pbrockway2; 02062012 at 04:03 AM.
 02062012, 04:01 AM #11Member
 Join Date
 Feb 2012
 Posts
 8
 Rep Power
 0
Re: Help with simple algorithm problem
Thank you soo much i got it now... you have no idea how long this has been bothering me.
 02062012, 04:11 AM #12Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,565
 Rep Power
 12
Similar Threads

An algorithm problem
By bMorgan in forum New To JavaReplies: 1Last Post: 01272011, 09:53 AM 
Algorithm Problem
By Aggy in forum New To JavaReplies: 4Last Post: 01212010, 11:00 PM 
Problem with equation in my algorithm
By romina in forum New To JavaReplies: 2Last Post: 07202007, 07:53 AM 
Problem with algorithm
By Albert in forum AWT / SwingReplies: 1Last Post: 07132007, 03:31 PM 
Algorithm problem
By Marcus in forum Advanced JavaReplies: 2Last Post: 07012007, 01:37 AM
Bookmarks