2013-07-18 2 views
0

내가 다루고있는 문제는 내 클래스의 특정 값을 어떻게 0으로 반환하는지 표시하는 방법을 알 수 없다는 것입니다. 저는 초보자이기 때문에 Java에 대해 많이 알지 못하지만 4 가지 클래스 또는 3 가지 유형의 직원과 하나의 클래스를 만들어 값을 출력해야합니다. 그러나 저는위원회와 노동 조합이 보여 주어야 할 가치를 얻을 수 없습니다. 여기에 코드입니다 :자바 : 클래스 문제. Java 초보자

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(); 
    } 
} 
+0

왜 이상 그들을 복사 만 할 수는 정확히'이 태그 javascript'했다? 당신은'javascript'가'java'와 아무런 관련이 없다는 것을 알고 있습니다. – Shawn31313

+2

JS 목록에서 벗어나갑니다. –

+0

오, 미안하지만 나는 자바 초보자입니다. 나는 실제로 자바를 배우는 데 일주일 반 밖에 걸리지 않았다. – PrimeRC

답변

1

나는 당신의 Employee 볼 수있는 유일한 장소의 필드를 설정 얻을라는 방법 안에 inputs()

one의 당신이 one에 만의 inputs 메소드를 호출하기 때문에 값이 채워 UnionEmployee three, inputs과 같은 다른 직원 유형은 절대 호출되지 않으며 해당 필드는 설정되지 않습니다.

다른 직원의 값을 설정하려면 입력 방법을 호출해야합니다.

UnionEmployee three = new UnionEmployee(); 
three.inputs(); 
three.Syndicate(); 

또는

three.setName(one.getName()); 
+0

그래, 그게 아마 내가 특정 출력에 대해 0을 얻고있는 이유는 어떻게 변수를 채울 수 있을까? 아니면 그냥 다른 클래스의 메서드를 호출해야합니까? – PrimeRC

+0

여기에 자신의'inputs' 방법 –

+0

를 호출 @RogelioLoop 출력 이미지 링크입니다 : 그래서에서 three.inputs 부분을 추가해야 http://i756.photobucket.com/albums/xx207/ChaosOrochi/Java_Problem_zps7c9dc5b4.jpg – PrimeRC