Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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:



 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

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
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

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
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please use the correct format of comments, eg for documentation comments:

Don't use long rows of **********, nor /* */ on each line.
 
boniface nasah
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
Marshal
Posts: 79178
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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>

 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

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.
 
sree java
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic