#Error when trying to run code on bluej.
1 messages · Page 1 of 1 (latest)
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
So is the issue with something I'm typing into like the parameter slot or the code? (would you like to see the code)?
Can I see ur code?
The only issue here is redundant String temp, but method has no mistakes in syntax
And this code is fine too
So why is it that the addPack method wouldn't take my parameter again?
Have you declared a variable that you're trying to reference?
when you say declare a variable do you mean like assign a value to something?
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?
Every variable you're referencing should be declared
What do you mean "need to equal"
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?
It is declared and not assigned
.
So declaring is like making the properties of something known
@high panther has 0 active warns with a total of 0 severity.
like it's a string boolean integer etc
Wait yeah then I think that the parameter pack is declared
it's declared as an object of a class I created before
yh I think so
is there anything else that could be wrong?
At this point - i think no
I didn't see the full code
So I cannot tell that everything's ok
if I send you everything would you mind reading through it or nah too long?
No, you can send
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
Wait, why cannot you just copy and paste code? It's much simpler than making screenshots
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 ❤️
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
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)
In () declaration can only happen within a method declaration
When you're defining arguments for method
public void someMethod(Class arg)
Only here
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