对于类型妖精,该方法未定义。为什么? [英] The method is undefined for the type leprechaun. Why?

查看:96
本文介绍了对于类型妖精,该方法未定义。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个Java项目并且我收到此错误:



方法findTreasure(Treasure)未定义Leprechaun类型。



我试图找出为什么我在我的代码中获得它时会得到这个?有些人可以为我看看这个,让我知道我在哪里蠢蠢欲动?这是我的代码:



  package  mythical.controllers; 

import java.text.NumberFormat;

import mythical.model.Leprechaun;
import mythical.model.Treasure;

/ * *
*这是非正式测试应用程序的驱动程序
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~
* ~~不要修改TestDriver里面的代码~~
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
*
* @author Kwesi Hopkins
* @version 9/12/2016
*
* /

public class LeprechaunDemo {
私人 Treasure treasurePail;
私人宝藏宝藏;
私人 Leprechaun patti;
private NumberFormat currencyFormatter;

/ * *
*用2 Treasure $ b创建一个新的LeprechaunDemo对象$ b *对象和Leprechaun的实例
* /

public LeprechaunDemo(){
.treasurePail = new Treasure( 48 );
.treasureChest = 宝藏( 250 );
this .patti = new Leprechaun( 100 0 );
this .currencyFormatter = NumberFormat.getCurrencyInstance();
}

/ * *
*运行一组测试对于妖精的行为
* /

public void testLeprechaun( ){
this .describeLeprechaun( Patti's初始值 100 00 );

System.out.println( Patti说:);
System.out.println( \tExpect:\ t \top o't the mornin到你!\);
System.out.println( \tActual:\t\t\ + .patti.getGreeting()+ \ );
System.out.println();

this .patti.findTreasure( this .treasurePail);
.describeLeprechaun( Patti之后的值找到小宝贝 11735 2 );
System.out.println( 找到小宝贝后的价值:);
System.out.println( \tExpected:\t $ 0.00);
System.out.println( \tActual:\t\t + this .currencyFormatter.format( this .treasurePail.getValue()));
System.out.println();

this .patti.meetPerson();
.describeLeprechaun( Patti之后的值赠送第一次 7627 88 );

this .patti.meetPerson();
.describeLeprechaun( Patti之后的值赠送第二次 4958 122 );

this .patti.findTreasure( this .treasureChest);
.describeLeprechaun( Patti之后的值找到大宝 65558 122 );
System.out.println( 找到大宝藏后的价值:);
System.out.println( \tExpected:\t $ 0.00);
System.out.println( \tActual:\t\t + this .currencyFormatter.format( this .treasureChest.getValue()));
}

/ * *
*接受a的助手方法消息和预期值
*
* @param消息要显示的消息
* @param expectedValue预期值
* /

public void describeLeprechaun( String 消息, double expectedValue){
System.out.println(message);
System.out.println( \tExpected:\t + .currencyFormatter.format(expectedValue));
System.out.println( \tActual:\t + this .currencyFormatter.format( this .patti.getAssetValue()));
System.out.println();
}
}





以下是班级代码:



  package  mythical.model; 

public class Leprechaun {
private int treasurePail;
private int treasureChest;
private double patti;

public Leprechaun(){

this .treasurePail = 0 ;
.treasureChest = 0 ;
.patti = 0 ;
}

public Leprechaun( double patti){
this .patti = patti;
}

public void chooseTreasurePail(){

.treasurePail = .treasurePail + 48 ;
}

public void chooseTreasureChest(){
.treasureChest = .treasureChest + 250 ;
}

public void choosePatti(){
this .patti = this .patti + 100 00 ;
}

public String getGreeting(){
返回 顶部o到ma! ;
}

public double getAssetValue(){
return this .patti;
}

public int meetPerson(){
return .treasurePail;
}
}





我的尝试:



我上下搜索我的代码以找出我的错误。

解决方案

0.00);
System.out.println( \tActual:\t\t + this .currencyFormatter.format( this .treasurePail.getValue()));
System。 out.println();

this .patti.meetPerson();
这个 .describeLeprechaun( Patti在第一次赠送后的价值 7627 88 );

this .patti.meetPerson();
this .describeLeprechaun( 第二次赠送后的Patti值 4958 122 );

this .patti.findTreasure( this .treasureChest);
.describeLeprechaun( Patti之后的值找到大宝 65558 122 );
System.out.println( 找到大宝藏后的价值:);
System.out.println( \tExpected:\t


0.00\" );
System.out.println( \tActual:\t\t + this .currencyFormatter.format( this .treasureChest.getValue()));
}

/ * *
*接受a的助手方法消息和预期值
*
* @param消息要显示的消息
* @param expectedValue预期值
* /

public void describeLeprechaun( String 消息, double expectedValue){
System.out.println(message);
System.out.println( \tExpected:\t + .currencyFormatter.format(expectedValue));
System.out.println( \tActual:\t + this .currencyFormatter.format( this .patti.getAssetValue()));
System.out.println();
}
}





