Hye..Anybody can help me? I need some help here..
Below is program 1 (main program)

import java.util.*;
public class Staff
{
public double weeklyIncome, monthlyIncome;
public String name, staffId;

[B]/*how to code the input method to read the staff name,
staff id and weekly salary from a keyboard?*/[/B]

}


//Program 1
public class Salary
{
public static void main(String[]arg)
{
Staff[]staff = new Staff[12];
Staff data=new Staff();
data.input(staff);
data.calculateMonthlyIncome(staff);
double max=data.maximum(staff);
}
}

Some tips?
Can anybody show me the some examples? :)

thank you

Recommended Answers

All 5 Replies

why not use a constructor? EDIT: LINK

Can you show me how to do it?
I stil blur on this part. Sorry.

did you read the link?

class myClass{//demonstration class
    double var;//variable for demonstration class
    public myClass(){//this is a constructor
        var=3.1415926535;//set value for var
    }
    public myClass(double d){//this is a constructor with an argument
        var = d;//set the variable to parameter value
    }
    public void setVar(double d){//this is a method known as a setter
        var = d;//set the variable to the parameter value
    }
    public double getVar(){//this is a method known as a getter
        return var;//return the value of the value
    }
    public double plaintMethod(){//this is just a plain method
        return var*37;//return stuff
    }
}

i still recommend you read THIS LINK

I trust that you already have created the class: Staff. It should be like what sciwizeh has suggested.
This is an example on how to read from the keyboard:

Staff [] staff = Staff[12] //this is an ARRAY. It is not null, but these are: staff[0], staff[1], ...
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));

staff[0] = new Staff(); //staff[0] IS a Staff object.

String name =  keyboard.readLine(); //reads from the keyboard
staff[0].setName(name);
//read the rest of the elements that Staff should have

Use a for loop for the rest of the elements of the array

wow.. thank you for that example..

@sciwizeh , tq too.. nice help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.