Pierre Gadar

Greenhorn
+ Follow
since Mar 05, 2017
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Pierre Gadar

I have 2 class, one class Person with attributes(name, age) and a class main, i have to instantiate:
"Instantiate  age ∈  [0,100] " i don't know what it means, can you look at my code and tells if i did ok or not?
Thanks.



7 years ago

Emma Sophia Jones wrote:Okay so what you’re probably wanting is a HashMap – this is a container which stores a value (which can be any object) against a key (which again can be any object but is pretty often a String). When you call the method .get(<key>) on your HashMap it will return the value associated with that key.

So let’s say we have a HashMap where a person’s age is stored against their name, I can pull out Sally's age by saying
If you’re still a bit uncertain on HashMaps, I’d have a bit of a google and see if you can find a tutorial before you continue reading my post
When we’re creating the HashMap, we need to specify the type of key it will have and the type of value it will store – so something like this:

Once we have that, we can start putting in new guests with a .put() command.

You can then get people out of the HashMap with get():

And also remove them on checkout with remove():

To get this to work you’ll need to rewrite quite a lot of your hotel class as your approach so far probably isn't going to work. It might be worth starting from scratch instead of trying to slot it into what is there already. Does that help?



Thanks, i think it's more clear for me now;)
7 years ago

Emma Sophia Jones wrote:And would you like to keep track of them by name or by, say, room number?



Yes, by name;)
7 years ago

Emma Sophia Jones wrote:What's the goal of the assignment Pierre?

Are you just trying to keep track of the number of guests in the hotel? Or do you need to be able to retrieve information about them while they're staying there?



Yes i ll need to have the information about them after
7 years ago
I putted String instead of Integer in ArrayList but i changed and i still have the error, cannot convert ArrayList to int :/*******

7 years ago
Sorry, I am not familiar with arraylist, i have an error, "convert arraylist to int" someone knows?

7 years ago
Thanks all, y i think you're right emma, i'll try to make an arrayList()

(Carey, no it has to be protected for this exercice)
7 years ago
I have an error in my code ("Error convert object to int"), I have two class, a, class Personn with his attributes, and a class Hotel which has 2 functions checkout and checkin, the problem is:  I can't make person++ or -- because it's an objet , so i don't know how to make person++ in the function without eror, thanks






7 years ago

Les Morgan wrote:Since you are using synchronized in your methods, I suggest you change your declaration of numberOfOccupatedRooms to a protected static int.  This will make it a class variable and tie any and all threads to one instance of numberOfOccupatedRooms.  As it stands now in your code, the use of a protected int is an instance variable. Instance variables will tie to any particular instance, so if you have 2 instances running, then your number of occupied rooms will be tracked separately in each instance and allow maximum checkins in each instance, 250 in the first instance and 250 more in each additional instance.  Without the use of a static qualifier, Class Variable, you will be able to double, triple, or more book your rooms according to how many instances you have running.


ok, thanks


Campbell Ritchie wrote:I worry whenever I see anything marked static. Making the variable static would suggest every hotel has the same number of rooms. Are you sure about that? Shou‍ld the exercise use one instance reached by several threads? Is this possible in view of the tight specifications above?



But I think in the exercice, there is only one hotel
so i changed a little.. :

Paul Clapham wrote:I understand the "capacity" of a hotel -- it's the maximum number of people who can stay in the hotel at one time. That's what "capacity" means. But "size"? I don't understand what the "size" of a hotel is. Perhaps you could explain? Yes, I realize that having to work in English makes that sort of thing harder... perhaps you thought of a specific word in French (which it looks to me is your native language) but your English translation as "size" is not at all specific.

And don't be afraid of long variable names: if you want a variable to store the number of available rooms then numberOfAvailableRooms is a good choice for that variable's name.



Yes you're right ;)
For me capacity is the maximum number of rooms of the hotel(250) and size( yes i chosed a bad name) is the number of rooms occupated (by a person) ;))
Yes a long variable name is better ;)

Campbell Ritchie wrote:I think the time has come to turn yout computer off and write down what you are trying to do on paper. Only when you have that worked out will you be able to write any code.



Im not better on a paper, i dont see my mistakes, but what do you think of my function checkOut and checkIn?
ok, thanks , but i really don't understand, but i try

so in part I:
I don't know what others attributes than capacity (nomber of room)there is in the class
I don't know what to write in the function checkOut and CheckIn i write something but i dont really know:
Hello all,
I have to do an important exercice in java using thread and i dont understand at all

I put the enunciated after so it's more clear better to look what to do ( i passed long time translating it into english, tried my best;*-*)

my code.. :
Part1:

part2:


The enunciated /what i have to do: :/
-Thread-
General remarks:
- Classes can have attributes but they must be protected.
- Think about managing exceptions


Warning: Please read the entire subject carefully before starting.
A developer is planning to build a hotel with 250 rooms. To do this, he wants to create a simulation
Using the principle of producer / consumer and cooperative synchronization


I) Hotel class
Write the Hotel class that includes
1) A constructor
2) A checkIn () method representing the arrival of a person in the hotel
3) A checkOut () method representing the departure of a person from the hotel

Remarks :
It is impossible to simulate a person reserving a room if the hotel is full and it is
Impossible to simulate the exit of a person of the hotel if there is nobody in the hotel.


II)Person class
Write the class Person which has a constructor to assign at least:
1. A name
2. The number of stays(or sojourn) that the person passed at the hotel (numberOfStays)
3. The duration of each stay passed at the hotel (stayDuration)


III) ArrivingPerson and OutgoingPerson
- Write the ArrivingPerson class, to manage different people arriving at the hotel in
parallel. They come numberOfStays times and sleep at the hotel during stayDuration. At the
end of stays, display the name of the person and indicate that he has made his last arrival.

- Write the OutgoingPerson class to manage different people leaving the hotel in
parallel. 
This class also contains, in attribute, the duration of the departure of the hotel timeToPart and the action is repeated numberOfStays times.
At the end of the stays, display the person's name then indicate that the person made his last departure.
(Remarks: Think about the mechanisms of inheritance)


IV) ManagementHotel
Write the ManagementHotel class containing the main method to manage a table of 1000 people consisting of 500 people arriving at the hotel and 500 people leaving the hotel.
The Parallel simulation of persons must also be in this class. Instantiate the parameters of
simulation with random numbers.
For it :
- Put all the simulation in the method public static void main (String [] args)
- Define a variable populationMax and instantiate it at the right value
- Creating Population, a Person Table
- Instantiate  numberOfStays  ∈  [0,10]
- Instantiate half of population as ArrivingPerson ,with for each person  stayDuration ∈ [0,100]
- Instantiate the second half of the population as an OutgoingPerson, with for each person timeToPart ∈ [0,75]
- Prepare and run the simulation in parallel with populationMax threads
- Indicate when the simulation is finished

Remarks:
- Think of reserving the memory boxes of the tables
- Think of using thread operations only to objects that allowing it (this is not the case for Person, for example).



Thanks all

Norm Radder wrote:

maybe the problem is that the thread go to 200 instead of 100


Sorry, without the author of the code writing some comments saying what the program is supposed to do,
There are 100s of things the program does not do.  Is one of those 100s of  things what the program should do? Impossible to tell.



yes i understand, i have the same problem, it's not clear