您将需要检查用户输入的四个参数是否为空白,因此您将执行与之前相同的操作,但要执行四次。
识别用户是否按下
<enter>
您编写了一个 JAVA 程序,该程序创建了一个带有四个实例变量的 CD 对象,以及一个帮助您验证此输入的 CDException.java 类。到目前为止,您一直在将这些类与我的驱动程序类一起使用。现在是时候创建一个真正的驱动程序类来实现 CD 对象的 ArrayList。这是您的 LAST 计划的要求列表
- 从用户那里读取艺术家姓名
- 从用户那里读取专辑名称
- 读取库存商品数量
- 阅读专辑价格
您的程序应该继续从用户那里读取 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( ));
}
}
}