This site requires JavaScript, please enable it in your browser!
Greenfoot back
coder04
coder04 wrote ...

2015/9/7

Inputting and calculating a result

1
2
coder04 coder04

2015/11/8

#
If I wanted to show this aswell as the wheels and doors needed do I need to include this
System.out.println(cup*140+lemon*300+(sugarPerBag-1))/sugarPerBag;
When I do include this it highlights
/sugarPerBag;
and says not a statement
davmac davmac

2015/11/8

#
If you examine the line by parts:
System.out.println(cup*140+lemon*300+(sugarPerBag-1))
This is a complete method call that prints a calculated value. Note that the brackets much up - everything inside the outermost brackets is the argument to the method call. The method doesn't return a value.
(...)/sugarPerBag;
This divides the result of the method call by sugarPerBag. However, as mentioned, the method call prints something out but doesn't return a value. You can't divide a non-value by something, so you get an error. If you want to change what it prints out, you need to divide the argument, not the method return:
System.out.println((cup*140+lemon*300+(sugarPerBag-1)) / sugarPerBag);
(I added an extra pair of brackets so that the whole expression is divided, which is probably what you want).
coder04 coder04

2015/11/8

#
Oh right I see
coder04 coder04

2015/11/8

#
I wanted to make pack for the doors and wheels but when I make another pack I want it to pick the bigger packs then if it needs more a little bit more wheels or doors choose the smaller pack so it works its way down.
       System.out.println("You need " + (cars*4 + trucks*6) + " wheels and " + (cars*4 + trucks*2) + " doors.");
        int wheelsPerPack = 5;
        int wheelPacksNeeded = (cars*4+trucks*6+(wheelsPerPack-1))/wheelsPerPack;
      
       System.out.println("You need " + (cars*4 + trucks*6) + " wheels and " + (cars*4 + trucks*2) + " doors.");
        int wheelsPerPack = 10;
        int wheelPacksNeeded = (cars*4+trucks*6+(wheelsPerPack-1))/wheelsPerPack;
      
coder04 coder04

2015/11/8

#
System.out.println("You need " + (cars*4 + trucks*6) + " wheels and " + (cars*4 + trucks*2) + " doors.");
 int smallwheelsPerPack = 5;
 int smallwheelPacksNeeded = (cars*4+trucks*6+(smallwheelsPerPack-1))/smallwheelsPerPack;
 
System.out.println("You need " + (cars*4 + trucks*6) + " wheels and " + (cars*4 + trucks*2) + " doors.");
 int mediumwheelsPerPack = 10;
 int mediumwheelPacksNeeded = (cars*4+trucks*6+(mediumwheelsPerPack-1))/mediumwheelsPerPack;
danpost danpost

2015/11/8

#
With different size packs, you will be calculating more than one value (number of 10-packs and number of 5-packs to purchase). Therefore,
int wheels = cars*4+trucks*6;
int tenWheels = wheels/10;
int fiveWheels =((wheels%10)+4)/5;
should give the correct number of packs of each to purchase (for wheels, at least). Curiously, I cannot believe that anyone would pack doors in packs of five. For basic cars and trucks, doors always come in pairs (a left and a right door). If you pack them in sets of five, it would be difficult to determine which door would be the odd one (you would need two different types of 5-packs. It would be more logical to count your doors as sets of doors and have maybe a 6-pack (3 sets) and a 10-pack (5 sets) -- but, so be it.
coder04 coder04

2015/11/9

#
I get this error Cannot find symbol- variable wheels
danpost danpost

2015/11/9

#
coder04 wrote...
I get this error Cannot find symbol- variable wheels
Show your code!
coder04 coder04

2015/11/9

#
I fixed it just needed to state the variable
coder04 coder04

2015/11/9

#
The decimal point does not work in this code
int smalleggPerBox = 6;       
int smalleggsBoxesNeeded = (cup*1+lemon*4.5+(smalleggPerBox-1))/smalleggPerBox;
System.out.println((cup*1+lemon*4.5+(smalleggPerBox-1))/smalleggPerBox);
danpost danpost

2015/11/10

#
You can avoid fractional values as follows:
int smalleggsBoxesNeeded = ((cup*2+lemon*9+1)/2+(smalleggPerBox-1))/smalleggPerBox;
coder04 coder04

2016/1/25

#
So i wanted the program to show how many medium boxes first then move onto the small boxes but it does not seem to be working.
  int smallsugarPerBag = 200;
        int smallsugarBagsNeeded = (cup*140+lemon*300+(smallsugarPerBag-1))/smallsugarPerBag;
        System.out.println((cup*140+lemon*300+(smallsugarPerBag-1))/smallsugarPerBag);

       int sugar = cup*140+lemon*300;
       int mediumSugarPerBag = sugar/200;
       int smallSugarPerBag =((sugar%200)+140)/300;
       System.out.println(((sugar%200)+140)/300);
danpost danpost

2016/1/26

#
I am not sure I understand line 6 of your last code post. I would think that the assigned value would be some constant greater than 200, which is the number of sugar units per small bag. Or, am I confused as to what values these variables are trying to represent? At any rate, the code should not even compile. You should be getting a 'smallSugarPerBag' already defined message. Ignore this part. The two variables are different by one character being different cases (one upper and one lower). However, this does confuse things (representing two different values with basically the same name).
CALLUM13221 CALLUM13221

2016/1/26

#
hi
You need to login to post a reply.
1
2