2013-11-10 5 views
2

ошибка: не найден символ (строка 23 основного класса) myRapidRefund.setDestination (destination);Ошибка: не удается найти символ (java)

символ: метод setDestination (String) местоположение: переменная myRapidRefund типа RapidRefund

Я искал и не смог найти решение. Я предполагаю, что проблема заключается в методе get/set, но я не могу понять, что прошло некоторое время с тех пор, как я использовал java. Любая помощь очень благодарна спасибо! Вот код:

Main App класс:

/* 
*@author k.Donohoe 
*4th Nov 2013 
*RapidRefundApp.java 
*/ 

import javax.swing.JOptionPane; 
public class RapidRefundApp{ 
    public static void main(String args[]){ 
     //declare variables 
     String location, destination; 
     int cash; 
     double fare; 

     //declare & Create objects 
     RapidRefund myRapidRefund = new RapidRefund(); 

     //input 
     location = JOptionPane.showInputDialog(null,"Please enter your current location"); 
     myRapidRefund.setLocation(location); 

     destination = JOptionPane.showInputDialog(null,"Please enter your destination"); 
     myRapidRefund.setDestination(destination); 

     cash = Integer.parseInt(JOptionPane.showInputDialog(null,"How much change do you have?")); 
     myRapidRefund.setCash(cash); 

     //process 
     myRapidRefund.compute(); 

     //output 
     fare = myRapidRefund.getFare(); 
     if(fare==-1){ 
      JOptionPane.showMessageDialog(null,"Sorry, you have entered an invalid day, please try again"); 
     } 
     else{ 
      JOptionPane.showMessageDialog(null,"The cost of the ticket is "+fare); 
     } 
    } 
} 

инстанциируемый Класс:

/* 
*@author K.Donohoe 
*4th Nov 2013 
*RapidRefund.java 
*/ 

public class RapidRefund{ 
    //declare data members 
    private String location, destination; 
    private int cash; 
    private double fare; 

    //constructor 
    public RapidRefund(){ 
     location = " "; 
     destination = " "; 
     cash = 0; 
     fare = 0.0; 
    } 

    //set method(s) 
    public void setLocation(String location){ 
     this.location = location; 
    } 

    public void setDesination(String destination){ 
     this.destination = destination; 
    } 

    public void setCash(int cash){ 
     this.cash = cash; 
    } 

    //compute method 
    public void compute(){ 
     if(location.equals("IFSC")||location.equals("Stephens Green")||location.equals("O'Connell Street")||location.equals("Dublin Castle")){ 
      if(destination.equals("Powerscourt")){ 
       fare = 2.95; 
      } 
      else if(destination.equals("Ikea")){ 
       fare = 2.40; 
      } 
      else if(destination.equals("Phoenix Park")){ 
       fare = 2.15; 
      } 
      else if(destination.equals("Howth")){ 
       fare = 2.95; 
      } 
      else{ 
       fare= -1; 
      } 
     } 
     else{ 
      fare = -1; 
     } 
    } 

    //get method(s) 
    public double getFare(){ 
     return fare; 
    } 
} 
+1

Благодарим вас за исправление на ваш вопрос. 1 + голосование по вопросу и ответ Макото. –

ответ

2

Похоже орфографические ошибки в destination.

myRapidRefund.setDestination(destination); 

не соответствует подписи в RapidRefund:

public void setDesination(String destination) 

Помните: Java не заботится о правописании, до тех пор, пока вы последовательны!

+0

Плохо, спасибо! – user2976972

Смежные вопросы