Default Int Values

public class Massey_Week3_CreateInvoice1
{
      public static void main(String[] args)
      {

            Massey_Week3_InvoiceItem1 item1 = new Massey_Week3_InvoiceItem1()
            item1.setItemNum(20239);
            item1.setItemName("Coors Light");
        item1.setItemQuantity(1);
        item1.setItemPrice(10.00f);
        item1.setTotalPrice(itemQuantity * itemPrice);
      }

      public static void main(String[] args)
      {

            Massey_Week3_InvoiceItem1 item2 = new Massey_Week3_InvoiceItem1()
            item2.setItemNum(20052);
            item2.setItemName("Coors Original");
            item2.setItemQuantity(1);
            item2.setItemPrice(11.00f);
            item2.setTotalPrice(itemQuantity * itemPrice);
      }

      public static void main(String[] args)
      {

            Massey_Week3_InvoiceItem1 item3 = new Massey_Week3_InvoiceItem1()
            item3.setItemNum(20151);
            item3.setItemName("Killians Irish Red");
            item3.setItemQuantity(1);
            item3.setItemPrice(12.00f);
            item3.setTotalPrice(itemQuantity * itemPrice);

      }

      public static void main(String[] args)
      {

            Massey_Week3_InvoiceItem1 item4 = new Massey_Week3_InvoiceItem1()
            item4.setItemNum(20024);
            item4.setItemName("Keystone Ice");
            item4.setItemQuantity(1);
            item4.setItemPrice(13.00f);
            iete4.setTotalPrice(itemQuantity * itemPrice);

      }

}
MSAJMAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimYatesCommented:
You need a ";" after all the:

         Massey_Week3_InvoiceItem1 item3 = new Massey_Week3_InvoiceItem1() ;

lines
0
CEHJCommented:
You can't have more than on emain method
0
TimYatesCommented:
lines 6, 17, etc

err...you also can't have more than one main method in the same class

0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

MSAJMAuthor Commented:
OK, obviouly I need to rewrite the whole program.
0
CEHJCommented:
You need to parameterize the main method so you can do what you intend
0
CEHJCommented:
And you really want a collection of objects to hold items. Perhaps you can tell me exactly what you want to achieve?
0
MSAJMAuthor Commented:
Create 3 invoice items, (I have 4 possibly for extra credit:) using InvoiceItem.
Print out a header line
Print out the 3 (4) invoice item lines
Print out the total cost of the invoice

New and improved version, but still not compiling:

public class Massey_Week3_CreateInvoice1
{
      public static void main(String[] args)
      {

            Massey_Week3_InvoiceItem1 item1 = new Massey_Week3_InvoiceItem1("20239", "Coors Light", 10.00f);
            Massey_Week3_InvoiceItem2 item2 = new Massey_Week3_InvoiceItem2("20052", "Coors Original", 11.00f);
            Massey_Week3_InvoiceItem3 item3 = new Massey_Week3_InvoiceItem3("20151", "Killians Irish Red", 12.00f);
            Massey_Week3_InvoiceItem4 item4 = new Massey_Week3_InvoiceItem4("20024", "Keystone Ice", 13.00f);

            System.err.println("Item 1: " + item1.toString());
            System.err.println("Item 2: " + item2.toString());
        System.err.println("Item 3: " + item3.toString());
        System.err.println("Item 4: " + item4.toString());

        float totalPrice = item1.getItemPrice() + item2.getItemPrice() + item3.getItemPrice() + item4.getItemPrice();
            System.err.println("Total value: $" + totalPrice);
      }

}
0
CEHJCommented:
>>Massey_Week3_InvoiceItem1

Is a class name. You only need one class, but four instances. Call it

Massey_Week3_InvoiceItem

and do

Massey_Week3_InvoiceItem item1 = new Massey_Week3_InvoiceItem("20239", "Coors Light", 10.00f);

...
0
CEHJCommented:
Save this to file elsewhere as Massey_Week3_CreateInvoice1.java. It should get you started.



public class Massey_Week3_CreateInvoice1 {

