如何清除类中的语法标记错误,以便正确编译? [英] How to clear out the syntax token error in the class so it will compile correctly?

查看:208
本文介绍了如何清除类中的语法标记错误,以便正确编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JAVA项目,其中包含启动代码,但在给您的两个类中没有代码.我是JAVA的新手,确实需要帮助.我将代码添加到Treasure类,现在得到:令牌语法错误,删除这些令牌和语法错误,插入;"完成BlockStatements .为什么会出现这些错误?我想念什么?


这是已经存在的Java代码:

I have a JAVA project that has code in it to start but no code in the two classes it gives you. I am new to JAVA and really need help on this. I added my code to the Treasure class and now I am getting: Syntax error on tokens, delete these tokens and Syntax error, insert ";" to complete BlockStatements. Why am I getting these errors? What did I miss?


Here is the already Java code:

package mythical.controllers;

import java.text.NumberFormat;

import mythical.model.Treasure;

/**
 * This class is used to informally test the Treasure class.
 * 	NOTE: This class won't compile until the Treasure class
 * 	has been completed correctly
 * 
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * ~~ DO NOT MODIFY THE CODE INSIDE TreasureDemo ~~
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * 
 * @author	Kwesi Hopkins
 * @version	09/12/2016
 *
 */
public class TreasureDemo {
	private Treasure largeTreasure;
	private Treasure smallTreasure;
	private NumberFormat currencyFormatter;	
	
	/**
	 * Creates a new TreasureDemo object with 2 Treasures
	 */
	public TreasureDemo() {
		this.largeTreasure = new Treasure(105);
		this.smallTreasure = new Treasure(10);
		this.currencyFormatter = NumberFormat.getCurrencyInstance();
	}
	
	/**
	 * This method will print information about each Treasure,
	 * 	have each Treasure be claimed, and print information 
	 * 	about each (newly found) Treasure
	 */
	public void testTreasure() {
		this.describeTreasure2("New large treasure", this.largeTreasure, 105, 25452.0);
		
		this.describeTreasure2("New small treasure", this.smallTreasure, 10, 2424.0);
		
		System.out.println();
		System.out.println("~~~~ The treasures get found ~~~~");
		this.largeTreasure.getsFound();
		this.smallTreasure.getsFound();
		
		System.out.println();
		this.describeTreasure2("Found large treasure", this.largeTreasure, 0, 0.0);
		
		this.describeTreasure2("Found small treasure", this.smallTreasure, 0, 0.0);
		System.out.println();
	}
	
	/**
	 * Helper method that accepts a message and the expected value
	 * 
	 * @param	message			The message to be displayed
	 * @param	theTreasure		The treasure to be described
	 * @param	expectedWeight	The treasure's expected weight
	 * @param	expectedValue	The treasure's expected value
	 */
	public void describeTreasure2(String message, Treasure theTreasure, 
			int expectedWeight, double expectedValue) {
		System.out.println(message);
		System.out.println("\tExpected weight: \t" + expectedWeight);
		System.out.println("\tActual weight: \t\t" + theTreasure.getWeight());	
		
		System.out.println("\tExpected value: \t" + this.currencyFormatter.format(expectedValue));
		System.out.println("\tActual value: \t\t" + this.currencyFormatter.format(theTreasure.getValue()));
		System.out.println();
	}
}



这是课程:



Here is the Class:

package mythical.model;

public class Treasure {
	
		private int theTreasure;
		    private int largeTreasure;
		    private int smallTreasure;
		
		 public Treasure() {
		        this.theTreasure = 0;
		        this.largeTreasure = 0;
		        this.smallTreasure = 0;
		        
		        
		    }
		    
		    public Treasure(int largeTreasure){
		        this.largeTreasure = largeTreasure;
		        
		    }
		    
		    public void getLargeTreasure(){
		        this.largeTreasure = this.largeTreasure + 105;
		    }
		    
		    public void getSmallTreasure(){
		        this.smallTreasure = this.smallTreasure + 10;
		    }
		        
		    public int getWeight(){
		        return this.largeTreasure;
		    }
		    
		    public double getValue(){
		        return this.largeTreasure * 242.40;
		    }
		                
		    public int getsFound(){
		        return this.largeTreasure;

		    }

		    public int expectedWeight(){
		        return this.largeTreasure + 105;
		    }
		    
		}
	}
}



请帮帮我.

我尝试过的事情:

我尝试了不同的方法来启动构造函数,但是没有运气. JAVA的新手.



Please help me.

What I have tried:

I have tried different ways to start the constructor but no luck. New to JAVA.

推荐答案

从此处开始:
为您的类提供构造器 [ Java中的构造方法-Javatpoint [ ^ ]
Java入门指南-类构造函数 [
Start here:
Providing Constructors for Your Classes[^]
Constructor in Java - Javatpoint[^]
Java For Complete Beginners - class constructor[^]

public class Treasure {
	int tres;
	public Treasure(int countOftres){
		tres = countOftres;
	}
}


我们不做您的作业:它的设置是有原因的.在这里,您可以考虑自己被告知的内容,并尝试理解它.也可以在那里帮助您的导师识别您的弱点,并将更多的注意力放在补救措施上.

因此,从现在开始重新阅读您的课程笔记和/或这本书.您需要的信息就在那里-通过自己解决问题,比没有上下文的解决方案",您将学到更好的基础知识.
自己尝试,您可能会发现它并不像您想的那么难!

如果您遇到特定问题,请询问此问题,我们将尽最大努力为您提供帮助.但是我们不会为您做所有这一切!
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

So start by re-reading your course notes and / or the book so far. The information you need will be there - and you will learn this basic stuff a lot better by working it out for yourself than by being given a "solution" with no context.
Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren''t going to do it all for you!


我发现我的代码中做错了什么.这是更正的代码.

I found out what I did wrong within my code. Here is the corrected code.

public class Treasure {
	private int theTreasure;
    private int largeTreasure;
    private int smallTreasure;

public Treasure(){
    this.theTreasure = 0;
    this.largeTreasure = 0;
    this.smallTreasure = 0;
}
public Treasure(int largeTreasure){
    this.largeTreasure = largeTreasure;
}
public void getLargeTreasure(){
    this.largeTreasure = this.largeTreasure + 105;
}
public void getSmallTreasure(){
    this.smallTreasure = this.smallTreasure + 10;
}
public int getWeight(){
    return this.largeTreasure;
}
public double getValue(){
    return this.largeTreasure * 242.40;
}
public int getsFound(){
    return this.largeTreasure;
}
public int expectedWeight(){
    return this.largeTreasure + 105;
}

}


这篇关于如何清除类中的语法标记错误,以便正确编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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