import java.text.*;
public class Employee
{
String firstname;
String lastname;
int id;
double salary;
char grade;
DecimalFormat df = new DecimalFormat("$0.00");
public Employee(String fn,String ln, int id,double sal,char g)
{
firstname = fn;
lastname = ln;
id = id;
salary = sal;
grade = g;
}
public void deposit(double amt)
{
System.out.println("\nAdd more salary by : " + df.format(salary));
if (amt > 0)
salary = salary + amt;
toString();
}
public void display()
{
System.out.println("First Name :" + firstname);
System.out.println("Last Name :" + lastname);
System.out.println("ID :" + id);
System.out.println("Salary :" + salary);
System.out.println("grade :" + grade);
}
//public Employee(String firstname, String lastname, int id, double salary, String grade)
//{
//this.firstname = firstname;
//this.lastname = lastname;
//this.id = id;
//this.salary = salary;
//this.grade = grade;
//}
public String toString()
{
return "First Name : " + firstname +
"Last Name : " + lastname +
"ID : " + id +
"\nSalary : " + df.format(salary) +
"Grade : " + grade;
}
public String getFirstname() { return firstname; }
public String getLastname() { return lastname; }
public int getId() { return id; }
public double getSalary() { return salary;}
public char getGrade() { return grade; }
}
The above code is able to work just that i do not knw hw to made a code to write a random number with a checker to ensure that the number will not be duplicate need some people to explain to me or help me out
public class UseEmployee
{
public static void main (String args[]) throws Exception
{
Employee x = new Employee("Daniel", "Liew", 87, 1200, 'P');
x.display();
x.paycut(100);
x.display();
x.deposit(300);
x.display();
}
}

New Topic/Question
Reply




MultiQuote



|