title: Using default and non default constructors in my application
body: <p>I'm new to java and have a question about default and non default constructors. My professor wants us to use the default constructor for creation of object BOOK1, and then use the non default constructor for BOOK2, BOOK3 and BOOK4. I know a constructor is used with the creation of an object, but I guess I don't understand how i'm supposed to differentiate between the two. My class code is as follows, where I have both a default and non default constructor:</p>
  
  <pre><code>import java.text.DecimalFormat;
  
  public final class BOOKItem {
  
      DecimalFormat intFormat = new DecimalFormat("000");
      DecimalFormat doubleFormat = new DecimalFormat("$#,##0.00");
  
      private int bookID;
      private int numberInStock;
      private double price;
      private double totalValueOfStock;
      private int code;
      private String genre = "";
  
      public BOOKItem() {
          bookID = 0;
          numberInStock = 0;
          price = 0;
          code = 0;
      }
  
      public BOOKItem(int newID, int newStock, double newPrice, int newCode) {
  
          setID(newID);
          setStock(newStock);
          setCode(newCode);
          setPrice(newPrice);
  
  
      }
  
      public void setStock (int newStock) {
  
          if (newStock &gt;= 1 &amp;&amp; newStock &lt;=5000) {
              numberInStock = newStock;
          }
           else {
              numberInStock = 0;
          }
    }
  
  public void setCode (int newCode) {
  
      if (newCode &gt; 0) {
          code = newCode;
      }
  }
  
  public void setID (int newID) {
      if (newID &gt;=11 &amp;&amp; newID &lt;= 111111) {
          bookID = newID;
      }
      else {
          bookID = 0;
      }
      }
  
  public void setPrice (double newPrice) {
      if (newPrice &gt;= 1.0 &amp;&amp; newPrice &lt;=150.0) {
          price = newPrice;
      }
      else {
          price = 0;
      }
  }
  
  public int getID () {
  
  return bookID;
  </code></pre>
  
  <p>}</p>
  
  <pre><code>public int getNumberInStock () {
      return numberInStock;
  }
  
  public int getCode () {
      return code;
  }
  
  public double getPrice () {
      return price;
  }
  
  public double calcTotalValue () {
      totalValueOfStock = numberInStock * price;
      return totalValueOfStock;
  }
  
  public double getTotalValue () {
      return totalValueOfStock;
  }
  
     public void display() {
         switch (code)
      {   
         case 1:               
           genre = "Romance";
             break;
         case 2: 
           genre = "Adventure";
             break;
         case 3:
           genre = "Sci-Fi";
             break;
         case 4:
           genre = "Mystery";
             break;
      }               
     System.out.println("Display:");
     System.out.println("Book ID: " + bookID + " NumInStock: " + numberInStock + " Code: " + genre + " Price: " + 
                        price + " TotalStockValue: " + calcTotalValue());
     }
  
  
  
  }
  </code></pre>
  
  <p>Here is my application that uses the constructors(sorry about the break in the class code, i dunno why its doing that):</p>
  
  <pre><code>import java.util.Scanner;
  
  public class Project7 {
  
  public static void main(String[] args) {
  
      int bookID;
      int numberInStock;
      double price;
      int code;
  
      Scanner keyboard = new Scanner(System.in);
  
      BOOKItem BOOK1, BOOK2, BOOK3, BOOK4;
      BOOK1 = new BOOKItem();
      BOOK2 = new BOOKItem();
      BOOK3 = new BOOKItem();
      BOOK4 = new BOOKItem();
  
      System.out.println("Enter in a blank separated list: ID, number in stock, quality, price" + 
                         "- use a BAD ID(&lt;11 or &gt;111111)");
  
      bookID = keyboard.nextInt();
      numberInStock = keyboard.nextInt();
      code = keyboard.nextInt();
      price = keyboard.nextDouble();
  
      BOOK1.setID(bookID);
      BOOK1.setStock(numberInStock);
      BOOK1.setCode(code);
      BOOK1.setPrice(price);
      BOOK1.display();
  
      System.out.println("Enter in a blank separated list: ID, number in stock, quality, price" + 
                         "- use a BAD STOCK(&gt;5000)");
  
      bookID = keyboard.nextInt();
      numberInStock = keyboard.nextInt();
      code = keyboard.nextInt();
      price = keyboard.nextDouble();
  
      BOOK2.setID(bookID);
      BOOK2.setStock(numberInStock);
      BOOK2.setCode(code);
      BOOK2.setPrice(price);
      BOOK2.display();
  
      System.out.println("Enter in a blank separated list: ID, number in stock, quality, price" + 
                         "- use a BAD PRICE(&gt;150.0)");
  
      bookID = keyboard.nextInt();
      numberInStock = keyboard.nextInt();
      code = keyboard.nextInt();
      price = keyboard.nextDouble();
  
      BOOK3.setID(bookID);
      BOOK3.setStock(numberInStock);
      BOOK3.setCode(code);
      BOOK3.setPrice(price);
      BOOK3.display();
  
      System.out.println("Enter in a blank separated list: ID, number in stock, quality, price" + 
                         "- use ALL GOOD DATA");
  
      bookID = keyboard.nextInt();
      numberInStock = keyboard.nextInt();
      code = keyboard.nextInt();
      price = keyboard.nextDouble();
  
      BOOK4.setID(bookID);
      BOOK4.setStock(numberInStock);
      BOOK4.setCode(code);
      BOOK4.setPrice(price);
      BOOK4.display();
  
  
  
  
  
  
   }
  }
  </code></pre>
  
  <p>Am I doing something incorrect with the creation of my objects? How do I use the non default constructor for BOOK2, BOOK3 and BOOK4? I created it, but perhaps i'm using it incorrectly. Any feedback would be greatly appreciated. </p>