Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 162
  • Last Modified:

Est Communication among helper classes and the main class

I'm just learning programming concepts in Java 2 and don't understand how to put my "program" together so that both classes exist and work together to produce some mock invoices. I checked my classpath - fine and both files were saved in the same directory. And I don't see any typos...

I have two classes: Smith_Week3_InvoiceItem.java has my set/get functions to hold my invoice items (which compiles fine) The "main" class is my Smith_Week3_CreateInvoice.java (which is a mess and does not exist...I get the dreaded cannot resolve symbol and am sure it is a simple thing I've overlooked...) Anyway, I have to resolve this before I can get my main class to print my items. I don't get how it will call the methods to the other class...

No laughing - code so far:

//*Make class public so that all other classes can see it (ie: CreateInvoice)
public class Smith_Week3_InvoiceItem
{
  //Constructors

  public Smith_Week3_InvoiceItem()
  {
    //Call to new method
    reset();

    return;
  }
  //constructor: taking all arguments
  public Smith_Week3_InvoiceItem(String itemNameIn, int itemIdIn, float itemCostIn)
  {
    set(itemNameIn, itemIdIn, itemCostIn);

    return;
  }

  //Misc functions

 //set all args at once

  public void set(String itemNameIn, int itemIdIn, float itemCostIn)
  {
    setItemName(itemNameIn);
    setItemId(itemIdIn);
    setItemCost(itemCostIn);

    return;
  }

  //Reset all args to default values
  public void reset()
  {
    setItemName("");
    setItemId(0);
    setItemCost(0.0f);

    return;
}

//Create a string containing all of the cureent values
public String toString()
{
      String outputString = "Smith_Week3_InvoiceItem: Name=" + getItemName() + "; Id=" + getItemId() + "; Cost=" + getItemCost();

      return outputString;
}

  //Do set/get functions
  //Don't allow null balues for strings
  //Don't allow negative values for prices
  //Id numbers must be > 0
public void setItemName(String valueIn)
{
      if(valueIn !=null)
      {
            itemName=valueIn;
    }
    return;
}
public String getItemName()
{
    return itemName;
}

public void setItemId(int valueIn)
{
      if(valueIn > 0)
      {
            itemId=valueIn;
    }
    return;
}
public int getItemId()
{
      return itemId;
}
public void setItemCost(float valueIn)
{
      if(valueIn >=0.0f)
      {
            itemCost=valueIn;
    }
    return;
}
public float getItemCost()
{
      return itemCost;
}

//Do member data/attributes

private String itemName = "";
private int itemId = (0);
private float itemCost = 0.0f;

}//End of class Smith_Week3_InvoiceItem


The other class:

public class Smith_Week3_CreateInvoice
{
      public static void main(String[] args)
      {
            //Create some new invoices
            Smith_Week3_Invoice invoice1 = new Smith_Week3_Invoice("Palm m505", 1, 125.50f);
            Smith_Week3_Invoice invoice2 = new Smith_Week3_Invoice("Dell Laptop", 2, 1800.00f);
            Smith_Week3_Invoice invoice3 = new Smith_Week3_Invoice("Sony Digital Camera", 3500.00f);

            //Print out the information for each invoice
            System.err.println("Invoice 1:"+ invoice1.toString());
            System.err.println("Invoice 2:"+ invoice2.toString());
            System.err.println("Invoice 3:"+ invoice3.toString());

            //Print out the information for each invoice
            float totalValue = invoice1.getItemCost() + invoice2.getItemCost() + invoice3.getItemCost();
            System.err.printIn("Total value: $" + totalValue);
      }
}

If you could point me in the right direciton - I would be greatful      -Frustrated!

0
blaze41
Asked:
blaze41
  • 4
  • 2
3 Solutions
 
StillUnAwareCommented:
in main You use Smith_Week3_Invoice
while other file name is Smith_Week3_InvoiceItem
0
 
StillUnAwareCommented:
Smith_Week3_InvoiceItem invoice3 = new Smith_Week3_InvoiceItem("Sony Digital Camera", 3500.00f); - you omited the second parameter <int>

misspelled System.err.printIn("Total value: $" + totalValue);
should be System.err.println("Total value: $" + totalValue);
0
 
StillUnAwareCommented:
After removing these mistakes I got the result:

Invoice 1:Smith_Week3_InvoiceItem: Name=Palm m505; Id=1; Cost=125.5
Invoice 2:Smith_Week3_InvoiceItem: Name=Dell Laptop; Id=2; Cost=1800.0
Invoice 3:Smith_Week3_InvoiceItem: Name=Sony Digital Camera; Id=3; Cost=3500.0
Total value: $5425.5

so it's working. Keep on learning. Good luck.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
blaze41Author Commented:
StillUnAware,

Thanks so much for your observations! I did figure this out eventually last night and cannot believe I overlooked such obvious items/structure. However, am trying to cut myself some slack since it is my first attempt. Repetition brings familiarity, right? Again - Thanks :-)
0
 
StillUnAwareCommented:
Thanks for the points, but there is a little but, You shouldn't select the same person more than once while acceppting Your answer. Now it looks like I assissted answering to myself, in other words I got the points, but for good assistance, and not for an accepted answer.

Just a hint:)
StillUnAware
0
 
blaze41Author Commented:
...Sorry about that. Let me get this straight: When assigning points -- if you choose to "split the points" that is strictly among different contributors? So in this case I should have only selected the most applicable comment you made to my question? Why didn't they take the one with the most points assigned to it?

Thanks...I better check into the new member information -
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now