Mona Smith

Greenhorn
+ Follow
since Jan 16, 2019
Merit badge: grant badges
Biography
I am a high school student interested in CS and excited to learn more about technology! I love this website, it's the best place to ask questions in an encouraging, friendly, non-judgemental environment.
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Mona Smith

Thanks to everyone who replied. I ended up using the GridBag layout which worked better in my case, since my two buttons were different sizes. Now I'm just having some troubles linking together the JFrames to the main Frame once 'Start' is pressed, but I should be able to figure that out soon!
5 years ago
Thanks Rob Camick, it was a dumb mistake on my part!
5 years ago
Hello, I am trying to make a snake program but I'm having some trouble with the main screen. I am trying to make the Snake title, a start button, and a back button, but the Start button seems to be taking up the whole page and I can't figure out why. I am also trying to use Box Layout to create vertical boxes but that's not working either. My code is attached below:



Any help would be appreaciated as to why this is happening.
5 years ago
My goal is to create a simple snake game. I was expecting to get the snake to move around on the screen, but I am getting the error:



I'm not sure what this means but it has to do with private class Key implements @KeyListener at the bottom of the Screen class. I've seen that the problem could be that you have to put it in a different method, but mine already is. So here's my code:

Snake class:



Bodypart class:



Frame class:



Thanks in advance for your help!
5 years ago
Hello, I have a few static members exercises due and I wasn't sure if I am doing this correctly. Here is the question:

Create a class named Shirt with data members for collar size and sleeve length.  Include 2 constructors (default and one with both data members) and appropriate set and get methods.  Create a static variable to hold the material type and set it to “cotton”. [Shirt.java].  

Create a TestShirt class with a main method to test the Shirt class.  Create 5 objects of the class. Three will use the default constructor and then the set methods and user input to set the values. The other two will use the overloaded constructors and values that you provide when you instantiate the objects. Output all information for each object.



Here is my code:


Second class:




My questions are:

1. I'm not sure what I should be putting in the default constructor- is it values you give it or just blank?
2. How can I use user input from and set method from the default constructor for the first 3 values? Super confused about that.
3. How can I use overloaded constructors when I instantiate the object for the last two?

Thank you.
5 years ago
Hello,

Ok thank you everyone for your suggestions! The reason why I have extra comments is because my teacher requires us to do so. But this is my code using your suggestions:


5 years ago
OK Thank you! Can you specify what you mean by that? Like this?



That gives me this output:



5 years ago
Hello,

Yes I forgot to println! Thanks for that. But it still outputs as:



Whereas I want it to be in three rows according to test #.
5 years ago
Hello, I would like to print this out using arrays and for loops:

Test     Student 1     Student 2     Student 3
Test 1      89                 76                88
Test 2      78                 87                70
Test 3      90                 94                20

But my program does not work! It outputs everything side by side, like this:
 


This is my program:




Thank you for your help!
5 years ago


It gives me the error message above, the code does not run at all
5 years ago
Hello everyone, I've needed help on a program that asks the user for 5 countries, their currency name, the exchange rate and displays it in dollars using arrays. This is my code:




Help is much appreciated. Thank you.
5 years ago
Oh ok thank you! I tried subtracting one so the line for the student is [row-1][col-1] and that seems to give me the correct answer. Yes, there are unnecessary comments as my teacher wants us to comment on at least every other line of code to help us better understand it. I didn't do it in the second part, as I was still tinkering around with it. No, I have not learnt about methods yet! The only problem now is that I'm not sure how to display a message if the student asks for an array which has not been entered.
5 years ago
Wow thank you so much! It means a lot, I really needed the motivation!
5 years ago
Hello,

I have to write a program for two users, a school admin and a student. The admin must first enter a password and enter 15 courses by day Mon-Fri (1-5) and time Morning, Afternoon, Evening (1-3) into an array. Then the student can enter the day and time and view courses available. If the admin has not entered a course for that day, it should display 'Course not available'. This is the code I have:






But I have two problems: when I try to enter a day and time for the student, this error shows up: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3 at pkg.Exercise3.main(Exercise3.java:72)
which I know means my array is out of bounds, but I'm not sure why as I entered numbers like 2 for day and 3 for time! Also, I cannot figure out how to display the message that the 'course is not available' if the array has not been filled.

Any help would be much appreciated! Thanks!
5 years ago
Thank you all for the help! And yes, my teacher requires that we comment on at least every other line of code to make sure we understand what we are doing. And thank you, I will put the square brackets immediately following the type from now on.
5 years ago