64 624
Assignments Done
99,1%
Successfully Done
In September 2018

Answer to Question #57921 in Java | JSP | JSF for kenya

Question #57921
Here is some data regarding an employee:

name: William
age:25
hourly pay rate: $18.50
office: B
Assign these data items to suitable Java variables, then use the variables and three statements to print these formatted lines of output:

Will is 25 years old
He is in office B
In a 40-hour week, his pay is $740.00
Expert's answer
import java.text.DecimalFormat;

public class Employee {
private String name;
private int age;
private double rate;
private char officeNumber;
private DecimalFormat format;

public Employee() {
format = new DecimalFormat("#0.00");
}

public void employessInfo() {
System.out.println(getName() + " is " + getAge() + " years old");
System.out.println("He is in office " + getOfficeNumber());
System.out.println("In a 40-hour week, his pay is $" + format.format(getRate() * 40));
}

public String getName() {
return name;
}

public int getAge() {
return age;
}

public double getRate() {
return rate;
}

public char getOfficeNumber() {
return officeNumber;
}

public void setName(String name) {
this.name = name;
}

public void setAge(int age) {
this.age = age;
}

public void setRate(double rate) {
this.rate = rate;
}

public void setOfficeNumber(char officeNumber) {
this.officeNumber = officeNumber;
}

public static void main(String[] args) {
Employee e1 = new Employee();
e1.setName("Will");
e1.setAge(25);
e1.setOfficeNumber('B');
e1.setRate(18.50);
e1.employessInfo();

}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions