Following a UML class diagram. Stuck and need help!
So, I have to create this small program in Java right? I finished pretty much all of it but there's this problem with the Main class that I'm pretty much stumped with. You can see my code below.
Basically as far as I understand it, this is technically the way to do it? But it doesn't work that way since it's asking the variables to be static or something. But I can't make them static because the UML doesn't say to make them static. I asked ChatGPT to what to do with this and she told me something like creating a new Main object or something but I don't think I can do that with this UML diagram? (since it doesn't say to make one).
Wondering what exactly to do here... Or even whether its doable with this diagram. Or maybe I'm missing something completely obvious. I'm really just a few weeks into this class! This is like, a question from last year's one. The code pretty much works other than that. Thanks in advance!<3
import java.util.LinkedList;
public class Main {
public LinkedList<Account> accounts;
public LinkedList<String> firstNames;
public LinkedList<String> lastNames;
public LinkedList<Integer> accountList;
public LinkedList<Integer> balanceList;
public String file;
public ReadAccounts readAccounts = new ReadAccounts(file);
public Transaction transfer = new Transaction();
public static void main(String[] args) {
file = "C:/Users/KatsPC/Desktop/readthis.csv";
}
}
Oh, the error is at file = "C:/Users/KatsPC/Desktop/readthis.csv";
29 Replies
⌛
This post has been reserved for your question.
Hey @Run! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
Hi. You've accessed a field that is only available after class initialization. If you want to work with it, you need to mark the "file" field as
public static String file
;. I don't know what you're doing, but you'd better declare this variable in the "main" method.if you want to access these fields in the main method then you need them to be static
you could make another class thats not named main and have these fields without them being static though
@Голди @ayylmao123xdd hii thanks for responding!
Wouldn't the UML diagram need to have, like underlines underneath the variables and stuff for me to make them static?
Not me pinging the wrong person. Sorry 😭
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
What do you mean by underlining the variables?
In the UML diagram
ok so
to run the app you need this code in some class
Isn't there supposed to be a line there underneath to say they are static
so you could make a class lets say
AppRunner
and put the main method there
and then make the main class with those fields
let me test that
I mean, I still can't do that because it goes outside of the UML diagram
(I think)
can you show how you run the application btw
do you use the main class for anything
i think the problem is with the naming of the uml because most of the time the main class is used to run the application
you can have something like this
I think the naming is fine because the main class is the place where the guideline says to run/test the program from
is it supposed to be 1 file per program
because if you do a static field for file for example
Like .java files?
then you can have only one file
no the variable
string file
Yeah only 1 file
It's like made to just read 1 file
then the fields should be static i guess
either you make the fields static or you have to do the example i showed
maybe the person that made the uml forgot to say that theyre supposed to be static fields
Chatgpt said to do something similar to what you said but the problem is that the UML doesn't say anything about making another class 😭
I'm just here wondering what's less "wrong", making another class or making the variables and stuff static
Maybe, yeah lol
i think static is the better option
if you run the program from the main class that means you cant do the example like i showed
I think so too. Thanks for your time!
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
I'll just keep this thread open just in case someone has a magical answer or something
ok
heres a hilarious gif then
Literally me
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
The UML diagram doesn't say that Main should have the main static method
Are there are other requirements?
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.