Thread: Java problem
April 28th, 2010, 05:07 PM #1
- Join Date
- Jul 2006
Java problemGuys I haven't a clue where to being with this one. Any help much appreciated.
Three housemates all have different Nokia mobile phones but only have one charger
between them. Each phone works for a certain amount of time before needing to be
recharged:•phoneA needs to be charged every 48 hours•phoneB needs to be charged every 24 hours•phoneC needs to be charged every 16 hours•All phones take 2 hours to charge fully.
The charger can only be used by one phone at a time. If a phone needs to recharge but
the charger is in use it must turn off until the charger is free. A phone object must
keep a count of the number of times it was forced to turn off.
Create a phone class. The constructor accepts one integer for charge time (e.g. 48 for
phoneA), a reference to a charger object and a String for its name. The phone should
also have members that store the amount of hours that have elapsed since the start of
the week and whether or not the phone is on or off. When the end of the week is
reached (168 hours), a toString method should display the amount of times the phone
needed to be recharged and the amount of times, if any, that the phone had to be shut
down because the charger was not available.
Each phone must have a run() method which advances the time elapsed since the start
of the week by 1 hour for each ½ second of the simulation (i.e. the thread sleeps for
500ms). At the start of every new hour, the method should check if the phone needs to
be recharged, attempting to access the charger if it is free, or shutting down if not.
The run() method should adjust the time to the next recharge accordingly if the phone
does not need to be recharged.
Write a multithreaded Java application to simulate a week of phone activity in the
household. You should assume that each phone is fully charged on Monday morning.
The simulation will run for 84 seconds of real time (168 hours simulation). Display
messages in the terminal stating that the simulation has started, notifying the user if a
phone is recharging, has been shut down or turned on, and display each phone’s
toString method at the end of the simulation.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
By Darkdragonterra in forum Technical SupportReplies: 1Last Post: January 21st, 2010, 08:11 AM
By Vietster1 in forum Networking and InternetReplies: 0Last Post: June 17th, 2009, 01:26 PM
By orkboss in forum Applications and Operating SystemsReplies: 1Last Post: January 10th, 2006, 08:04 PM
By goatieau in forum Applications and Operating SystemsReplies: 1Last Post: September 17th, 2004, 11:05 PM
By Chase-Man in forum Technical SupportReplies: 4Last Post: February 4th, 2003, 04:56 PM