我正在处理的问题是我无法弄清楚如何使我的类中的某些值出现,它们只返回为零。我是初学者,所以我对 Java 了解不多,但我必须制作 4 个类或 3 类员工和一个类来输出他们的值。但我无法得到委员会和工会所雇用的价值观。这是代码:
import java.util.Scanner;
// Base or Superclass
class Employee
{
String name;
String department;
double pay;
double hours;
double money;
double mission;
double rate;
double withheld;
double moneyc;
double moneyu;
double sales;
public void inputs()
{
Scanner in = new Scanner(System.in);
System.out.println("Enter your name: ");
name = in.nextLine();
System.out.println("Enter your department: ");
department = in.nextLine();
System.out.println("Enter your pay per hour: ");
pay = in.nextDouble();
System.out.println("Enter how many hours you worked: ");
hours = in.nextDouble();
System.out.println("Enter your rate of commission(0.00): ");
rate = in.nextDouble();
System.out.println("Enter your withheld amount: ");
withheld = in.nextDouble();
System.out.println("Enter your sales amount: ");
sales = in.nextDouble();
money = pay * hours;
}
// Accessor Methods
public String getName()
{
return this.name;
}
public String getDepartment()
{
return this.department;
}
public Double getPay()
{
return this.pay;
}
public Double getHours()
{
return this.hours;
}
public Double getMoney()
{
return this.money;
}
public Double getMission()
{
return this.mission;
}
public Double getRate()
{
return this.rate;
}
public Double getWithheld()
{
return this.withheld;
}
public Double getMoneyc()
{
return this.moneyc;
}
public Double getMoneyu()
{
return this.moneyu;
}
public Double getSales()
{
return this.sales;
}
// Mutator Methods
public void setName(String n)
{
name = n;
}
public void setDepartment(String d)
{
department = d;
}
public void setPay(double p)
{
pay = p;
}
public void setHours(double h)
{
hours = h;
}
public void setMoney(double m)
{
money = m;
}
public void setMission(double mi)
{
mission = mi;
}
public void setRate(double r)
{
rate = r;
}
public void setWithheld(double w)
{
withheld = w;
}
public void setMoneyc(double mc)
{
moneyc = mc;
}
public void setMoneyu(double mu)
{
moneyu = mu;
}
public void setSales(double s)
{
sales = s;
}
}
class Last extends Employee
{
public void dinero()
{
Employee one = new Employee();
one.inputs();
// Union Employee
UnionEmployee three = new UnionEmployee();
three.Syndicate();
// Commission Employee
Commissioned two = new Commissioned();
two.sales();
System.out.println("\n"+ "Name: "+ one.getName());
System.out.println( "Department: "+ one.getDepartment());
System.out.println( "Hours: "+ one.getHours());
System.out.println( "Pay Rate: "+ one.getPay());
System.out.println("Your money is: "+ one.getMoney());
// Commissioned Employee
System.out.println( "\n"+ "Commissioned Employee");
System.out.println("Your money is: "+ one.getMoneyc());
System.out.println( "Your commission is: "+ one.getMission());
System.out.println("Your rate: "+ one.getRate());
// Union employee
System.out.println("\n"+"Union Employee");
System.out.println("Your money is: "+ one.getMoneyu());
System.out.println( "Your withheld is: "+ one.getWithheld());
}
}
// Derived or Subclass
class Commissioned extends Employee
{
public void sales()
{
moneyc = hours * pay;
// Commission
mission = sales * rate;
}
}
// Derived or Subclass
class UnionEmployee extends Employee
{
public void Syndicate()
{
if (hours <= 40) {
moneyu = (hours * pay) - withheld;
} else {
moneyu = (pay * hours * ((hours - 40) * 1.5)) - withheld;
}
}
}
public class WeiTry extends Last
{
public static void main(String[] args)
{
// Output
Last show = new Last();
show.dinero();
}
}