申し訳ありませんが、プログラミングは初めてで、プログラムのコーディングに問題があります。元のプログラムは次のとおりです。
import java.io.*;
import java.io.IOException;
import java.io.InputStreamReader;
class buildABoat{
String boatName; // Boat name
void buildABoat(){
String BoatName;
}
void nameTheBoat() {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("\n\nWhat should we name this vessel? \n\n");
this.boatName = br.readLine();
System.out.println("\n\nThe " + boatName + " is ready to sail!\n");
}
catch (IOException e) {
}
}
}
class proj1{
public static void main(String[] arg){
buildABoat boat1;
buildABoat boat2;
buildABoat boat3;
buildABoat boat4;
buildABoat boat5;
boat1 = new buildABoat();
boat2 = new buildABoat();
boat3 = new buildABoat();
boat4 = new buildABoat();
boat5 = new buildABoat();
boat1.nameTheBoat();
boat2.nameTheBoat();
boat3.nameTheBoat();
boat4.nameTheBoat();
boat5.nameTheBoat();
System.out.println("(Press ENTER to exit)");
try {
System.in.read();
}
catch (IOException e) {
return;
}
}
}
これにより、次のようになります。
What should we name this vessel?
Enterprise
The Enterprise is ready to sail!
What should we name this vessel?
Columbia
The Columbia is ready to sail!
What should we name this vessel?
Challenger
The Challenger is ready to sail!
What should we name this vessel?
Atlantis
The Atlantis is ready to sail!
What should we name this vessel?
Endeavor
The Endeavor is ready to sail!
(Press ENTER to exit)
これを次のように変更しようとしました。
import java.io.*;
import java.io.IOException;
import java.io.InputStreamReader;
class buildABoat{
String boatName; // Boat name
void buildABoat(){
String BoatName;
}
void nameTheBoat() {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("\n\nWhat should we name this vessel? \n\n");
this.boatName = br.readLine();
System.out.println("\n\nThe " + boatName + " is ready to sail!\n");
}
catch (IOException e) {
}
}
}
class proj1{
public static void main(String[] arg){
Boat[] boat;
boat = new Boat[5];
for(int i = 0; i <= Boat.Length; i++){
nameTheBoat();
}
System.out.println("(Press ENTER to exit)");
try {
System.in.read();
}
catch (IOException e) {
return;
}
}
}
もちろん、これにより次のエラーが発生します。
proj1.java:71: error: cannot find symbol
for(int i = 0; i <= Boat.Length; i++){
^
symbol: variable Length
location: class Boat
proj1.java:73: error: cannot find symbol
nameTheBoat();
^
symbol: method nameTheBoat()
location: class proj1
2 errors
新しいプログラムには何が欠けていますか?