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
1
Expert's answer
2016-02-19T08:01:00-0500
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();
Comments
Leave a comment