• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using BlueJ and can't understand the error  RSS feed

 
Julianna Greyjoy
Greenhorn
Posts: 4
Firefox Browser Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not done writing the code yet - obvs - but I don't understand why the program won't compile. It's a shipping program that will calculate shipping within Province and the rest of Canada (not important information but I know I'll have to use a lot of if else if statements).
i
Thanks for looking
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Julianna Rees wrote:
// ERROR SAYS
// unexpected type
// required:variable; found: value
else if (1 < packgwt < 3)
{ packgwt * shippingAB2 = totalABSHIP; }



Question: What is ....



supposed to do?

Henry
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

With regards to:
I'm not sure what you are even trying to accomplish with this. You have a multiplication operation as the target of an assignment. That makes no sense. What are you trying to accomplish with this? You do this a number of times in the code.

Looking ahead, this isn't valid syntax either:
If you want to check if the value is between 1 and 3, you'll need two expressions and-ed together.

[Edit: Henry beat me to it!]
 
Joel Christophel
Ranch Hand
Posts: 250
1
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Julianna Rees wrote:packgwt * shippingAB1 = totalABHIP;


The variable to which you are assigning a value must be placed on the left side of the assignment operator (i.e. equal sign). Also, you spelled your variable incorrectly. So the above should be: totalABSHIP = packgwt * shippingAB1;
You made this error two other times as well.

Julianna Rees wrote:1 < packgwt < 3


You cannot use compound inequalities. You must break it into two conditional statements: 1 < packgwt && packgwt < 3

And welcome to the ranch!
 
Julianna Greyjoy
Greenhorn
Posts: 4
Firefox Browser Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Awesome! Thanks so much for the help everyone!

I changed it and now came up with this


You guys are a great help! And sorry about the bad formatting, I'll try to remember to do that!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Speaking of formatting, your code is hard to read because it doesn't follow established conventions. This makes code surprisingly hard to inspect.

Rather than:
It should follow one of the established conventions of:
or

(I use the latter format.)

Notice how where the braces are placed differ from your original code.
 
Julianna Greyjoy
Greenhorn
Posts: 4
Firefox Browser Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the formatting help - I am in a first year programming class for Java (blueJ) so yeah my formatting isn't as great as it should be... Yet.
I've changed it to:


Hopefully this is easier to read and properly formatted.
 
Campbell Ritchie
Marshal
Posts: 56559
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Julianna Greyjoy wrote: . . . Hopefully this is easier to read and properly formatted.
'Fraid it isn't. It should look like this:-Welcome again

if (1 < packgwt) is much less easy to read than if (packgwt >= 1)
Actually, that bit is redundant. If you use else‑if, you have already excluded that. It is
if the weight is 1 or less,
otherwise if the weight is 3 or less
otherwise
It is always worth trying all sorts of different options with multiple else‑ifs, because you can often find a neater solution. You may find you must end with a plain simple else, otherwise you may confuse the compiler into thinking the variable might not be initialised.
 
Julianna Greyjoy
Greenhorn
Posts: 4
Firefox Browser Java Mac
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for your responses - I finished my assignment (five hours later...HA...) and I'm content with my output.

I'm so happy I joined up for Code Ranch Hopefully soon enough I'll be able to help, rather than be the one looking for it
 
Campbell Ritchie
Marshal
Posts: 56559
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!