2013-09-25 5 views
0

이 코드를 실행하려고하면 잘못된 값을 반환하고 잘못된 부분을 파악할 수 없습니다. 그것은 catUp에 10을 더한 후에 올바르게 출력되지만 같은 값이 199보다 큰지 확인하기 위해 어떤 이유로 if 문으로 넘어갑니다. 또한 나는 1의 값을 제공하는 upCategory 방법의 끝에 그것을 밖으로 인쇄,하지만 난 주에 그것을 밖으로 인쇄 할 갈 때 그것은 나에게로 간다 3.메서드의 Java 논리 문제

public void upCategory() 
    { 
    double catUp = radioXM.getCurrentStaion(); 
    catUp += 10; 
    System.out.println(catUp); 
    if (catUp > 199.0); 
    { 
     catUp = 1; 
     radioXM.setCurrentStation(catUp); 
     System.out.println(catUp); 
    } 
    radioXM.setCurrentStation(catUp); 
    System.out.println(catUp); 
    } 
public static void main (String [] args) { 
    AutoRadioSystem c = new AutoRadioSystem(); 
    c.selectRadio(); 
    double b = c.getCurrentStation(); 
    System.out.println(b); 

    // this changes the radio to XM 
    c.selectRadio(); 
    double d = c.getCurrentStation(); 
    System.out.println(d); 

    //this is suppose to change the station up by 10 but gives incorrect value 
    c.upCategory(); 
    double f = c.getCurrentStation(); 
    System.out.println(f); 
    } 

추가 코드의 값을 제공 할 때

if (catUp > 199.0); 

자바가 if 문 본문으로 세미콜론을 취급하고아래 중괄호의 블록 : 그것은 ...

public abstract class Radio 
{ 
double currentStation; 

RadioSelectionBar radioSelectionBar; 
public Radio() 
{ 
    this.currentStation = getMin_Station(); 
} 
public abstract double getMax_Station(); 
public abstract double getMin_Station(); 
public abstract double getIncrement(); 
public void up() 
{ 

} 
public void down() 
{ 

} 
public double getCurrentStaion() 
{ 
    return this.currentStation; 
} 
public void setCurrentStation(double freq) 
{ 
    currentStation += freq; 
} 
public void setStation(int buttonNumber, double station) 
{ 
} 
public double getStation(int buttonNumber) 
{ 
    return 0.0; 
} 
public String toString() 
{ 
    String message = ("" + currentStation); 
    return message; 
} 
    public boolean equals (Object o) 
    { 
    if (o == null) 
     return false; 
    if (! (o instanceof Radio)) 
     return false; 
    Radio other = (Radio) o; 
    return this.currentStation == other.currentStation; 
    } 

public class XMRadio extends Radio 
{ 
    private static final double Max_Station = 199; 
    private static final double Min_Station = 1; 
    private static final double Increment = 1; 
    public XMRadio() 
    { 
    } 
    public double getMax_Station() 
    { 
    return this.Max_Station; 
    } 
    public double getMin_Station() 
    { 
    return this.Min_Station; 
    } 
    public double getIncrement() 
    { 
    return this.Increment; 
    } 
    public String toString() 
    { 
    String message = ("XM "+ currentStation); 
    return message; 
    } 
} 

답변

4

이 줄은 문제가은 정상적인 블록이되어 항상 실행됩니다.

if 문에 괄호로 블록을 연결 세미콜론 제거하려면

if (catUp > 199.0)