This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Phone subscribers multiple threads: incompatible type errors and cannot find symbols error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

Phone subscribers multiple threads: incompatible type errors and cannot find symbols error

boniface nasah
Greenhorn

Joined: Sep 30, 2004
Posts: 5
PLEASE HELP! I have this assignment (see below) and have a solution for it using synchronized lists. However my code does not compile successfully and I need some help fixing it. Please be patient with me as I am a slow learner and new to synchronized thread java programming. Also I have a limited time window to resolve this. My source files are also enclosed. This is the error I get:
C:\java\TMobile>javac -Xlint TMobileSubscriber.java
TMobileSubscriber.java:34: cannot find symbol
symbol : variable Subscriber
location: class TMobileSubscriber
ArrayList Subscribers = new ArrayList(Subscriber);
^
TMobileSubscriber.java:37: warning: [unchecked] unchecked conversion
found : java.util.ArrayList
required: java.util.List<T>
List subscriberList = Collections.synchronizedList(Subscribers);
^
TMobileSubscriber.java:37: warning: [unchecked] unchecked method invocation: <T>
synchronizedList(java.util.List<T>) in java.util.Collections is applied to (java
.util.ArrayList)
List subscriberList = Collections.synchronizedList(Subscribers);
^
.\Subscriber.java:339: reached end of file while parsing
} /* class Subscriber extends Runnable */
^
TMobileSubscriber.java:58: non-static method wait(long) cannot be referenced fro
m a static context
wait(60000);
^
.\Subscriber.java:28: cannot find symbol
symbol : variable Subscriber
location: class Subscriber
this.subscriberList = Collections.synchronizedList(new ArrayList(Subscri
ber)) ;
^
.\Subscriber.java:28: warning: [unchecked] unchecked conversion
found : java.util.ArrayList
required: java.util.List<T>
this.subscriberList = Collections.synchronizedList(new ArrayList(Subscri
ber)) ;
^
.\Subscriber.java:28: warning: [unchecked] unchecked method invocation: <T>synch
ronizedList(java.util.List<T>) in java.util.Collections is applied to (java.util
.ArrayList)
this.subscriberList = Collections.synchronizedList(new ArrayList(Subscri
ber)) ;
^
.\Subscriber.java:66: cannot find symbol
symbol : variable newSubscriber
location: class Subscriber
if (!subscriberList.contains(newSubscriber)) {
^
.\Subscriber.java:67: cannot find symbol
symbol : variable newSubscriber
location: class Subscriber
subscriberList.add(newSubscriber);
^
.\Subscriber.java:97: cannot find symbol
symbol : constructor Subscriber()
location: class Subscriber
Subscriber subscriber = new Subscriber();
^
.\Subscriber.java:100: incompatible types
found : java.lang.Object
required: Subscriber
subscriber = subscriberList.get(i);
^
.\Subscriber.java:135: cannot find symbol
symbol : constructor Subscriber()
location: class Subscriber
Subscriber subscriber = new Subscriber();
^
.\Subscriber.java:138: incompatible types
found : java.lang.Object
required: Subscriber
subscriber = subscriberList.get(i);
^
.\Subscriber.java:174: cannot find symbol
symbol : constructor Subscriber()
location: class Subscriber
Subscriber subscriber = new Subscriber();
^
.\Subscriber.java:177: incompatible types
found : java.lang.Object
required: Subscriber
subscriber = subscriberList.get(i);
^
.\Subscriber.java:221: cannot find symbol
symbol : constructor Subscriber()
location: class Subscriber
Subscriber subscriber = new Subscriber();
^
.\Subscriber.java:224: incompatible types
found : java.lang.Object
required: Subscriber
subscriber = subscriberList.get(i);
^
.\Subscriber.java:328: incompatible types
found : java.lang.Object
required: Subscriber
currentSubscriber = subscriberList.get(i);
^
15 errors
4 warnings

C:\java\TMobile> THANKS A LOT

ASSIGNMENT DETAILS:
Write a small java program that will store mobile subscribers in memory and allow a few operations on the subscribers. Each subscriber consists of a phone number, name, balance in cents, and decrement rate. A decrement rate is a number which indicates how many cents a subscriber is charged per minute. A phone number is a 10 digit number. In addition to the operations below, there should also be seperate thread running that prints the phone number and name of all the currently stored subscribers to standard out every minute.
The following operations should be supported:
1. Adding a new Subscriber:
a. This operation should accept all the attributes of a subscriber.
b. This operation should create the subscriber and save it.
c. This operation should fail with error code 100 and error message “Invalid subscriber definition!” if the phone number is not valid.
d. This operation should fail with error code 400 and error message “Subscriber already exists!” if the phone number corresponds to an existing subscriber.

2. Retrieving an existing Subscriber:
a. This operation should accept a phone number and return the associated subscriber.
b. This operation should fail with error code 200 and error message “Subscriber does not exist!” if the phone number does not correspond to an existing subscriber.

3. Removing an existing Subscriber:
a. This operation should accept a phone number and remove the associated subscriber.
b. This operation should fail with error code 200 and error message “Subscriber does not exist!” if the phone number does not correspond to an existing subscriber.

4. Update an existing Subscriber’s balance:
a. This operation should accept a phone number and an increment amount.
b. This operation should adjust the subscriber’s balance with the given amount.
c. This operation should fail with error code 200 and error message “Subscriber does not exist!” if the phone number does not correspond to an existing subscriber.
d. This operation should fail with error code 300 and error message “Balance is out of range!” if the new balance is less than $0 or more $1000.

5. Retrieve an existing Subscriber’s balance:
a. This operation should accept a phone number.
b. This operation should return both the subscriber’s balance in cents and how many minutes the subscriber can use before his balance is expired.
c. This operation should fail with error code 200 and error message “Subscriber does not exist!” if the phone number does not correspond to an existing subscriber.



MAIN CLASS:


THREAD CLASS:


OTHER CLASSES:



Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18550
    
  40

boniface nasah wrote:
C:\java\TMobile>javac -Xlint TMobileSubscriber.java
TMobileSubscriber.java:34: cannot find symbol
symbol : variable Subscriber
location: class TMobileSubscriber
ArrayList Subscribers = new ArrayList(Subscriber);
^


Basically, the compiler is complaining that you are using "Subscriber", but it has no idea what you are talking about -- as at that line, you have not declared anything with that name, or imported anything that has that name.

As for the rest of the errors... it's a good idea for a beginner to fix the first error, then recompile. Sometimes errors effect each other, and the later errors reported may not be accurate.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18550
    
  40


And although this project has threads in the name.... generally compile errors falls under the category of beginner Java. So... moving this topic to the beginner java forum.

Henry
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38087
    
  22
Your code is illegible without code tags; since you are new I might add them and you can see how much easier it is to read.
Never write so much code; only write one method at a time, then compile it and you will only get a few errors. I suggest you comment out about 90% of your code with // at the beginning of each line, then see how many errors you get. Correct them one at a time. Also run your code every time you write a new method, and test that method.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38087
    
  22
Please use the correct format of comments, eg for documentation comments:

Don't use long rows of **********, nor /* */ on each line.
boniface nasah
Greenhorn

Joined: Sep 30, 2004
Posts: 5
Thanks Henry & Campbell. I did as suggested and this is what I now get: PLEASE HELP

C:\java\TMobile>javac -Xlint Subscriber.java
Subscriber.java:57: cannot find symbol
symbol : variable nuSubscriber
location: class Subscriber
if (!subscriberList.contains(nuSubscriber)) {
^
Subscriber.java:58: cannot find symbol
symbol : variable nuSubscriber
location: class Subscriber
subscriberList.add(nuSubscriber);
^
2 errors

C:\java\TMobile>

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38087
    
  22
Why you can't find nuSubscriber? It should be obvious. Go and show us where nuSubscriber is declared. It's the same error you had earlier, just with a different spelling.
sree java
Greenhorn

Joined: Dec 10, 2012
Posts: 2
PLEASE HELP
do you have solution for this program.if so can you please send
















C:\java\TMobile>javac -Xlint Subscriber.java
Subscriber.java:57: cannot find symbol
symbol : variable nuSubscriber
location: class Subscriber
if (!subscriberList.contains(nuSubscriber)) {
^
Subscriber.java:58: cannot find symbol
symbol : variable nuSubscriber
location: class Subscriber
subscriberList.add(nuSubscriber);
^
2 errors

C:\java\TMobile>

Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4168
    
  21

Campbell Ritchie wrote:Why you can't find nuSubscriber? It should be obvious. Go and show us where nuSubscriber is declared. It's the same error you had earlier, just with a different spelling.


Already answered for you.


Steve
sree java
Greenhorn

Joined: Dec 10, 2012
Posts: 2
Write a small java program that will store mobile subscribers in memory and allow a few operations on the subscribers. Each subscriber consists of a phone number, name, balance in cents, and decrement rate. A decrement rate is a number which indicates how many cents a subscriber is charged per minute. A phone number is a 10 digit number. In addition to the operations below, there should also be seperate thread running that prints the phone number and name of all the currently stored subscribers to standard out every minute.
The following operations should be supported:
1. Adding a new Subscriber:
a. This operation should accept all the attributes of a subscriber.
b. This operation should create the subscriber and save it.
c. This operation should fail with error code 100 and error message “Invalid subscriber definition!” if the phone number is not valid.
d. This operation should fail with error code 400 and error message “Subscriber already exists!” if the phone number corresponds to an existing subscriber.

2. Retrieving an existing Subscriber:
a. This operation should accept a phone number and return the associated subscriber.
b. This operation should fail with error code 200 and error message “Subscriber does not exist!” if the phone number does not correspond to an existing subscriber.

3. Removing an existing Subscriber:
a. This operation should accept a phone number and remove the associated subscriber.
b. This operation should fail with error code 200 and error message “Subscriber does not exist!” if the phone number does not correspond to an existing subscriber.

4. Update an existing Subscriber’s balance:
a. This operation should accept a phone number and an increment amount.
b. This operation should adjust the subscriber’s balance with the given amount.
c. This operation should fail with error code 200 and error message “Subscriber does not exist!” if the phone number does not correspond to an existing subscriber.
d. This operation should fail with error code 300 and error message “Balance is out of range!” if the new balance is less than $0 or more $1000.

5. Retrieve an existing Subscriber’s balance:
a. This operation should accept a phone number.
b. This operation should return both the subscriber’s balance in cents and how many minutes the subscriber can use before his balance is expired.
c. This operation should fail with error code 200 and error message “Subscriber does not exist!” if the phone number does not correspond to an existing subscriber.


Can you please send me the elaborate solution for this assaignment. I Compiled The Above code in My Eclipse IDE, I Couldn't understand The flow, Do You have any other solution For this Assaignment?


Thanks,
Sree
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38087
    
  22
sree java wrote: . . . Can you please send me the elaborate solution for this assaignment. . . .
No. That is not how this website works. Please read this. And also please remind yourself of this before you post again.

Since this thread has gone inactive, I shall close it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Phone subscribers multiple threads: incompatible type errors and cannot find symbols error
 
Similar Threads
Just Can't figure it out and it's due today
Program to print numbers from 0 to 100 in words
Enhanced Observer pattern ?
toString method in vector.
Printing in Array in Ascending order