我正在尝试编译我的代码,但收到以下错误:
Project3.java:228: error: cannot find symbol
tokens[k] = removeCharAt(0, tokens[k]);
^
symbol: method removeCharAt(int,String)
location: class Project3
1 error
我不知道如何申请removeCharAt
,这是我的代码:
import java.io.IOException;
/****************************************************************************************************************************************************
Boat Class
by: Joseph King
The Boat class is a superclass for the Raceboat and SailBoat classes. The class is composed of the following:
The boat name
A boolean speed variable
A method to name the boat
A method to launch the boat and print the name
An abstract method to go faster
A method to increase speed
An abstract method to go slower
A method to decrease speed
An abstract method to indicate the boat's speed state
****************************************************************************************************************************************************/
abstract class Boat{
String boatName = (" ");
boolean addSpeed = false;
void christenBoat(String name){
boatName = name;
}
void launchBoat(){
System.out.println("The " + boatName + " is ready to launch...\n");
}
public abstract void goFast();
void increaseSpeed(){
addSpeed = true;
}
public abstract void goSlow();
void decreaseSpeed(){
addSpeed = false;
}
public abstract void whatIsBoatState();
}
/****************************************************************************************************************************************************
SailBoat Class
by: Joseph King
The SailBoat class is a subclass for the Boat Class. The class modifies the Boat Class as follows:
The go fast method indicates that sail boats go faster by raising the main sail
The go slow method indicates that sail boats go slower by lowering the main sail
The final method checks if the sail boat is going fast or slow and indicates the appropriate message
****************************************************************************************************************************************************/
class SailBoat extends Boat{
public void goFast(){
System.out.println("The " + boatName + " is hoisting the main!");
addSpeed = true;
}
public void goSlow(){
System.out.println("The " + boatName + " is lowering the sail!");
addSpeed = false;
}
public void whatIsBoatState(){
if(addSpeed){
System.out.println("\tthe sail is up, ahead full!\n");
}else{
System.out.println("\tbut the sail is down, hoist the main!\n");
}
}
}
/****************************************************************************************************************************************************
RaceBoat Class
by: Joseph King
The RaceBoat class is a subclass for the Boat Class. The class modifies the Boat Class as follows:
The go fast method indicates that race boats go faster by increasing the throttle
The go slow method indicates that race boats go slower by decreasing the throttle
The final method checks if the race boat is going fast or slow and indicates the appropriate message
****************************************************************************************************************************************************/
class RaceBoat extends Boat{
public void goFast(){
System.out.println("The " + boatName + " is throttling forward!");
addSpeed = true;
}
public void goSlow(){
System.out.println("The " + boatName + " is throttling backward!");
addSpeed = false;
}
public void whatIsBoatState(){
if(addSpeed){
System.out.println("\tshe is at full throttle, ahead full!\n");
}else{
System.out.println("\tbut the throttle is down, increase throttle!\n");
}
}
}
/****************************************************************************************************************************************************
Project3 Class
by: Joseph King
This class contains the main class for the program, the algorithm is as follows:
Create references for the boat array, characters for the first and second letter and an index
The array is then created
The program then checks to ensure if any args parameters were supplied at the command line
If not, it prints a statement and terminates the program
If so the program continues and enters a loop which
Isolates the first letter in the args parameter and ensures it is a capital letter
If a 'B', 'C' or 'N' a race boat is created
If not a sail boat is created
It then isolates the second letter in the args parameter and ensures it is a capital letter
If an 'A' or an 'E' the boat increases it speed
If not it decreases its speed
The program then prints out the name and state of the boat and goes back to the beginning of the loop until all args parameters are processed
Once the loop is completed the program ends
****************************************************************************************************************************************************/
class Project3{
public static void main(String[] args){
System.out.println("\n");
Boat[] boatArray;
String result = null;
char firstChar;
char firstLetter;
char secondLetter;
int i;
boatArray = new Boat[args.length];
if(args.length > 0){
for(i = 0 ; i < args.length ; i++){
String delimiters = "[ ]";
int limit = 0;
String[]tokens = args[i].split(delimiters, limit);
for( int k = 0 ; k < tokens.length ; ++k ){
firstChar = tokens[k].charAt(0);
if(firstChar == ' '){
break;
}else{
if(Character.isUpperCase(firstChar)){
break;
}else{
firstChar = Character.toUpperCase(firstChar);
tokens[k] = removeCharAt(tokens[k], 0);
tokens[k] = firstChar + tokens[k];
}
result = result + tokens[k];
if( k != tokens.length - 1 ){
break;
}else{
result = result.trim();
args[i] = result;
result = null;
}
}
}
// firstLetter = Character.toUpperCase(args[i].charAt(0));
firstLetter = args[i].charAt(0);
if((firstLetter == 'B') || (firstLetter == 'C') || (firstLetter == 'N')){
boatArray[i] = new RaceBoat();
boatArray[i].christenBoat(args[i]);
}else{
boatArray[i] = new SailBoat();
boatArray[i].christenBoat(args[i]);
}
secondLetter = Character.toUpperCase(args[i].charAt(1));
if((secondLetter == 'A') || (secondLetter == 'E')){
boatArray[i].increaseSpeed();
}else{
boatArray[i].decreaseSpeed();
}
}
for(i = 0 ; i < args.length ; i++){
boatArray[i].launchBoat();
boatArray[i].whatIsBoatState();
}
}else{
System.out.println("\nOops... you forgot to enter ship names!\n\n\nPlease try again!");
}
System.out.println("\n\n(press ENTER to exit)\n\n");
try{
System.in.read();
} catch(IOException e){
return;
}
}
}
有人可以指出我缺少什么吗?