[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Default Int Values

Posted on 2003-11-26
17
Medium Priority
?
246 Views
Last Modified: 2010-03-31
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);

      }

}
0
Comment
Question by:MSAJM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 6
  • 2
17 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 9825677
You need a ";" after all the:

         Massey_Week3_InvoiceItem1 item3 = new Massey_Week3_InvoiceItem1() ;

lines
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9825680
You can't have more than on emain method
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9825687
lines 6, 17, etc

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

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:MSAJM
ID: 9825790
OK, obviouly I need to rewrite the whole program.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9825811
You need to parameterize the main method so you can do what you intend
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9825924
And you really want a collection of objects to hold items. Perhaps you can tell me exactly what you want to achieve?
0
 

Author Comment

by:MSAJM
ID: 9826010
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 9826085
>>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
 
LVL 86

Expert Comment

by:CEHJ
ID: 9826156
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
 

Author Comment

by:MSAJM
ID: 9826191
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 9826230
>>public class Massey_Week3_InvoiceItem1

remove 'public' from the above
0
 

Author Comment

by:MSAJM
ID: 9826337
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
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 9826362
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
 

Author Comment

by:MSAJM
ID: 9826439
Awesome!  Thanks a million, no a billion!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9826518
:-) 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
 
LVL 86

Expert Comment

by:CEHJ
ID: 9826525
...although i see

setItemQuantity(1);

so that does alter things if you want to set that
0
 

Author Comment

by:MSAJM
ID: 9826542
I will set that back to 0, and thanks for all your help with this!  I really, really appreciate it!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question