Results 1 to 12 of 12
 02052012, 04: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 10:05 PM. Reason: moderation
 02052012, 05: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, 09: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, 01: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, 01: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, 02:05 AM #7Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,708
 Rep Power
 13
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, 03:45 AM #8Member
 Join Date
 Feb 2012
 Posts
 8
 Rep Power
 0
Re: Help with simple algorithm problem
 02062012, 03:47 AM #9Member
 Join Date
 Feb 2012
 Posts
 8
 Rep Power
 0
Re: Help with simple algorithm problem
Last edited by Eaballard513; 02062012 at 03:49 AM.
 02062012, 04:41 AM #10Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,708
 Rep Power
 13
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 05:03 AM.
 02062012, 05: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, 05:11 AM #12Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,708
 Rep Power
 13
Similar Threads

An algorithm problem
By bMorgan in forum New To JavaReplies: 1Last Post: 01272011, 10:53 AM 
Algorithm Problem
By Aggy in forum New To JavaReplies: 4Last Post: 01222010, 12:00 AM 
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