Link to home
Start Free TrialLog in
Avatar of blaze41
blaze41

asked on

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!

ASKER CERTIFIED SOLUTION
Avatar of StillUnAware
StillUnAware
Flag of Lithuania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of blaze41
blaze41

ASKER

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 :-)
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
Avatar of blaze41

ASKER

...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 -