#Error when trying to run code on bluej.

1 messages · Page 1 of 1 (latest)

lost dew
#

First of all:
; only at the end of a statement

#

I suppose bluej will place it automatically

#

Because the correct code would be smth like:

#

snackMac1.addPack(hereYourVariable);

#

The symbol issue could be simply undeclared variable

high panther
lost dew
#

The only issue here is redundant String temp, but method has no mistakes in syntax

#

And this code is fine too

high panther
#

So why is it that the addPack method wouldn't take my parameter again?

lost dew
#

Have you declared a variable that you're trying to reference?

high panther
#

when you say declare a variable do you mean like assign a value to something?

lost dew
#

Yes

#
Declaration:
String a;

Assignment:
a = "hello";

Definition:
String a = "hello";
high panther
#

Then I think so wait does pack need to equal to something here explicitly in the code? if so nope pack is just a parameter

#

wait parameters need to be declared?

lost dew
high panther
#

I meant like need to be assigned to something

#

if I say int x; and just leave it is and not say x = 1 is it not declared?

lost dew
#

It is declared and not assigned

high panther
#

Oh shit

#

lol idk what declare means

high panther
# lost dew .

So declaring is like making the properties of something known

trail rockBOT
#
TheArtOfWar#1665
Recent Warns

@high panther has 0 active warns with a total of 0 severity.

high panther
#

like it's a string boolean integer etc

lost dew
#

Nevermind

high panther
#

Wait yeah then I think that the parameter pack is declared

#

it's declared as an object of a class I created before

high panther
#

is there anything else that could be wrong?

lost dew
#

At this point - i think no

#

I didn't see the full code

#

So I cannot tell that everything's ok

high panther
#

if I send you everything would you mind reading through it or nah too long?

high panther
#

Alright I'll tell you when I'm done with each class after I've sent them

#

Okay so First class PackOfCrisps

#

2nd Class Penny

#

Thats it

#

and the last class is the most long one 1 sec

lost dew
#

Wait, why cannot you just copy and paste code? It's much simpler than making screenshots

high panther
#

oh mb

#

kk maybe I should do that for the last class

lost dew
#

Use triple backticks

#

`

#

But triple

#

At start and end of code

high panther
#

final class

#

tbh the 2 other classes were designed for this class

#

Ik it'll probably take a while @lost dew lmk if you find anything but also lmk if you couldn't or sumn so I'm not left hanging tysm for the help regardless of the outcome man ❤️

lost dew
#
public void describe()
    {
     int packetsl;
     int penniesl;
     packetsl = packets.size();
     penniesl = pennies.size();
     System.out.println("The snack machine has" + packetsl  +"of crisps left and has taken"  + penniesl  +"in payment");
    }
        

Perfect example of declaration

#

int packetsl and int penniesl are declarations

#

And 2 lines below them are assignments

#

Code is fine

high panther
#

ah I see do declarations always have to look like that or can they happen within the parentheses as well?

#

like could it be public int test (int why)

lost dew
#

When you're defining arguments for method

#

public void someMethod(Class arg)

#

Only here

high panther
#

right okay that makes sense

#

ty tapeline

lost dew
#

And about ur original problem'

#

Just try passing a new instance of PackOfCrisps

#

snackMac1.addPack(new PackOfCrisps("salt"));

#

This method call (i suppose) works outside all your methods, thus nothing you've declared in methods is not visible. So you should pass either static field or just make new instance

#

In other words: something, that you can access outside methods

#

snackMac1.addPack( new PackOfCrisps("salt") );

#

This should work

high panther
#

Ah alrighty makes sense

#

ty Tapeline