您需要检查用户输入的四个参数 是空白的,所以你会像以前一样做四次。
识别用户是否按下
<enter>
您编写了一个JAVA程序,可以创建一个包含四个CD对象的程序 实例变量,以及可以帮助您的CDException.java类 验证此输入。到目前为止,你一直在使用我的这些课程 司机班。现在是时候创建一个真正的驱动程序类了 这将实现CD对象的ArrayList。这是一个列表 最新计划的要求
- 从用户
中读取艺术家姓名- 从用户
中读取相册名称- 阅读库存中的商品数量
- 阅读相册的价格
您的程序应继续从用户读取CD信息,直到用户对所有字段的所有条目都为空。然后,您的程序将打印列表中输入的所有“有效”CD 用户。
我一直收到这样的错误
CDStore.java:12: error: cannot find symbol
Disk d;
^
symbol: class Disk
location: class CDStore
CDStore.java:61: error: cannot find symbol
catch(CDException cde){
^
symbol: class CDException
location: class CDStore
CDStore.java:67: error: cannot find symbol
for(int i = 0; i < CDShelf.length( ); i++){
^
symbol: method length()
location: variable CDShelf of type ArrayList
CDStore.java:68: error: cannot find symbol
d = (Disk)(CD.get(i));
^
symbol: class Disk
location: class CDStore
CDStore.java:68: error: cannot find symbol
d = (Disk)(CD.get(i));
^
symbol: method get(int)
location: class CD
5 errors
看起来我的驱动程序类没有链接到我的异常类。如何摆脱这些错误,将非常感谢任何帮助!
import java.util.*;
import java.text.*;
public class CDStore{
public static void main (String[ ] arg)throws Exception{
String sArtist = "";
String sAlbum = "";
int inStock = 0;
double dPrice = 0;
String C = "";
Disk d;
int count = 0;
boolean exit = false;
Scanner reader = new Scanner (System.in);
ArrayList CDShelf = new ArrayList( );
do{
try{
System.out.print("What is the Artist name: ");
sArtist = reader.nextLine( );
reader = new Scanner(System.in);
if(sArtist.length( ) < 1){
exit = true;
}
System.out.print("What is the album name: ");
sAlbum = reader.nextLine( );
reader = new Scanner(System.in);
if(sAlbum.length( ) < 1){
exit = true;
}
System.out.print("What is the price: ");
dPrice = reader.nextDouble( );
reader = new Scanner(System.in);
if(dPrice < 1){
exit = true;
}
System.out.print("How many are in stock: ");
inStock = reader.nextInt( );
reader = new Scanner(System.in);
d = new CD(sArtist, sAlbum, dPrice, inStock);
if(inStock < 1){
exit = true;
}
CD.add(d);
count++;
System.out.println(C.toString( ));
System.out.println("=============================");
}
catch(InputMismatchException ime){
System.out.println("You didnt do it");
}
catch(CDException cde){
System.out.println(cde.getMessage( ));
}
}while(count < 3);
System.out.println("This is what you entered");
for(int i = 0; i < CDShelf.length( ); i++){
d = (Disk)(CD.get(i));
System.out.println(d.toString( ));
}
}
}