#problem

13 messages · Page 1 of 1 (latest)

orchid night
#

in a bus 52 places in a minibus 23 places and in a taxi 10 places.
input an amount of students and calculate how many vehicles are needed from each type

novel wrenBOT
#

Hey, @orchid night!
Please remember to /close this post once your question has been answered!

orchid night
#

these is my code how can i make it better

#

am i in the right path?

#

public class HW6 {
    public static void main(String[] args) {
        System.out.println("how many students are ?");
        Scanner scanner = new Scanner(System.in);
        int students = scanner.nextInt();
        final int students1 = students;
        int bus = 0;
        int minBus = 0;
        int taxi = 0;
        if (students >= 52) {
            bus = students1 / 52;
            minBus = (students1 - 52) / 23;
            taxi = (students1 - 75) / 10;
        } else if (students1 < 52 && students1 >= 23) {
            minBus = students1 / 23;

        } else if (students < 23 && students > 10) {

            taxi++;
            taxi++;
        } else if (students <= 10) {

            taxi++;
        }
        System.out.println("you will need: " + taxi + " taxi " + minBus + " MiniBus " + bus + " bus ");
    }


}


molten hill
#

I would get type by type. 🙂
And use % for get remaining student for further calc. 🙂

#

if (studentNumber >= BUS_CAPACITY) { bus = studentNumber / BUS_CAPACITY; studentNumber = studentNumber % BUS_CAPACITY; }

#

And another If for MINBUS_CAPACITY and TAXI_CAPACITY.

And at the end of all the if, the last If, for the last Taxi.

#

Actually ur code isn't good. Cause u don't use the number of minBus and bus. 🙂

If u got 200 students.
U got 3 Bus (156 students)
For minBus, u calc for 200-52 Students instead of (200 - 3 * 52)

#

% can give u the remaining value of a fraction.
200 % 52 = 44

brittle badger
#

WRONG TAG

orchid night
#

WHY?