2

错误:找不到符号(主类第 23 行) myRapidRefund.setDestination(destination);

符号:方法 setDestination(String) 位置:RapidRefund 类型的变量 myRapidRefund

我已经搜索并找不到解决方案。我认为问题出在 get/set 方法中,但我无法弄清楚自从我使用 java 以来已经有一段时间了。非常感谢任何帮助,谢谢!这是代码:

主要应用类:

/*
 *@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;
     }
 }
4

1 回答 1

2

看起来像是 的拼写错误destination

myRapidRefund.setDestination(destination);

与中的签名不匹配RapidRefund

public void setDesination(String destination)

记住:Java 不关心拼写,只要你保持一致!

于 2013-11-10T20:05:01.743 回答