我一直收到错误
错误:找不到符号案例1:System.out.println(myCar [0]);
我正在尝试创建一个基于菜单的应用程序,该程序将为3个子类创建5个超读初始数据实例的数组。 我希望这能够显示不同的车号,用户可以输入他们想要的车号。然后程序应显示该车内保存的信息。
我想输出我为此5个实例中的每一个设置的详细信息。
public class Test
{
int CarNo;
static Scanner keyboard=new Scanner (System.in);
public static void main(String[] args)
{
Ford myFord = new Ford ("AA1B2DD", "A", 1.1, 2.1, 3.1, 43.4, 9, 10.2);
Ford myFord1 = new Ford ("AA1B2DD", "B", 1.1, 2.1, 3.1, 43.4, 9, 10.2);
BMW myBMW = new BMW ("AA1B2DD", "C", 1.1, 2.1, 3.1, 43.4, 5.0, 100);
BMW myBMW1 = new BMW ("AA1B2DD", "D", 1.1, 2.1, 3.1, 43.4, 5.0, 100);
Merc myMerc = new Marquee ("AA1B2DD", "E", 1.1, 2.1, 3.1, 43.4, 5.0, 9, "wood");
Car[] myCar = new Car [5];
myCar[0]=myFord;
myCar[1]=myFord1;
myCar[2]=myBMW;
myCar[3]=myBMW1;
myCar[4]=myMerc;
displayMenu();
}
public static void displayMenu()
{
System.out.println("Please select Which type of Car\n\n");
for (int count =0; count <5; count++)
{
System.out.println("Car option number"+ "[" + (count +1) + "] ");
}
System.out.println("\nEnter The Car Number you want");
int CarNo=keyboard.nextInt();
System.out.print("\n");
if (CarNo <1 || CarNo >5)
{
System.out.println("Please enter a vaild Car nummber");
}
else
{
switch(CarNo)
{
case 1: System.out.println(myCar[0]);
break;
case 2: System.out.println(myCar[0]);
break;
case 3: System.out.println(myCar[0]);
break;
case 4: System.out.println(myCar[0]);
break;
case 5: System.out.println(myCar[0]);
break;
}
}
}
}
答案 0 :(得分:1)
require(ggplot2)
te = structure(list(lat = c(33.7399, 32.8571, 50.2214, 36.96263, 33.5835,
33.54557, 47.76147, 48, 59.40289, 35.93411, 32.87962, 38.3241,
50.03844, 37.44, 50.07774, 50.26668, 36.5944), lng = c(-118.37608,
-117.25746, -5.3865, -122.00809, -117.86159, -117.79805, -124.45055,
-126, -146.35157, -122.931472, -117.25285, -123.07331, -5.26339,
25.4, -5.709894, -3.86828, -121.96201)), .Names = c("lat", "lng"
), class = "data.frame", row.names = c(NA, -17L))
all_states = map_data("world")
# world version:
wp = ggplot() +
geom_polygon(data = all_states, aes(x = long, y = lat, group = group), colour = "gray",
fill = "gray") +
coord_cartesian(ylim = c(0, 80), xlim = c(-155, 45)) +
geom_point(data = te, aes(x = lng, y = lat), color = "blue", size = 5,alpha = 0.6)
print(wp)
#states plot
sp = ggplot() +
geom_polygon(data = all_states, aes(x = long, y = lat, group = group), colour = "gray", fill = "gray") +
coord_cartesian(ylim = c(30, 52), xlim = c(-128, -114)) +
geom_point(data = te, aes(x = lng, y = lat), color = "blue", size = 5, alpha = 0.6)
print(sp)
方法中看不到myCar
变量。尝试将其作为参数传递:
displayMenu()
此外,@ ryekayo的建议将为您提供准确的结果。
还要确保public static void displayMenu(Car[] myCar)
类具有Car
方法才能打印。