以下是班级代码:



  package  mythical.model; 

public class Leprechaun {
private int treasurePail;
private int treasureChest;
private double patti;

public Leprechaun(){

this .treasurePail = 0 ;
.treasureChest = 0 ;
.patti = 0 ;
}

public Leprechaun( double patti){
this .patti = patti;
}

public void chooseTreasurePail(){

.treasurePail = .treasurePail + 48 ;
}

public void chooseTreasureChest(){
.treasureChest = .treasureChest + 250 ;
}

public void choosePatti(){
this .patti = this .patti + 100 00 ;
}

public String getGreeting(){
返回 顶部o到ma! ;
}

public double getAssetValue(){
return this .patti;
}

public int meetPerson(){
return .treasurePail;
}
}





我的尝试:



我上下搜索我的代码以找出我的错误。


你的错误非常清楚。 Leprechaun不包含名为findTreasure的方法。在您的妖精课程中,您有以下方法



  public   void  chooseTreasurePail 
public void chooseTreasureChest
public void choosePatti
public 字符串 getGreeting
public double getAssetValue
public int meetPerson







你的Leprechaun课程中没有findTreasure方法。如果您要添加



  public   void  findTreasure(Treasure yourparam)







然后你的错误应该去了程。


I have a Java project I am working on and I get this error:

The method findTreasure(Treasure) is undefined for the type Leprechaun.

I am trying to find out why am I getting this when I do have it in my code? Can some please look this over for me and let me know where I goofed? Here is my code:

package mythical.controllers;

import java.text.NumberFormat;

import mythical.model.Leprechaun;
import mythical.model.Treasure;

/**
 * This is the driver for the informal test application
 * 
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * ~~ DO NOT MODIFY THE CODE INSIDE TestDriver ~~
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * 
 * @author	Kwesi Hopkins
 * @version	9/12/2016
 *
 */
public class LeprechaunDemo {
	private Treasure treasurePail;
	private Treasure treasureChest;
	private Leprechaun patti;
	private NumberFormat currencyFormatter;

	/**
	 * Creates a new LeprechaunDemo object with 2 Treasure
	 * 	objects and an instance of a Leprechaun
	 */
	public LeprechaunDemo() {
		this.treasurePail = new Treasure(48);
		this.treasureChest = new Treasure(250);
		this.patti = new Leprechaun(100.0);
		this.currencyFormatter = NumberFormat.getCurrencyInstance();
	}
	
	/**
	 * Runs a set of tests for the Leprechaun's behavior
	 */
	public void testLeprechaun() {
		this.describeLeprechaun("Patti's initial value", 100.00);
		
		System.out.println("Patti says:");
		System.out.println("\tExpected:\t\"Top o' the mornin to ya!\"");
		System.out.println("\tActual:\t\t\"" + this.patti.getGreeting() + "\"");
		System.out.println();
		
		this.patti.findTreasure(this.treasurePail);
		this.describeLeprechaun("Patti's value after finding the small treasure", 11735.2);
		System.out.println("Small treasure's value after being found:");
		System.out.println("\tExpected:\t$0.00");
		System.out.println("\tActual:\t\t" + this.currencyFormatter.format(this.treasurePail.getValue()));
		System.out.println();
		
		this.patti.meetPerson();
		this.describeLeprechaun("Patti's value after giving away first time", 7627.88);
		
		this.patti.meetPerson();
		this.describeLeprechaun("Patti's value after giving away second time", 4958.122);
		
		this.patti.findTreasure(this.treasureChest);
		this.describeLeprechaun("Patti's value after finding the large treasure", 65558.122);
		System.out.println("Large treasure's value after being found:");
		System.out.println("\tExpected:\t$0.00");
		System.out.println("\tActual:\t\t" + this.currencyFormatter.format(this.treasureChest.getValue()));
	}
	
