• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using BlueJ and can't understand the error

 
Greenhorn
Posts: 4
Mac Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!]
 
Ranch Hand
Posts: 250
1
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac Firefox Browser Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
reply
    Bookmark Topic Watch Topic
  • New Topic