Nathan Montgomery

Ranch Hand
+ Follow
since Sep 25, 2019
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
1
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 Nathan Montgomery

Norm Radder wrote:One issue might be integer division.  status/100 will be 0 until status = 100.  Make status a double  or divide by 100.0 to do floating division.

Display the value of all your variables to make sure they are correct.


That is also true for expressions.  Printlng status/100 would show what is happening.


Made status a double and works perfectly, thanks!
1 week ago
I am trying to get the status bar for this program to update with the tickets that are being purchased. However, it only changes the to updated color once all the tickets are sold and I need it to gradually increase the color as the tickets are sold not change the whole bar to that color.

Heres my status bar class:


And then my TicketCounter class:

1 week ago

Dave Tolls wrote:OK, so we're back at this point.

What is parts at that point, and what data does it hold?
Add some debug printlns there (you'll need to use Arrays.toString() to print out the array).

I assume this is from the parameter passed in as parts[3] earlier (on line 40)?
So I would suggest printing out that parts array as well.

Edit: At the moment you are flying blind, and encountering an error and deciding you have no idea why.  And that's because you aren't printing out any useful debug information that you can use to figure it out.  Or at least to show us so we can help point you in the right direction.


Fixed it. I have yet to understand why, but when I changed it to be part[0],part[0],part[0] everything displayed correctly. I am confused to as why because the instructions I was given say the information is in the first 3 parts but this will have to do for now thanks.
1 week ago

Dave Tolls wrote:If this:

is line 72 then there is nothing in that line that would throw an ArrayIndexOutOfBoundsException.
Consequently that's not the line throwing the exception, or the code you posted is not the code being executed.


Apologies, line 72 is this:


And here is where instructors.txt is being created:
1 week ago

Carey Brown wrote:

Campbell Ritchie wrote:

Nathan Montgomery wrote:. . . array is supposed to be 3 parts . . .

In which case you ccan use indices 0 1 2. Have you printed the length of the array to verify it is length 3?

change the index of the array to 0 so part[0],part[0],part[0] . . .

No, that won't work, will it?
Where does the =, part of your regex come from? I can't see any = or commas in the file sample you showed.


I see to attempt on your part to respond to this.


I tried using indices 0,1,2 but that did not work and I only recieved the same errors. I have not printed the length of the array, but I will go ahead and try that. The = sign seems to not be apart of any of the files from what I now realize? The commas however, are apart of the Instructors.txt file as such:
Wanda Jean,Smith,null
Wilma,Fitz,null
Emily,Theo,null
1 week ago
I am re-posting my previous thread as I have still been unable to figure out how to fix the errors.
Here are the errors:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at controller.CourseFileHelper.getInstructor(CourseFileHelper.java:72)
at controller.CourseFileHelper.readFile(CourseFileHelper.java:40)
at tests.CourseFileHelperTest.main(CourseFileHelperTest.java:79)

Line 72


Line 40


Line 79


courses.txt is formatted as such:
12345|BIO101|11:15|12:55|Wanda Jean Smith wsmith@dmacc.edu|Building : 3 Room Number: 17 Campus: Ankeny Type: Science Lab Capacity: 22
23456|CIS171|10:10|12:20|Wilma Fitz wfitz@dmacc.edu|Building : 8 Room Number: 17 Campus: Ankeny Type: Computer Lab Capacity: 25
29876|LIT105|15:15|16:30|Emily Theo etheo@dmacc.edu|Building : 2 Room Number: 12 Campus: Urban Type: Classroom Capacity: 18
instructors.txt:
Wanda Jean,Smith,null
Wilma,Fitz,null
Emily,Theo,null
1 week ago

Campbell Ritchie wrote:Welcome to the Ranch

Have you inspected the array anywhere to confirm its length? How are you converting those lines to arrays? If you are using String#split(), what arguments are you passing to that method? Why have you got that cast in the first line of code (line 79)?


I inspected it and the, array is supposed to be 3 parts because that is what the instructor creates. The program sort of works if I change the index of the array to 0 so part[0],part[0],part[0] but then I recieve the same error just with the classroom file instead of the instructor. I am using String[] parts = string.split("[\\[=,\\]]"); and only arguments being passed in is a string that gets split; private Instructor getInstructor(String string)
2 weeks ago
I am receiving an Array Out of Bounds Exception when trying to read the Instructors from a file.

Here are my errors:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at controller.CourseFileHelper.getInstructor(CourseFileHelper.java:72)
at controller.CourseFileHelper.readFile(CourseFileHelper.java:40)
at tests.CourseFileHelperTest.main(CourseFileHelperTest.java:79)

Line 79 CourseFileHelperTest

Line 72 CourseFileHelper

Line 40 CourseFileHelper


Courses.txt:
12345|BIO101|11:15|12:55|Wanda Jean Smith wsmith@dmacc.edu|Building : 3 Room Number: 17 Campus: Ankeny Type: Science Lab Capacity: 22
23456|CIS171|10:10|12:20|Wilma Fitz wfitz@dmacc.edu|Building : 8 Room Number: 17 Campus: Ankeny Type: Computer Lab Capacity: 25
29876|LIT105|15:15|16:30|Emily Theo etheo@dmacc.edu|Building : 2 Room Number: 12 Campus: Urban Type: Classroom Capacity: 18

Instructors.txt:
Wanda Jean,Smith,null
Wilma,Fitz,null
Emily,Theo,null
2 weeks ago

Carey Brown wrote:Without seeing a sample of "courses.txt" it would be hard to say.


12345|BIO101|11:15|12:55|Wanda Jean Smith wsmith@dmacc.edu|Building : 3 Room Number: 17 Campus: Ankeny Type: Science Lab Capacity: 22
23456|CIS171|10:10|12:20|Wilma Fitz wfitz@dmacc.edu|Building : 8 Room Number: 17 Campus: Ankeny Type: Computer Lab Capacity: 25
29876|LIT105|15:15|16:30|Emily Theo etheo@dmacc.edu|Building : 2 Room Number: 12 Campus: Urban Type: Classroom Capacity: 18

This is the exact format of courses.txt, I need firstname,lastname, and email for the Instructor which seems to be in positions 4,5,and 6.
3 weeks ago
So I am recieving an error in my code that the information within my array is out of bounds. This array is supposed to contain 3 parts of information, email, firstname, and lastname. However, any part other than 0 seems to be out of bounds and I am confused on what to do from there. My instructor just threw all this code at us without a thorough explanation of how it works.

There a bunch of Instructors/classes so I will include the ones I think are necessary.

Tester class:


Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
at controller.CourseFileHelper.getInstructor(CourseFileHelper.java:73)
at controller.CourseFileHelper.readFile(CourseFileHelper.java:40)
at tests.CourseFileHelperTest.main(CourseFileHelperTest.java:79)
3 weeks ago

Carey Brown wrote:The only place you set teamList is in setTeamList() which is never called. In most cases this would never be called, so how then do you initialize teamList without calling this method?


So should I call the method within the addToTeam method, or what?
4 weeks ago

Carey Brown wrote:

Nathan Montgomery wrote:

Junilu Lacar wrote:The problem reported is NullPointerException and the line is

The only thing here that can cause an NPE is teamList being null. So make sure teamList isn't null when you call this method.


How do you suggest I do that? Because when I call the method I am adding players so that it won't be null, but are you saying it needs to be not null before I add players?


Are you initializing teamList anywhere?


In my roster class yes and my tester class when I attempt to add information to it

Heres part of my roster class:

4 weeks ago

Junilu Lacar wrote:The problem reported is NullPointerException and the line is

The only thing here that can cause an NPE is teamList being null. So make sure teamList isn't null when you call this method.


How do you suggest I do that? Because when I call the method I am adding players so that it won't be null, but are you saying it needs to be not null before I add players?
4 weeks ago

Carey Brown wrote:Does BasketballPlayer extend Player?


Here is my player class

4 weeks ago

Carey Brown wrote:Does BasketballPlayer extend Player?


Yes it does.

Roster class:


And tester class:

4 weeks ago