为什么每个产品都是"类型"我运行时没有显示在我的输出上?

时间:2015-02-25 01:35:31

标签: java

public class DVD implements Comparable<DVD>
{ 
     int dvdNumber; 
     String dvdName;
     int quantity; 
     double price;


     /*  
      *This constructor takes the dvdNumber as string, the dvdName as string, a quantity as integer, and a price as a double and sets the base values of the items(s) in inventory 
      */ 
     public DVD(int number, String name, int quantity, double MSRP) 
     { 
          dvdNumber = number; 
          dvdName = name;
          this.quantity = quantity; 
          price = MSRP; 
     } 
     // getdvdNumber: returns the identifier for the item 
     public int getdvdNumber() 
     { 
          return dvdNumber; 
     } 
     // setdvdNumber: sets the identifier for the item 
     public void setdvdNumber(int value) 
     { 
          dvdNumber = value; 
     } 
     // getdvdName: returns the item name for the item 
     public String getdvdName() 
     { 
          return dvdName; 
     }      

     // getQuantity: returns the quantity of dvds in stock 
     public int getQuantity() 
     { 
          return quantity; 
     } 

     // setQuantity: sets the number of dvds in stock 
     public void setQuantity(int value) 
     { 
          quantity = value; 
     } 

     // getPrice: returns the price for the dvd
     public double getPrice() 
     { 
          return price; 
     } 
     // setPrice: sets the price for the dvd 
     public void setPrice(double value) 
     { 
          price = value; 
     } 
     // getInventoryValue: calculates the total value of the inventory for the item 
     public double getInventoryValue() 
     { 
          return getPrice() * getQuantity(); 
     } 
     // toString returns the printout of the individual item for display to the screen 
     public String toString() 
     { 
          return String.format("\nInventory Info\n%s %s\n%s\t %s\n%s\t %d\n%s\t $%,.2f\n%s\t $%,.2f","Product Number: ", getdvdNumber(), 
                    "Product Name: ", getdvdName(), "Units In Stock:", getQuantity(), 
                    "Price per Unit:", getPrice(), "Total Inventory Value:", getInventoryValue()); 
     }

        @Override
        public int compareTo(DVD other){
            int last = this.dvdName.compareTo(other.dvdName);
            return last == 0 ? this.dvdName.compareTo(other.dvdName) : last;
            }

} // end class DVD

我是整个编程的新手。我很困惑为什么每次运行时都没有显示每个DVD的类型。我不知道你们是否需要我的其他2个班级,但如果你这样做,我会乐意为他们提供。顺便说一下,当我运行这个程序时,我没有收到任何错误消息。它只是没有正确显示。

class DVD2 extends DVD {
    private String dvdGenre;

    public DVD2(int number, String name, String genre, int quantity, double price)
    {
        super(number, name, quantity, price);
        dvdGenre = genre;
    }

    public String getdvdGenre()
    {
        return dvdGenre;
    }

    DVD p1 = new DVD2(1,"Forrest Gump","Drama",3,15.49);
    DVD p2 = new DVD2(2,"Cast Away","Adventure",7,17.29);
    DVD p3 = new DVD2(3,"The Interview","Comedy",9,19.99);
    DVD p4 = new DVD2(4,"Fight Club","Drama",5,14.79);
    DVD p5 = new DVD2(5,"Happy Gilmore","Comedy",16,9.29);

    public double value() {
        double value = getPrice() * getQuantity();
        value = 0.05 * value;
        return value;
    } // end method value

    @Override public String toString()
    { 
        return String.format("\nInventory Info\n%s %s\n%s\t %s\n%s\t %d\n%s\t $%,.2f\n%s\t $%,.2f","Product Number: ", getdvdNumber(), 
              "Product Name: ", getdvdName(), "Genre: ", getdvdGenre(), "Units In Stock:", getQuantity(), 
              "Price per Unit:", getPrice(), "Total Inventory Value:", getInventoryValue()); 
    }

} // end class DVD2

0 个答案:

没有答案