schwierigkeit beim atributtwahl

sahra

Mitglied
hallo leute,

ich weiss nicht was genau diese 3. und 6. punkte besagen und wie ich das implementieren soll. habt ihr ideen?

A Worker has the attributes
1. a name
2. a salary
3. a unique taxNumber – this number should depend on the existence of other workers no matter whether they are still at work or retired and no matter to which firm they belong to. So the first worker gets number 1, the second worker 2 ... in order to count all the workers, you must store the amount of created workers in the additional attribute amount
4. amount of all workers
5. a salaryRaise in percent, is the same for all workers due to the inflation factor
6. the actualNumber of workers – includes the number of actual workers (which are not retired) and work in any arbitrary firm


ich waere euch wirklich sehr dankbar
sahra
 
Zuletzt bearbeitet:
Steht das nicht in Nr. 3 erklärt?
Du solltest dir in einer Variable merken wie viele Worker es bereits gibt, damit du beimanlegen eines neuen weisst welche WorkerNummer dieser bekommen muss. Es soll ja aufsteigend ablaufen.
 
Zu 3 und 6:
Java:
class Worker
{
    private static int numberOfWorkers=0;
    private static int numberOfRetiredWorkers=0;

    private int taxNumber;
    private boolean isRetired;

    public Worker()
    {
         this.taxNumber=(++numberOfWorkers);
    }

    public void setRetired(boolean retire)
    {
         if(isRetired == retire)
             return;
         isRetired=retire;
         numberOfRetiredWorkers+=retire?1:-1;
    }
    
//    .......
 

Neue Themen


Zurück
Oben