Win a copy of OCP Oracle Certified Professional Java SE 11 Developer Practice Tests this week in the OCP forum!

Aria Villano

Greenhorn
+ Follow
since Feb 15, 2021
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Aria Villano

Thank you guys for your help though
1 week ago
No worries. And yes - unfortunately, I cannot share my code online since this is for an assignment. I wish I could because I know a lot of things can be fixed to improve it; plus I have over 100 lines of code anyway.
1 week ago
What -1 are you referring to? I also did create a for loop to print out the array which is working fine. Also, I thought it would be harder to make the game with 1 array, so I made 2 instead.
1 week ago
I also forgot to mention that numBees has already been declared after my arrays.
1 week ago
I basically did what you did except I have:


And my while loop has one more statement than yours which is:

Campbell - Thanks for the advice, I did not think about it like that. I will probably do it that way then.


1 week ago
Oh, I see. I already have a boolean array for the bees though, plus the char array.
1 week ago
I know that issue won't happen because my instructor said that that won't be a problem. And yeah, you're right about the char array. The only reason I did that is because the squares need to be blank before they're revealed and I make them blank with whitespace (like: ' '). The only other option to be able to make them blank would be with a String array. So should I make a third array that's of type int?
1 week ago
I did something similar to the code you posted but I used a char array because the squares are supposed to be blank before they're revealed. I also have a 2nd array that is of type boolean for the bee locations and is supposed to return true if there is a bee in that location. And the file won't have coordinates that are not on the grid. However, if the user enters a coordinate to reveal or mark a square that is not on the grid, then that will be handled.  
1 week ago
Well, in a correctly formatted file, the size of the array would be double the amount of bees, right? I only want to store the locations in the array, as I have already stored the size and the number of bees. For example, if there were 2 bees, there would be 2 coordinates, and therefore 4 numbers - so the size of the array would be 4. If there were 10 bees, there would be 10 coordinates and a total of 20 coordinate integers. So, would it not work if I did this (my array is called beeLoc):
int[] beeLoc;
beeLoc = new int[numBees * 2];
1 week ago
I do have a scanner object which I created before the while loop. So, I guess I'm having trouble with storing the values. Could I just make an int array to store the coordinates? And no, I did not consider making another class because it's required to only have 2 classes.

I also do have a say in the format of the file. The first 2 numbers will always be the width and the height of the board; the 3rd number is the number of bees; and then the remaining numbers are the coordinates for the bees. The file format will always be the same, I just don't know what the numbers are. I do not need to account for if the size is smaller than the coordinates because no files will be formatted like that.

Here's an example of what the file would contain:
10 10
2
0 1
2 3
This would be a 10x10 board with 2 bees located at 0,1 and 2,3.

1 week ago
My bad, I didn't know that. Regarding the board size, it is not fixed - the user determines the size (I wish it was fixed, it would make it much easier haha).
1 week ago
Hi! I am new to this forum and I am also a beginner in Java so please go easy on me haha. I just need some ideas with this problem I'm having:

I am creating a game similar to minesweeper, but instead of mines, it has bees (beesweeper xD). I have to pass in a file to my code which contains the locations of the bees. In the file, the bee locations are written like coordinates (ex: 0 1). The file will typically have multiple coordinates for the bees (more than 1 location). I am having difficulty on how to read these values and store them in a variable. I am using a while loop which checks for .hasNextInt() and then I use .nextInt() to read each integer and store them. Since the bee coordinates have multiple integers, I obviously can't store them in a single integer variable. I was thinking of storing them in an integer array. Thoughts? (I would also like to point out that there is not a set number of bee locations - it changes depending on the file given).

Another thing: I also need the game board to update after a command that the user enters. I don't need exact code or anything, I just want some ideas for how to go about this. Would I use a for loop? If statements?

I also have another problem. I have 2 classes and I am kind of confused on how to call a class from another class? Would it be fine to call my constructor that's in class B from class A, and then run only class A?

This is my first time making a game with Java so I appreciate any help. Thank you!
1 week ago