Write an individualized class I chose
airplain
and you can use theses attributes name, duration, hero, dimension or any thing work for the
airplain
MovieTheater, Car, Book, etc, which we discussed and assigned in class already). It should have at least three attributes, getter and setter methods and a tellAboutSelf method. Additionally, the class must have two custom methods that involve some sort of calculation.To test your class, you also need to write a tester class that creates at least one object based on your custom class and call the tellAboutSelf and the two custom methods on it.
package bmarina;
import java.text.*;
public class EmployeeTester {
public static void main(String[] args) {
Employee emp1 = new Employee(“Jim”, “1234”, “Terre Haute”, “456-5789”);
System.out.println(emp1.tellAboutSelf());
double wage = emp1.wage(40, 10);
System.out.println(wage);
double tax = emp1.tax(400.0, .20);
System.out.println(emp1.tax(400.0, .20));
System.out.println(emp1.tax(emp1.wage(40, 10), .20));
NumberFormat currencyFormat = NumberFormat.getCurrencyInstance();
System.out.println(“Wage is ” + currencyFormat.format(wage));
System.out.println(“Tax is ” +
currencyFormat.format(emp1.tax(emp1.wage(40, 10), .20)));
System.out.println(“Tax is ” + currencyFormat.format(tax));
DecimalFormat decimalFormat = new DecimalFormat(“##,##0.00”);
System.out.println(“Tax is ” + decimalFormat.format(tax));
System.out.println(“Random number ” + decimalFormat.format(999123456.78912));
}
}
Add Comment
Employee New
Posted by Ayman Abuhamdieh at Tuesday, November 12, 2013 3:12:17 PM EST
//Written by Ayman
package bmarina;
public class Employee {
//attributes
private String name;
private String IDNo;
private String address;
private String phoneNo;
//parameterized constructor
public Employee(String newName, String newIDNo, String newAddress,
String newPhoneNo){
setName(newName);
setIDNo(newIDNo);
setAddress(newAddress);
setPhoneNo(newPhoneNo);
}
//wage method
public double wage(double hoursWorked, double ratePerHour) {
double pay = hoursWorked * ratePerHour;
return pay;
}
// tax method, tax rate should be a percentage
public double tax(double aWage, double taxRate){
double taxAmount = aWage * taxRate;
return taxAmount;
}
// setter methods
public void setName(String aName) {
name = aName;
}
public void setIDNo(String anIDNo) {
IDNo = anIDNo;
}
public void setAddress(String anAddress) {
address = anAddress;
}
public void setPhoneNo(String aPhoneNo) {
phoneNo = aPhoneNo;
}
//getter methods
public String getName() {
return name;
}
public String getIDNo() {
return IDNo;
}
public String getAddress() {
return address;
}
public String getPhoneNo() {
return phoneNo;
}
public String tellAboutSelf() {
String info = “Employee name is ” + getName() + “, \nID# is ” + getIDNo()
+”, \naddress is ” + getAddress() + ” \nand phone# is ” + getPhoneNo();
return info;
}
}