#Codes
77 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @vale karma! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
i wrote this but i can't continue
How will i identify to videoGameList
and the methods
there are two methods
yep but i didn't understand how will i identify "videoGameList"
its a VideoGame[]
its an array yes
public class ShoppingSite {
private String storeName;
private int videoGameCount;
private int totalGameStock;
private VideoGame[] videoGameList = new VideoGame[totalGameStock]; // reference to a VideoGame class somewhere
public ShoppingSite(String storeName) {
this.storeName = storeName;
}
public String getStoreName(){
return this.storeName;
}
public void addVideoGame(VideoGame videoGame){
videoGameList[this.videoGameCount + 1] = videoGame;
this.videoGameCount++
// maybe add check if videoGameCount > totalGamesStock then can't add more videoGame's
}
}
Think this could work?
This assumes that totalGameStock is the maximum number of games in the store and videoGameCount is how many games are in the stock room
how can i test "totalgameStock"
when i add the new game it has to be increase
Is this a school project?
nope i wanna make a practice
Looking at the error message, there seems to be an error on line 15 of ShoppingSite.java
it is " videoGameList[this.videoGameCount++] = videoGame;
"
So an array is immutable, you can't keep updating the length of videoGameList. Can I see a screenshot of ShoppingSite.java to try and fix the error
I think the error is it needs to be:
videoGameList[this.videoGameCount + 1] = videoGame;
yes this should fix your error ^
isn't it same already?
Also, in your constructor function you need to instantiate what videoGameCount and totalGameStock are, and then move the ```java
new VideoGame[this.totalGameStock];
You normally use ++ if you want to add one to the value. It might return the value + 1 but for readability I would say ```java
this.videoGameCount + 1
You still need to instantiate this in the constructor. I feel as though if you are struggling with this and you aren't doing this as part of education then you should rewatch your fundamentals as it is covered well in the freecodecamp java course (https://www.youtube.com/watch?v=A74TOX803D0) or if you are in education you should wait until you get further or talk to your lecturer
Learn the Java programming language in this complete beginner's course. You will learn all the main features of Java (version 17) and how to use Java for your own projects.
🔗 Code along on Replit: https://join.replit.com/java-students
✏️ Farhan Hasin Chowdhury created this course.
🏗 Replit provided a grant that make this course possible.
🔗 h...
but how , i already instantiate constructor called " ShoppingSite(String storeName),
wil
will i have to create one more?
You need to instantiate all of the variables in there preferably however your class diagram doesn't ask for any other inputs except for a String. As far as I can tell you haven't attempted to do this by yourself and have just copied and pasted what I have given. I recommend you go back to the fundamentals to understand how this all works. I'm not trying to be mean I think this project may just be a bit too advanced for you currently
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.
but i have to ask one more thing
as you say " your class diagram doesn't ask for any other inputs except for a String". So, how ahaha
im not asking the code
but how it can be possible
I assume there must be a hard coded value for these variables, which would mean they don't need to be in the constructor, however without knowing these values I can't tell you if this is the solution. If I were making this as a practice project I would just include these values in the constructor
Where did you find this diagram? It seems like a fun challenge
yep my friend gave
actually i wrote the other codes
can i show you
like that
i didn't understand only "addVideoGame
my friend gave me the print
it has to be like this
1m
i did everything actually but i couldn't write the last sentence
Right okay, looking at what the output is I would scrap what I told you lol. I would be interested in how your friend designed the videoGameList as it is a list with unknown size so I would use an ArrayList<VideoGame> however the typing is VideoGame[] so you must know how big the videoGameList is?
or I guess you could make videoGameList's size some large number
yeah actually i can try arraylist
i guess it doesn't matter for him
i tried and it worked but i guess i have to create methods called "addVideoGame"
Show code
i am trying arraylist now
how it could be?
i created a arraylist and i used ".set" command
Instead of using the .set command you can use the .add command to append to the end.
also your videoGameCount is now wrong. to get the total you would need to loop through your videoGameList and get the total of all the VideoGame's getGameStock's()
oh thank u
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 will try that (i hope)