0

You will need to check that the four parameters entered by the user are blank, so you will do the same as you did before but four times.

To Identify if the User Presses <enter>

You have written a JAVA program that creates a CD object with four instance variables, along with a CDException.java class that helps you validate this input. So far you have been using these classes with my driver classes. Now it is time for you to create a real driver class that will implement an ArrayList of CD objects.
Here is a list of requirements for your LAST program

Read the artist name from the user
Read the album name from the user
Read the number of items in stock
Read the price of the album
Your program should continue to read the CD information from the user until all the entries from
the user for all the fields are blank.
Your program will then print the list all the "valid" CDs entered by the user.

I keep getting errors like this

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

And it looks like that my driver class here is not linking with my exception class. Any help would be much appreciated on how to get rid of these errors!

import java.util.*;
import java.util.ArrayList;
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.size( ); i++){
            d = (Disk)(CD.get(i));
            System.out.println(d.toString( ));
        }
 }
}
2
Contributors
1
Reply
11
Views
3 Years
Discussion Span
Last Post by stultuske
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.