	/**
	 * Helper method that accepts a message and the expected value
	 * 
	 * @param	message			The message to be displayed
	 * @param	expectedValue	The expected value
	 */
	public void describeLeprechaun(String message, double expectedValue) {
		System.out.println(message);
		System.out.println("\tExpected: \t" + this.currencyFormatter.format(expectedValue));
		System.out.println("\tActual: \t" + this.currencyFormatter.format(this.patti.getAssetValue()));
		System.out.println();
	}
}



Here is the class code:

package mythical.model;

public class Leprechaun{
    private int treasurePail;
    private int treasureChest;
    private double patti;

    public Leprechaun(){
        
        this.treasurePail = 0; 
        this.treasureChest = 0; 
        this.patti = 0;
    }
    
    public Leprechaun(double patti){
        this.patti = patti;
    }
    
    public void chooseTreasurePail(){
        
        this.treasurePail = this.treasurePail + 48;
    }
    
    public void chooseTreasureChest(){
        this.treasureChest = this.treasureChest + 250; 
    }
    
    public void choosePatti(){
        this.patti = this.patti + 100.00;
    }

    public String getGreeting() {
    	return "Top o' the mornin to ya!";
    }
    
    public double getAssetValue(){
    	return this.patti;
    }

    public int meetPerson(){
    	return this.treasurePail;
    }
}



What I have tried:

I have searched my code up and down to find my mistakes.

解决方案

0.00"); System.out.println("\tActual:\t\t" + this.currencyFormatter.format(this.treasurePail.getValue())); System.out.println(); this.patti.meetPerson(); this.describeLeprechaun("Patti's value after giving away first time", 7627.88); this.patti.meetPerson(); this.describeLeprechaun("Patti's value after giving away second time", 4958.122); this.patti.findTreasure(this.treasureChest); this.describeLeprechaun("Patti's value after finding the large treasure", 65558.122); System.out.println("Large treasure's value after being found:"); System.out.println("\tExpected:\t


0.00"); System.out.println("\tActual:\t\t" + this.currencyFormatter.format(this.treasureChest.getValue())); } /** * Helper method that accepts a message and the expected value * * @param message The message to be displayed * @param expectedValue The expected value */ public void describeLeprechaun(String message, double expectedValue) { System.out.println(message); System.out.println("\tExpected: \t" + this.currencyFormatter.format(expectedValue)); System.out.println("\tActual: \t" + this.currencyFormatter.format(this.patti.getAssetValue())); System.out.println(); } }



Here is the class code:

package mythical.model;

public class Leprechaun{
    private int treasurePail;
    private int treasureChest;
    private double patti;

    public Leprechaun(){
        
        this.treasurePail = 0; 
        this.treasureChest = 0; 
        this.patti = 0;
    }
    
    public Leprechaun(double patti){
        this.patti = patti;
    }
    
    public void chooseTreasurePail(){
        
        this.treasurePail = this.treasurePail + 48;
    }
    
    public void chooseTreasureChest(){
        this.treasureChest = this.treasureChest + 250; 
    }
    
    public void choosePatti(){
        this.patti = this.patti + 100.00;
    }

    public String getGreeting() {
    	return "Top o' the mornin to ya!";
    }
    
    public double getAssetValue(){
    	return this.patti;
    }

    public int meetPerson(){
    	return this.treasurePail;
    }
}



What I have tried:

I have searched my code up and down to find my mistakes.


Your error is pretty clear. Leprechaun does not contain a method called findTreasure. In your leprechaun class you have the following methods

public void chooseTreasurePail
   public void chooseTreasureChest
   public void choosePatti
   public String getGreeting
   public double getAssetValue
   public int meetPerson




There is no findTreasure method in your Leprechaun class. If you were to add

public void findTreasure(Treasure yourparam)




Then your error should go away.


这篇关于对于类型妖精,该方法未定义。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