在cmd中编译错误而不是netbeans

时间:2013-12-19 19:47:06

标签: java netbeans arraylist compiler-errors cmd

我尝试使用javac在cmd中编译Java类文件,但它一直给我这些错误:

Jukebox.java:10: error: cannot find symbol
    private ArrayList<Song> jSongs;

  symbol:    class Song
  location:  class Jukebox

我得到的所有错误都指向Song类(如果这意味着什么,所有文件都在同一个文件夹中),除非我使用NetBeans,文件编译得很好。问题是这是一个项目,无论谁标记它都会尝试用cmd编译它。所以任何帮助都将不胜感激。

在下面你会找到Song类(在cmd中编译得很好),然后是Jukebox类(有问题的那个)。

public class Song {
    private String artist;
    private String title;
    private double price;
    private int playCount;
    private double length;

    public Song()
    {
        artist = "unknown";
        title = "unknown";
        price = 0.00;
        length = 0.00;
        playCount = 0;
    }

    public Song(String artist, String title, double price, double length)
    {
        this.artist = artist;
        this.title = title;
        this.price = price;
        this.length = length;
        playCount = 0;
    }

    public String getArtist()
    {
        return artist;
    }

    public String getTitle()
    {
        return title;
    }

    public double getPrice()
    {
        return price;
    }

    public int getCount()
    {
        return playCount;
    }

    public double getLength()
    {
        return length;
    }

    public void changePrice(double newPrice)
    {
        price = newPrice;
    }

    public void playSong()
    {
        playCount++;
        System.out.println(title + " is now playing." + "\n" + toString());
    }

    public String toString()
    {
        return artist + "\n"
        + title + "\n"
        + price + "\n"
        + length;
    }
}

Jukebox课程:

import java.util.ArrayList;
public class Jukebox {
    private String name;
    private ArrayList<Song> jSongs;

    public Jukebox()
    {
        name = "Primary Jukebox";
        jSongs = new ArrayList<Song>();
    }

    public String getName()
    {
        return name;
    }

    public double calcTotal()
    {
        double total = 0.00;

        for (int i = 0; i < jSongs.size(); i++)
        {
            total += jSongs.get(i).getPrice();
        }

        return total;
    }

    public void searchSong(String sTitle)
    {
        boolean check = false;
        if ( jSongs.size() == 0 ) {
            System.out.println("The are no songs in the list.");
            check = true;
        } else if ( jSongs.size() != 0 ) {
            for ( int i = 0; i < jSongs.size(); i++ ) {
                if ( jSongs.get(i).getTitle().equals(sTitle) == true ) {
                    check = true;
                    System.out.println(jSongs.get(i));
                    jSongs.get(i).playSong();
                }
            }
        }
        if ( check == false ) {
            System.out.println("The searched song could not be found.");
        }
    }

    public Song searchArtist(String sArtist)
    {
        int countMatch = 0;
        for (int i = 0; i < jSongs.size(); i++) {
            if ( jSongs.get(i).getArtist().equals(sArtist) ) {
                countMatch++;
                return jSongs.get(i);
            } else if ( countMatch == 0 ) {
                System.out.println("The requested artist could not be found.");
            }
        }
        return null;
    }

    public void addSong(Song s1)
    {
        boolean check = false;

        if ( jSongs.size() == 0 ) {
            System.out.println("Your song will be added to the list.");
            jSongs.add(s1);
            return;
        } else if ( jSongs.size() != 0 ) {
            for ( int i = 0; i < jSongs.size(); i++ ) {
                if ( jSongs.get(i) == s1 ) {
                    check = true;
                }
            }
        }
        if ( check == false ) {
            System.out.println("Your song will be added to the list.");
            jSongs.add(s1);
        } else if ( check == true ) {
            System.out.println("Your song is already in the list.");
        }
    }

    public void removeSong(String title)
    {
        boolean check = false;
        for ( int i = 0; i < jSongs.size(); i++ ) {
            if ( jSongs.get(i).getTitle().equals(title) ) {
                jSongs.remove(i);
                check = true;
            }
        }
        System.out.println(check);
    }

    public void displaySongs()
    {
        for ( int i = 0; i < jSongs.size(); i++ ) {
            System.out.println(jSongs.get(i));
        }
    }

    public Song showMostExpensive()
    {
        double price = 0.00;
        Song mostESong = new Song();
        for ( int i = 0; i < jSongs.size(); i++ ) {
            if ( jSongs.get(i).getPrice() > price ) {
                price = jSongs.get(i).getPrice();
                mostESong = jSongs.get(i);
            }
        }
        return mostESong;
    }

    public Song showShortest()
    {
        double length = 500.00;
        Song shortest = new Song();
        for ( int i = 0; i < jSongs.size(); i++ ) {
            if ( jSongs.get(i).getLength() < length ) {
                length = jSongs.get(i).getLength();
                shortest = jSongs.get(i);
            }
        }
        return shortest;
    }

    public Song mostPlayed()
    {
        int count = 0;
        Song mostPSong = new Song();
        for ( int i = 0; i < jSongs.size(); i++ ) {
            if ( jSongs.get(i).getCount() > count ) {
                count = jSongs.get(i).getCount();
                mostPSong = jSongs.get(i);
            }
        }
        return mostPSong;
    }
}

0 个答案:

没有答案
相关问题