• Post Reply Bookmark Topic Watch Topic
  • New Topic

variable to hold the size of the array  RSS feed

 
Reno Madrigal
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Reno Madrigal:
...Is what I am looking for simply


Yes, assuming "size" represents an int.
 
Reno Madrigal
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Reno Madrigal
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!