| Author |
variable to hold the size of the array
|
Reno Madrigal
Greenhorn
Joined: Sep 24, 2007
Posts: 18
|
|
I am stuck on this portion of my assignment please help me. Here is what I have so far, My question is how do I put in the size , i know after PetService class I will use class ServicesArray which will use a variable to hold the size of the array, also i will null reference using PetService[] servicesArray; Is what I am looking for simply
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
Originally posted by Reno Madrigal: ...Is what I am looking for simply
Yes, assuming "size" represents an int.
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
Reno Madrigal
Greenhorn
Joined: Sep 24, 2007
Posts: 18
|
|
Okay I finished a rough draft of my coding but I am getting a few identifier expected errors and I know that they are there because that code needs to be in a class but where am I going wrong on this?
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
Originally posted by Reno Madrigal: ... I am getting a few identifier expected errors and I know that they are there because that code needs to be in a class but where am I going wrong on this?...
I think you mean because the code needs to be in a method. Start by correcting those errors. You need to try to get this to compile before moving forward.
|
 |
Reno Madrigal
Greenhorn
Joined: Sep 24, 2007
Posts: 18
|
|
I feel hopeless because when I move 1 thing around or something i get like 29 errors, yet if i leave it alone i get like 3 errors, I am just really confused at what I should do next, It wont compile correctly because of my errors here is the latest log with my code: Here are my errors: ------------------Configuration: MadrigalRPA6 - JDK version 1.6.0_02 <Default> - <Default>-------------------- E:\MadrigalR\MadrigalRPA6\src\MadrigalRPA6.java:19: cannot find symbol symbol : class StaugIO location: class PetService private StaugIO io = new StaugIO(); ^ E:\MadrigalR\MadrigalRPA6\src\MadrigalRPA6.java:19: cannot find symbol symbol : class StaugIO location: class PetService private StaugIO io = new StaugIO(); ^ E:\MadrigalR\MadrigalRPA6\src\MadrigalRPA6.java:86: incompatible types found : double required: java.lang.String return price; ^ E:\MadrigalR\MadrigalRPA6\src\MadrigalRPA6.java:109: cannot find symbol symbol : class PetServices location: class ServicesArray servicesArray = new PetServices[size]; ^ E:\MadrigalR\MadrigalRPA6\src\MadrigalRPA6.java:109: cannot find symbol symbol : variable size location: class ServicesArray servicesArray = new PetServices[size]; ^ E:\MadrigalR\MadrigalRPA6\src\MadrigalRPA6.java:111: cannot find symbol symbol : variable io location: class ServicesArray int size = io.readInt("How many services do you have to enter?"); ^ E:\MadrigalR\MadrigalRPA6\src\MadrigalRPA6.java:115: cannot find symbol symbol : class Service location: class ServicesArray PetService services[] = new Service[size]; ^ E:\MadrigalR\MadrigalRPA6\src\MadrigalRPA6.java:119: cannot find symbol symbol : variable number location: class ServicesArray for(int i = 0; i < number; ++i) ^ E:\MadrigalR\MadrigalRPA6\src\MadrigalRPA6.java:121: cannot find symbol symbol : class Service location: class ServicesArray services[i] = new Service(); ^ E:\MadrigalR\MadrigalRPA6\src\MadrigalRPA6.java:126: cannot find symbol symbol : method setPrice() location: class PetService services[i].setPrice(); ^ E:\MadrigalR\MadrigalRPA6\src\MadrigalRPA6.java:131: cannot find symbol symbol : variable number location: class ServicesArray for(int i = 0; i < number; ++i) ^ E:\MadrigalR\MadrigalRPA6\src\MadrigalRPA6.java:133: cannot find symbol symbol : variable PetServiceInfo location: class ServicesArray PetServiceInfo = "PET SERVICE " + (i+1) + " DATA\n"; ^ E:\MadrigalR\MadrigalRPA6\src\MadrigalRPA6.java:134: cannot find symbol symbol : variable PetServiceInfo location: class ServicesArray PetServiceInfo += "\nSERVICE CODE: " + services[i].getServiceCode() + "\n" ^ E:\MadrigalR\MadrigalRPA6\src\MadrigalRPA6.java:140: cannot find symbol symbol : variable petserviceInfo location: class ServicesArray io.writeInfo(petserviceInfo); ^ E:\MadrigalR\MadrigalRPA6\src\MadrigalRPA6.java:140: cannot find symbol symbol : variable io location: class ServicesArray io.writeInfo(petserviceInfo); ^ 15 errors Process completed.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16687
|
|
I feel hopeless because when I move 1 thing around or something i get like 29 errors, yet if i leave it alone i get like 3 errors, I am just really confused at what I should do next, It wont compile correctly because of my errors here is the latest log with my code:
Generally, the thing to do is to fix the first few errors, and then recompile. The reason is because errors tend to chain react -- it just takes one error to cause other errors. So... whether you have 29 errors or 3 errors, just fix the first few and recompile. Anyway, the first error... States that it doesn't know what the StaugIO class is -- which I assume is a class that you got from your instructor. Is this class in your classpath? and if it is, did you import the package that it is in? Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Reno Madrigal
Greenhorn
Joined: Sep 24, 2007
Posts: 18
|
|
|
Yes I always do the same thing for each assignment which is right click my Assignment and "add existing directory" and then i locate my staugIO class from my jumpdrive
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16687
|
|
Originally posted by Reno Madrigal: Yes I always do the same thing for each assignment which is right click my Assignment and "add existing directory" and then i locate my staugIO class from my jumpdrive
Well, check it again, because that's the error. Either (1) it isn't in your classpath, (2) you didn't import the package, or (3) you mis-spelled, or have the wrong case, for the class. We can't really tell, because we don't have the class here. Henry
|
 |
Reno Madrigal
Greenhorn
Joined: Sep 24, 2007
Posts: 18
|
|
it just doesnt make sense because i ran my other programs that are on the same drive and use the same staugio and they dont come up with errors, even my src txt reads this: E:\MadrigalR\MadrigalRPA6\staugIO\StaugIO.java and that is correct I guess i can try on my class computer, can we go to the next error?
|
 |
Reno Madrigal
Greenhorn
Joined: Sep 24, 2007
Posts: 18
|
|
i guess this would help if i added this in my code that fixed the problem so now on to my other errors, sorry
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16687
|
|
I guess i can try on my class computer, can we go to the next error?
Like I mentioned, errors tend to chain react -- fix the first few and recompile. Going to the next one may work, or you can spend hours on a problem that was caused by the previous problem.
that fixed the problem so now on to my other errors, sorry
So now that you fixed it -- recompile and go after the first error again. So what is the first error? Henry
|
 |
Reno Madrigal
Greenhorn
Joined: Sep 24, 2007
Posts: 18
|
|
E:\MadrigalR\MadrigalRPA6\src\MadrigalRPA6.java:87: incompatible types found : double required: java.lang.String return Price; from here [ November 05, 2007: Message edited by: Reno Madrigal ]
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9946
|
|
|
The error message tells you exactly what the problem is. Your method is declared to return a string. the thing you are trying to return is a double. you need to either a) change what the method is declared to return, b) change what the returned thing is, or c) create a new thing (in this case a string) and return that.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
 |
|
|
subject: variable to hold the size of the array
|
|
|