      public static void main(String[] args) {

            Massey_Week3_InvoiceItem item1 = new Massey_Week3_InvoiceItem("20239", "Coors Light", 10.00f);
            Massey_Week3_InvoiceItem item2 = new Massey_Week3_InvoiceItem("20052", "Coors Original", 11.00f);
            Massey_Week3_InvoiceItem item3 = new Massey_Week3_InvoiceItem("20151", "Killians Irish Red", 12.00f);
            Massey_Week3_InvoiceItem item4 = new Massey_Week3_InvoiceItem("20024", "Keystone Ice", 13.00f);

            System.err.println("Item 1: " + item1.toString());
            System.err.println("Item 2: " + item2.toString());
            System.err.println("Item 3: " + item3.toString());
            System.err.println("Item 4: " + item4.toString());

            float totalPrice = item1.getItemPrice() + item2.getItemPrice() + item3.getItemPrice() + item4.getItemPrice();
            System.err.println("Total value: $" + totalPrice);
      }

}

class Massey_Week3_InvoiceItem {

      public Massey_Week3_InvoiceItem(String s1, String s2, float f1) {
            // unimplemented
      }

      public int getItemPrice() {
            //dummy
            return 100;
      }

      public String toString() {
            return "Dummy!";
      }

}
0
MSAJMAuthor Commented:
OK, here we go.  I have almost figured it out, but I still have 1 error message.  I have to put the two programs together to get the desired results....duhhh!  OK, here is what I have now....

////////////////////////////////////////////////////////////////////////////
//
// File:     Massey_Week3_CreateInvoice1.java
//
// Project:  POS406
//
// Purpose:  Create Invoice
//
// Comments: Version 1 is what I would turn in if this were an assignment
//
// Author:   Amy Massey
//
///////////////////////////////////////////////////////////////////////////
public class Massey_Week3_InvoiceItem1
{

      private int itemNum = 0;
        private String itemName = "";
         private int itemQuantity = 1;
      private float itemPrice = 0.0f;
      private float totalPrice = 0.0f;


public void setItemNum(int valueIn)
{
    itemNum = valueIn;
    return;
         }
         public int getItemNum()
         {
    return itemNum;
}

public void setItemName(String valueIn)
{
     itemName = valueIn;
     return;
          }
          public String getItemName()
          {
     return itemName;
}

public void setItemQuantity(int valueIn)
{
     itemQuantity = valueIn;
     return;
          }
          public int getItemQuantity()
          {
     return itemQuantity;
}

public void setItemPrice(float valueIn)
{
       itemPrice = valueIn;
       return;
       }
       public float getItemPrice()
       {
       return itemPrice;
}

public void setTotalPrice(float valueIn)
{
      totalPrice = valueIn;
      return;
      }
      public float getTotalPrice()
      {
      return totalPrice;
}

public Massey_Week3_InvoiceItem1()
{
      setItemNum(0);
    setItemName("");
    setItemQuantity(1);
      setItemPrice(0.0f);
      setTotalPrice(0.0f);

    return;
}

public Massey_Week3_InvoiceItem1(int itemNumIn, String itemNameIn, int itemQuantityIn, float itemPriceIn, float totalPriceIn)
{
    setItemNum(itemNumIn);
    setItemName(itemNameIn);
    setItemQuantity(itemQuantityIn);
      setItemPrice(itemPriceIn);
      setTotalPrice(totalPriceIn);

       return;
      }

public class Massey_Week3_CreateInvoice1
{
      public static void main(String[] args)
      {

            Massey_Week3_InvoiceItem1 item1 = new Massey_Week3_InvoiceItem1("20239", "Coors Light", 1, 10.00f);
            Massey_Week3_InvoiceItem1 item2 = new Massey_Week3_InvoiceItem1("20052", "Coors Original", 1, 11.00f);
            Massey_Week3_InvoiceItem1 item3 = new Massey_Week3_InvoiceItem1("20151", "Killians Irish Red", 1, 12.00f);
            Massey_Week3_InvoiceItem1 item4 = new Massey_Week3_InvoiceItem1("20024", "Keystone Ice", 1, 13.00f);

            System.err.println("Item 1: " + item1.toString());
            System.err.println("Item 2: " + item2.toString());
        System.err.println("Item 3: " + item3.toString());
        System.err.println("Item 4: " + item4.toString());

        float totalPrice = item1.getItemPrice() + item2.getItemPrice() + item3.getItemPrice() + item4.getItemPrice();
            System.err.println("Total value: $" + totalPrice);
      }

}
0
CEHJCommented:
>>public class Massey_Week3_InvoiceItem1

remove 'public' from the above
0
MSAJMAuthor Commented:
OK, now we have run into 5 more errors...
lines 102, 103, 104, 105...cannot resolve symbol...ahhhh! the ^ in under "new"

and line 99 inner classes cannot have static declarations.  any ideas on what I am doing wrong?
0
CEHJCommented:
You have return statements all over the place. They should not be there. The following compiles fine:



////////////////////////////////////////////////////////////////////////////
//
// File:     Massey_Week3_CreateInvoice1.java
//
// Project:  POS406
//
// Purpose:  Create Invoice
//
// Comments: Version 1 is what I would turn in if this were an assignment
//
// Author:   Amy Massey
//
///////////////////////////////////////////////////////////////////////////
class Massey_Week3_InvoiceItem1
{

