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:

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" );

}

Re: Help with simple algorithm problem!!!!!????

Code:

`if(studentsRemaining > 0) {`

extraBus++;

}

?

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.

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

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.

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.

Re: Help with simple algorithm problem

Quote:

Originally Posted by

**Vampiricx3** Why not ask a class mate of yours to help? We aren't here to do your homework mate.

this isn't my whole home work assignment only a small portion and i'm only looking for help because i've spent 3 days trying to figure it out and its getting frustrating. i don't see aany of my class mates till tomorrow, after the assignments due.

Re: Help with simple algorithm problem

Quote:

Originally Posted by

**pbrockway2** 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.

i don't think i get what you trying to say. Could you give me an example?

and my teacher wont allow us to use if statements on this problem i wish i could i would have finished this assignment along time ago.

Re: Help with simple algorithm problem

Quote:

i don't think i get what you trying to say. Could you give me an example?

I don't know if I can make the algorithm (effective procedure) any clearer, but here's 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:

Code:

`XXXXXXXXXX`

XXXXXXXXXX

XXXXXXXXXX

XXXXXXXXXX

XXXXXXXXXX

XXXXXXXXXX

XXXXXXXXXX

XXXXXXXXXX

XXXXXXXXXX

I. More precisely have almost a bus full of them [teddybears] (39) on hand

Here are my teddybears:

Code:

`..........`

..........

..........

.........

II 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).

By busload they look like this:

Code:

`Bus 1: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX`

Bus 2: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Bus 3: XXXXXXXXXX..............................

The remainder: .........

III The remainder can now be safely ignored because it consists of a bus with some number of teddybears (but no students) in it.

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.

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.

Re: Help with simple algorithm problem

You're welcome. I'm glad you've got it figured out.