     private int itemNum = 0;
       private String itemName = "";
        private int itemQuantity = 1;
     private float itemPrice = 0.0f;
     private float totalPrice = 0.0f;


public void setItemNum(int valueIn)
{
    itemNum = valueIn;
        }
        public int getItemNum()
        {
    return itemNum;
}

public void setItemName(String valueIn)
{
     itemName = valueIn;
         }
         public String getItemName()
         {
     return itemName;
}

public void setItemQuantity(int valueIn)
{
     itemQuantity = valueIn;
         }
         public int getItemQuantity()
         {
     return itemQuantity;
}

public void setItemPrice(float valueIn)
{
      itemPrice = valueIn;
      }
      public float getItemPrice()
      {
      return itemPrice;
}

public void setTotalPrice(float valueIn)
{
     totalPrice = valueIn;
     }
     public float getTotalPrice()
     {
     return totalPrice;
}

public Massey_Week3_InvoiceItem1()
{
     setItemNum(0);
    setItemName("");
    setItemQuantity(1);
     setItemPrice(0.0f);
     setTotalPrice(0.0f);

}

public Massey_Week3_InvoiceItem1(int itemNumIn, String itemNameIn, int itemQuantityIn, float itemPriceIn, float totalPriceIn)
{
    setItemNum(itemNumIn);
    setItemName(itemNameIn);
    setItemQuantity(itemQuantityIn);
     setItemPrice(itemPriceIn);
     setTotalPrice(totalPriceIn);

     }

public Massey_Week3_InvoiceItem1(String itemNameIn, String x, int y, float totalPriceIn)
{
  // NEEDS IMPLEMENTATION!
}


}


public class Massey_Week3_CreateInvoice1
{
     public static void main(String[] args)
     {

          Massey_Week3_InvoiceItem1 item1 = new Massey_Week3_InvoiceItem1("20239", "Coors Light", 1, 10.00f);
          Massey_Week3_InvoiceItem1 item2 = new Massey_Week3_InvoiceItem1("20052", "Coors Original", 1, 11.00f);
          Massey_Week3_InvoiceItem1 item3 = new Massey_Week3_InvoiceItem1("20151", "Killians Irish Red", 1, 12.00f);
          Massey_Week3_InvoiceItem1 item4 = new Massey_Week3_InvoiceItem1("20024", "Keystone Ice", 1, 13.00f);

          System.err.println("Item 1: " + item1.toString());
          System.err.println("Item 2: " + item2.toString());
        System.err.println("Item 3: " + item3.toString());
        System.err.println("Item 4: " + item4.toString());

        float totalPrice = item1.getItemPrice() + item2.getItemPrice() + item3.getItemPrice() + item4.getItemPrice();
           System.err.println("Total value: $" + totalPrice);
     }

}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MSAJMAuthor Commented:
Awesome!  Thanks a million, no a billion!
0
CEHJCommented:
:-) Don't forget to implement the constructor. The following:

>>
public Massey_Week3_InvoiceItem1()
{
     setItemNum(0);
    setItemName("");
    setItemQuantity(1);
     setItemPrice(0.0f);
     setTotalPrice(0.0f);

}
>>

is redundant as

a. Java supplies the empty constructor
b. Java zeroes out values automatically

0
CEHJCommented:
...although i see

setItemQuantity(1);

so that does alter things if you want to set that
0
MSAJMAuthor Commented:
I will set that back to 0, and thanks for all your help with this!  I really, really appreciate it!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.