473,387 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Adding a Restock Fee

nexcompac
I am getting I believe three erros in this code. I had it running perfect untill I added all the restock fee items.

This is what I have so far:

Expand|Select|Wrap|Line Numbers
  1. import java.util.*; // program uses class Scanner
  2.  
  3. public class Inventory 
  4. {    
  5.     // main method begins execution of Java application
  6.    public static void main( String args[]) 
  7.    {    
  8.       product[] myProduct = new product[5];      
  9.  
  10.         product p1 = new product("Tom Clancy Vegas", 20003, 5, 30);
  11.         product p2 = new product("Froger", 74512, 2, 10);
  12.         product p3 = new product("Halo 2", 20009, 3, 45);
  13.         product p4 = new product("Night Caster", 74522, 8, 5);
  14.         product p5 = new product("Halo 3", 32976, 1, 50);
  15.  
  16.         myProduct[0] = p1;
  17.         myProduct[1] = p2;
  18.         myProduct[2] = p3;
  19.         myProduct[3] = p4;
  20.         myProduct[4] = p5;
  21.  
  22.         double totalValue = 0.0;
  23.  
  24.         for (int c=0; c < 5; c++)
  25.         {
  26.             totalValue = totalValue + myProduct[c].itemCalculate();
  27.         }
  28.  
  29.         Arrays.sort(myProduct); // function used to sort arrays
  30.  
  31.         for(product p: myProduct)
  32.         {
  33.             System.out.println(p);
  34.             System.out.println();
  35.         }
  36.        System.out.println("Total Inventory value is: $"+totalValue);
  37.  
  38.    } //end main
  39.  
  40. } //end Inventory
  41.  
  42.  
The above works fine, the errors appear here below (I think because I only changed the below and got errors.


Expand|Select|Wrap|Line Numbers
  1.  
  2. import java.util.*; // program uses any class available
  3.  
  4. class product implements Comparable 
  5. {
  6.    private String productName; // class variable that stores the item name
  7.    private int itemNumber; // class variable that stores the item number
  8.    private double unitProduct; // class variable that stores the quantity in 
  9.  
  10. stock
  11.    private double priceProduct; // class variable that stores the item price
  12.  
  13.     /** Creates a new instance of product */
  14.     public product() // Constructor for Product class
  15.      {
  16.         productName = "";
  17.         itemNumber = 0;
  18.         unitProduct = 0.0;
  19.         priceProduct = 0.0;
  20.      }
  21.     public product( String productName, int itemNumber, double unitProduct, 
  22.  
  23. double priceProduct) // Constructor for myProduct class
  24.     {
  25.         this.productName = productName;
  26.         this.itemNumber = itemNumber;
  27.         this.unitProduct = unitProduct;
  28.         this.priceProduct = priceProduct;
  29.     }
  30.  
  31.       public void setProductName(String name)  // Method to set the item 
  32.  
  33. name
  34.        {
  35.          this.productName = productName;
  36.        }
  37.       public String getProductName()  // Method to get the item name
  38.        {
  39.          return productName;
  40.        }
  41.       public void setItemNumber(int number)  // Method to set the item 
  42.  
  43. number
  44.        {
  45.          this.itemNumber = itemNumber;
  46.        }
  47.       public int getItemNumber()  // Method to get the item name
  48.        {
  49.          return itemNumber;
  50.        }
  51.        public void setUnitProduct(double unit)  // Method to set the item 
  52.  
  53. number
  54.        {
  55.          this.unitProduct = unitProduct;
  56.        }
  57.       public double getUnitProduct()  // Method to get the item name
  58.        {
  59.          return unitProduct;
  60.        }
  61.        public void setPriceProduct(double price)  // Method to set the item 
  62.  
  63. number
  64.        {
  65.          this.priceProduct = priceProduct;
  66.        }
  67.       public double getPriceProduct()  // Method to get the item name
  68.        {
  69.          return priceProduct;
  70.        }
  71.  
  72. // Calculation method
  73.   public double itemCalculate()
  74.    {     
  75.         return unitProduct * priceProduct * 2; // multiply for total for 
  76.  
  77. each item
  78.  
  79.    } // end calculation
  80.   public int compareTo (Object o) // use the compareTo method
  81.     {
  82.       product p = (product)o;
  83.          return productName.compareTo(p.getProductName());
  84.     }
  85.  
  86.   public String toString() // displays products
  87.   {
  88.       return "Title: "+productName+
  89.               "\nBarcode: "+itemNumber+
  90.               "\nNumber of Xbox games: "+(int)unitProduct+
  91.               "\nPrice: $"+priceProduct+
  92.               "\nTotal: $"+itemCalculate();
  93.    } // end toString
  94.  
  95.  
  96. }//end class Supplies 
  97.  
Jul 30 '07 #1
30 2519
blazedaces
284 100+
Care to show us the entire error and printed stack trace (shows where the error occurs)?

-blazed
Jul 30 '07 #2
Care to show us the entire error and printed stack trace (shows where the error occurs)?

-blazed
I have been compiling within the bin folders at the cmd prompt.

Product.java:61 cannot find symbol
symbol : method value<>
location: class product
return value<> * 0.05;

Product.java:65 cannot find symbol
symbol : method value<>
location: class product
return value<> * 0.05;

Product.java:82 cannot find symbol
symbol : method value<>
location: class product
return value<> * 0.05;

3 errors
Jul 30 '07 #3
madhoriya22
252 100+
I have been compiling within the bin folders at the cmd prompt.

Product.java:61 cannot find symbol
symbol : method value<>
location: class product
return value<> * 0.05;

Product.java:65 cannot find symbol
symbol : method value<>
location: class product
return value<> * 0.05;

Product.java:82 cannot find symbol
symbol : method value<>
location: class product
return value<> * 0.05;

3 errors
Hi,
I think you have posted errors of different code..........errors doesnt belong to the code u have posted. check it again..
Thanks and regards,
madhoriya
Jul 30 '07 #4
Yep your right.... That's what happens when your tired.

here it is:
Expand|Select|Wrap|Line Numbers
  1.  
  2. import java.util.*; // program uses any class available
  3.  
  4. class product implements Comparable 
  5. {
  6.    private String productName; // class variable that stores the item name
  7.    private int itemNumber; // class variable that stores the item number
  8.    private double unitProduct; // class variable that stores the quantity in stock
  9.    private double priceProduct; // class variable that stores the item price
  10.  
  11.     /** Creates a new instance of product */
  12.     public product() // Constructor for Product class
  13.      {
  14.         productName = "";
  15.         itemNumber = 0;
  16.         unitProduct = 0.0;
  17.         priceProduct = 0.0;
  18.      }
  19.     public product( String productName, int itemNumber, double unitProduct, double priceProduct) // Constructor for myProduct class
  20.     {
  21.         this.productName = productName;
  22.         this.itemNumber = itemNumber;
  23.         this.unitProduct = unitProduct;
  24.         this.priceProduct = priceProduct;
  25.     }
  26.  
  27.       public void setProductName(String name)  // Method to set the item name
  28.        {
  29.          this.productName = productName;
  30.        }
  31.       public String getProductName()  // Method to get the item name
  32.        {
  33.          return productName;
  34.        }
  35.       public void setItemNumber(int number)  // Method to set the item number
  36.        {
  37.          this.itemNumber = itemNumber;
  38.        }
  39.       public int getItemNumber()  // Method to get the item name
  40.        {
  41.          return itemNumber;
  42.        }
  43.        public void setUnitProduct(double unit)  // Method to set the item number
  44.        {
  45.          this.unitProduct = unitProduct;
  46.        }
  47.       public double getUnitProduct()  // Method to get the item name
  48.        {
  49.          return unitProduct;
  50.        }
  51.        public void setPriceProduct(double price)  // Method to set the item number
  52.        {
  53.          this.priceProduct = priceProduct;
  54.        }
  55.       public double getPriceProduct()  // Method to get the item name
  56.        {
  57.          return priceProduct;
  58.        }
  59.       public double setRestockFee()  // Method to set the Restocking fee
  60.        {
  61.         return value() * 0.05;
  62.        }
  63.       public double getRestockFee()  // Method to set the Restocking fee
  64.        {
  65.         return value() * 0.05;
  66.        }
  67.  
  68.  
  69. // Calculation method
  70.   public double itemCalculate()
  71.    {     
  72.         return unitProduct * priceProduct; // multiply for total for each item
  73.  
  74.    } // end calculation
  75.   public int compareTo (Object o) // use the compareTo method
  76.     {
  77.       product p = (product)o;
  78.          return productName.compareTo(p.getProductName());
  79.    }
  80.   public double RestockFee()  // Method to set the Restocking fee
  81.      {
  82.         return value() * 0.05;
  83.    }  // end
  84.  
  85.   public String toString() // displays products
  86.   {
  87.       return "Title: "+productName+
  88.               "\nBarcode: "+itemNumber+
  89.               "\nNumber of Xbox games: "+(int)unitProduct+
  90.               "\nPrice: $"+priceProduct+
  91.               "\nTotal: $"+itemCalculate();
  92.    } // end toString
  93.  
  94.  
  95. }//end class Supplies 
  96.  
Jul 30 '07 #5
madhoriya22
252 100+
class product implements Comparable
{
private String productName; // class variable that stores the item name
private int itemNumber; // class variable that stores the item number
private double unitProduct; // class variable that stores the quantity in stock
private double priceProduct; // class variable that stores the item price

/** Creates a new instance of product */
public product() // Constructor for Product class
{
productName = "";
itemNumber = 0;
unitProduct = 0.0;
priceProduct = 0.0;
}
public product( String productName, int itemNumber, double unitProduct, double priceProduct) // Constructor for myProduct class
{
this.productName = productName;
this.itemNumber = itemNumber;
this.unitProduct = unitProduct;
this.priceProduct = priceProduct;
}

public void setProductName(String name) // Method to set the item name
{
this.productName = productName;
}
public String getProductName() // Method to get the item name
{
return productName;
}
public void setItemNumber(int number) // Method to set the item number
{
this.itemNumber = itemNumber;
}
public int getItemNumber() // Method to get the item name
{
return itemNumber;
}
public void setUnitProduct(double unit) // Method to set the item number
{
this.unitProduct = unitProduct;
}
public double getUnitProduct() // Method to get the item name
{
return unitProduct;
}
public void setPriceProduct(double price) // Method to set the item number
{
this.priceProduct = priceProduct;
}
public double getPriceProduct() // Method to get the item name
{
return priceProduct;
}
public double setRestockFee() // Method to set the Restocking fee
{
return value() * 0.05;
}
public double getRestockFee() // Method to set the Restocking fee
{
return value() * 0.05;
}


// Calculation method
public double itemCalculate()
{
return unitProduct * priceProduct; // multiply for total for each item

} // end calculation
public int compareTo (Object o) // use the compareTo method
{
product p = (product)o;
return productName.compareTo(p.getProductName());
}
public double RestockFee() // Method to set the Restocking fee
{
return value() * 0.05;
} // end

}//end class Supplies
[/code][/quote]

Hi,
So here u posted the right code......see ur errors......compiler is not able to find value() method.......... coz there is no value() method in ur product(name it --Product *always start a class name with block letter only*) class...... so check it again

thanks and regards,
madhoriya
Jul 30 '07 #6
I am not sure that was the issue. If I take out these lines:

***************
public double RestockFee() // Method to set the Restocking fee
{
return value() * 0.05;
} // end
***************
public double setRestockFee() // Method to set the Restocking fee
{
return value() * 0.05;
}
public double getRestockFee() // Method to set the Restocking fee
{
return value() * 0.05;
}


Code will run fine.
Jul 30 '07 #7
r035198x
13,262 8TB
I am not sure that was the issue. If I take out these lines:

***************
public double RestockFee() // Method to set the Restocking fee
{
return value() * 0.05;
} // end
***************
public double setRestockFee() // Method to set the Restocking fee
{
return value() * 0.05;
}
public double getRestockFee() // Method to set the Restocking fee
{
return value() * 0.05;
}


Code will run fine.
Where is the definition for the method value() ?
Jul 30 '07 #8
madhoriya22
252 100+
I am not sure that was the issue. If I take out these lines:

***************
public double RestockFee() // Method to set the Restocking fee
{
return value() * 0.05;
} // end
***************
public double setRestockFee() // Method to set the Restocking fee
{
return value() * 0.05;
}
public double getRestockFee() // Method to set the Restocking fee
{
return value() * 0.05;
}


Code will run fine.
Hi,
luk at ur getRestockFee() method again........ here u r calling value method in ur return statement..... but there is no value method in ur class.....thats why compiler is not able to resolve it... it is not wise to remove the lines where u r getting errors...... instead u should think what u need to resolve this error.... I think r035198x has given u the answer.....define value() method in ur class

thanks and regards,
madhoriya
Jul 30 '07 #9
JosAH
11,448 Expert 8TB
I find those previous error diagnostics very suspicious:

Expand|Select|Wrap|Line Numbers
  1. Product.java:61 cannot find symbol
  2. symbol : method value<>
  3. location: class product
  4. return value<> * 0.05;
  5.  
Look at those angular brackets while the code itself seems to use ordinary
parentheses. Something's rotten in the state of Denmark here.

kind regards,

Jos
Jul 30 '07 #10
r035198x
13,262 8TB
I find those previous error diagnostics very suspicious:

Expand|Select|Wrap|Line Numbers
  1. Product.java:61 cannot find symbol
  2. symbol : method value<>
  3. location: class product
  4. return value<> * 0.05;
  5.  
Look at those angular brackets while the code itself seems to use ordinary
parentheses. Something's rotten in the state of Denmark here.

kind regards,

Jos
Looks suspicious indeed.
I ignored it thinking that maybe the OP is using a funny text editor that uses different characters for normal code pages and error output windows.
Jul 30 '07 #11
madhoriya22
252 100+
Looks suspicious indeed.
I ignored it thinking that maybe the OP is using a funny text editor that uses different characters for normal code pages and error output windows.
Hi,
I thought he has written the errors himself instead of just copy pasting it......that why he has done the typing mistake..... not so sure ? bcoz my compiler is showing it right..
Expand|Select|Wrap|Line Numbers
  1. product.java:60: Method value() not found in class product.
  2.         return value() * 0.05;
  3.                     ^
  4.  
Thanks and regards,
madhoriya
Jul 30 '07 #12
Hi,
I thought he has written the errors himself instead of just copy pasting it......that why he has done the typing mistake..... not so sure ? bcoz my compiler is showing it right..
Expand|Select|Wrap|Line Numbers
  1. product.java:60: Method value() not found in class product.
  2.         return value() * 0.05;
  3.                     ^
  4.  
Thanks and regards,
madhoriya
In reguards to the fishy smell, cant help you with that. Try lysol. About the error. I have been trying to compile from the bin folder using the comand prompt. Since I am unaware how to copy and paste from the CMD, I just typed it out.

I am very new to this and my work computer will not let me install the jdk on it without admin access. I could install it if I REALLY needed to, but it is not worth getting in trouble over. =)
Jul 30 '07 #13
r035198x
13,262 8TB
In reguards to the fishy smell, cant help you with that. Try lysol. About the error. I have been trying to compile from the bin folder using the comand prompt. Since I am unaware how to copy and paste from the CMD, I just typed it out.

I am very new to this and my work computer will not let me install the jdk on it without admin access. I could install it if I REALLY needed to, but it is not worth getting in trouble over. =)
Eh, do you mean to say that you compiled that code without the JDK?

Try using Textpad. You can compile and run certain programs from it.

P.S Are the errors gone now?
Jul 30 '07 #14
JosAH
11,448 Expert 8TB
In reguards to the fishy smell, cant help you with that. Try lysol.
Lol!

kind regards,

Jos :-)
Jul 30 '07 #15
r035198x
13,262 8TB
Lol!

kind regards,

Jos :-)
I just googled it.
Silly me
Jul 30 '07 #16
You googled Lysol? Funny....
For some reason I am having troubles with TextPad and the way it complies on my home computer. My laptop works just fine, but I can not use it at work. My work computer does not have permission to install the JDK files and its not worth "tweeking" it at the moment. So, I need to wait until I get home unless you have a way of doing it without requireing the Admin password.

About the complie stuff. Since my computer has issues, I copy the *.java files into the bin folder of the JDK and then compile from the comand prompt by changing the directory to the bin file and typing javac *.java. This will compile all the java files and give me the *.class files. Then, I can just fire the java files from the cmd too. Does that make sence?
Jul 30 '07 #17
JosAH
11,448 Expert 8TB
About the complie stuff. Since my computer has issues, I copy the *.java files into the bin folder of the JDK and then compile from the comand prompt by changing the directory to the bin file and typing javac *.java. This will compile all the java files and give me the *.class files. Then, I can just fire the java files from the cmd too. Does that make sence?
It sort of works but you shouldn't do it like that: add the name of that bin directory
to your 'path' environment variable and store your .java sources and .class files
somewhere else in their own directory. You don't pollute that bin directory then.

kind regards,

Jos
Jul 31 '07 #18
Hi,
luk at ur getRestockFee() method again........ here u r calling value method in ur return statement..... but there is no value method in ur class.....thats why compiler is not able to resolve it... it is not wise to remove the lines where u r getting errors...... instead u should think what u need to resolve this error.... I think r035198x has given u the answer.....define value() method in ur class

thanks and regards,
madhoriya
Ok, so should this be defined in the current class which it resides in or should it be designed in the public main class?
Jul 31 '07 #19
r035198x
13,262 8TB
Ok, so should this be defined in the current class which it resides in or should it be designed in the public main class?
See one of your error messages again:

Expand|Select|Wrap|Line Numbers
  1.  Product.java:61 cannot find symbol
  2. symbol  : method value<>
  3. location: class product
  4.       return value<> * 0.05;
Jul 31 '07 #20
Ok, so now I am getting just one error.
Again just typing out manually.
product.java:8: ';' expected
^
1 error

Here is what I changed

Expand|Select|Wrap|Line Numbers
  1. class product implements Comparable 
  2. {
  3. private String productName; // class variable that stores the item name
  4. private int itemNumber; // class variable that stores the item number
  5. private double unitProduct; // class variable that stores the quantity in stock
  6. private double priceProduct; // class variable that stores the item price
  7. private double restockfee
  8.  
  9.  
  10. /** Creates a new instance of product */
  11. public product() // Constructor for Product class
  12. {
  13. productName = "";
  14. itemNumber = 0;
  15. unitProduct = 0.0;
  16. priceProduct = 0.0;
  17. restockfee = 0.00;
  18. }
  19. public product( String productName, int itemNumber, double unitProduct, double priceProduct) // Constructor for myProduct class
  20. {
  21. this.productName = productName;
  22. this.itemNumber = itemNumber;
  23. this.unitProduct = unitProduct;
  24. this.priceProduct = priceProduct;
  25. this.restockfee = restockfee;
  26. }
  27.  
  28. public void setProductName(String name) // Method to set the item name
  29. {
  30. this.productName = productName;
  31. }
  32. public String getProductName() // Method to get the item name
  33. {
  34. return productName;
  35. }
  36. public void setItemNumber(int number) // Method to set the item number
  37. {
  38. this.itemNumber = itemNumber;
  39. }
  40. public int getItemNumber() // Method to get the item name
  41. {
  42. return itemNumber;
  43. }
  44. public void setUnitProduct(double unit) // Method to set the item number
  45. {
  46. this.unitProduct = unitProduct;
  47. }
  48. public double getUnitProduct() // Method to get the item name
  49. {
  50. return unitProduct;
  51. }
  52. public void setPriceProduct(double price) // Method to set the item number
  53. {
  54. this.priceProduct = priceProduct;
  55. }
  56. public double getPriceProduct() // Method to get the item name
  57. {
  58. return priceProduct;
  59. }
  60. public double setRestockFee() // Method to set the Restocking fee
  61. {
  62. return value() * 0.05;
  63. }
  64. public double getRestockFee() // Method to set the Restocking fee
  65. {
  66. return value() * 0.05;
  67. }
  68.  
  69.  
  70. // Calculation method
  71. public double itemCalculate()
  72. return unitProduct * priceProduct; // multiply for total for each item
  73.  
  74. } // end calculation
  75. public int compareTo (Object o) // use the compareTo method
  76. {
  77. product p = (product)o;
  78. return productName.compareTo(p.getProductName());
  79. }
  80. public double RestockFee() // Method to set the Restocking fee
  81. {
  82. return value() * 0.05;
  83. } // end 
  84.  
  85. }//end class Supplies
  86.  
Aug 1 '07 #21
madhoriya22
252 100+
Ok, so now I am getting just one error.
private double unitProduct; // class variable that stores the quantity in stock
private double priceProduct; // class variable that stores the item price
private double restockfee


/** Creates a new instance of product */
public product() // Constructor for Product class
{
productName = "";
itemNumber = 0;
unitProduct = 0.0;
priceProduct = 0.0;
restockfee = 0.00;
}
public product( String productName, int itemNumber, double unitProduct, double priceProduct) // Constructor for myProduct class
{
this.productName = productName;
this.itemNumber = itemNumber;
this.unitProduct = unitProduct;
this.priceProduct = priceProduct;
this.restockfee = restockfee;
}

public void setProductName(String name) // Method to set the item name
{
this.productName = productName;
}
public String getProductName() // Method to get the item name
{
return productName;
}
public void setItemNumber(int number) // Method to set the item number
{
this.itemNumber = itemNumber;
}
public int getItemNumber() // Method to get the item name
{
return itemNumber;
}
public void setUnitProduct(double unit) // Method to set the item number
{
this.unitProduct = unitProduct;
}
public double getUnitProduct() // Method to get the item name
{
return unitProduct;
}
public void setPriceProduct(double price) // Method to set the item number
{
this.priceProduct = priceProduct;
}
public double getPriceProduct() // Method to get the item name
{
return priceProduct;
}
public double setRestockFee() // Method to set the Restocking fee
{
return value() * 0.05;
}
public double getRestockFee() // Method to set the Restocking fee
{
return value() * 0.05;
}
[/code]
Hi,
put a semicolon at the end of this line.....
Expand|Select|Wrap|Line Numbers
  1. private double restockfee
  2.  
like this
Expand|Select|Wrap|Line Numbers
  1. private double restockfee;
  2.  
Thanks and regards,
madhoriya
Aug 1 '07 #22
ok, so now I am going in circles.....
Back to three errors
Aug 2 '07 #23
madhoriya22
252 100+
ok, so now I am going in circles.....
Back to three errors
Hi,
What are the errors....?

Thanks and regards,
madhoriya
Aug 2 '07 #24
Product.java:61 cannot find symbol
symbol : method value<>
location: class product
return value<> * 0.05;

Product.java:65 cannot find symbol
symbol : method value<>
location: class product
return value<> * 0.05;

Product.java:82 cannot find symbol
symbol : method value<>
location: class product
return value<> * 0.05;

3 errors
Aug 2 '07 #25
Heres what someone pointed out to me.

And your problem is that you did not and still have not defined a value() method. Typically, methods need to exist before you use them
Aug 2 '07 #26
JosAH
11,448 Expert 8TB
Heres what someone pointed out to me.
And your problem is that you did not and still have not defined a value() method. Typically, methods need to exist before you use them
That is ever so true; I tried to find the definition of the value() method in your
post but it was nowhere to be found. Define a method value() in your class:

Expand|Select|Wrap|Line Numbers
  1. double value() {
  2.    return //whatever it has to return
  3. }
  4.  
and try again.

kind regards,

Jos
Aug 2 '07 #27
That is ever so true; I tried to find the definition of the value() method in your
post but it was nowhere to be found. Define a method value() in your class:

Expand|Select|Wrap|Line Numbers
  1. double value() {
  2.    return //whatever it has to return
  3. }
  4.  
and try again.

kind regards,

Jos

Now I can not take all the credit as my teacher has done most of the work.

Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2.  
  3. public class Company extends product implements Comparable
  4. {
  5.     private String developer;
  6.     //double total;
  7.  
  8.     /** Creates a new instance of Company */
  9.     public Company()
  10.     {
  11.         super();
  12.         String developer ="";
  13.         //total =0.0;
  14.     }
  15.     public Company(String productName, int itemNumber, double unitProduct, double priceProduct, String developer)
  16.     {
  17.         super(productName, itemNumber, unitProduct, priceProduct);
  18.         this.developer = developer;
  19.     }
  20.  
  21.         public void setDeveloper( String developer)
  22.          {
  23.             this.developer = developer;
  24.          }
  25.         public String getDeveloper()
  26.          {
  27.             return developer;
  28.          }
  29.  
  30.         public double itemCalculate()
  31.         {
  32.             return (super.itemCalculate()*.05)+super.itemCalculate();
  33.         }
  34.  
  35.         public int compareTo (Object o) // use the compareTo method
  36.         {
  37.             product p = (product)o;
  38.             return productName.compareTo(p.getProductName());
  39.         }
  40.  
  41.         public String toString()
  42.         {
  43.          return super.toString()+ "\nCompany: "+ developer +"\nPrice with restock fee: $"+itemCalculate();
  44.         }
  45. }
  46.  

Expand|Select|Wrap|Line Numbers
  1. import java.util.*; // program uses class Scanner
  2.  
  3. public class Inventory 
  4. {    
  5.     // main method begins execution of Java application
  6.    public static void main( String args[]) 
  7.    {    
  8.       product[] myProduct = new product[5];
  9.       //Company[] myCompany = new Company[5];
  10.  
  11.         product p1 = new Company("Mad Dash", 20003, 5, 30, "EIDOS");
  12.         product p2 = new Company("Fuzion Frenzy", 74512, 2, 10, "MicroSoft");
  13.         product p3 = new Company("Time Splitters 2", 20009, 3, 45, "EIDOS");
  14.         product p4 = new Company("Night Caster", 74522, 8, 5, "MicroSoft");
  15.         product p5 = new Company("Lego Star Wars II", 32976, 1, 50, "LucasArts");
  16.  
  17.         myProduct[0] = p1;
  18.         myProduct[1] = p2;
  19.         myProduct[2] = p3;
  20.         myProduct[3] = p4;
  21.         myProduct[4] = p5;
  22.  
  23.         double totalValue = 0.0;
  24.  
  25.         for (int c=0; c < 5; c++)
  26.         {
  27.             totalValue = totalValue + myProduct[c].itemCalculate();
  28.         }
  29.  
  30.         Arrays.sort(myProduct); // function used to sort arrays
  31.  
  32.         for(product p: myProduct)
  33.         {
  34.             System.out.println(p);
  35.             System.out.println();
  36.         }
  37.        System.out.println("Total Inventory value is: $"+totalValue);
  38.  
  39.    } //end main
  40.  
  41. } //end Inventory
  42.  
  43.  
  44.  


Expand|Select|Wrap|Line Numbers
  1. import java.util.*; // program uses any class available
  2.  
  3. class product implements Comparable
  4. {
  5.    public String productName; // class variable that stores the item name
  6.    private int itemNumber; // class variable that stores the item number
  7.    private double unitProduct; // class variable that stores the quantity in stock
  8.    private double priceProduct; // class variable that stores the item price
  9.  
  10.     /** Creates a new instance of product */
  11.     public product() // Constructor for Product class
  12.      {
  13.         productName = "";
  14.         itemNumber = 0;
  15.         unitProduct = 0.0;
  16.         priceProduct = 0.0;
  17.      }
  18.     public product( String productName, int itemNumber, double unitProduct, double priceProduct) // Constructor for myProduct class
  19.     {
  20.         this.productName = productName;
  21.         this.itemNumber = itemNumber;
  22.         this.unitProduct = unitProduct;
  23.         this.priceProduct = priceProduct;
  24.     }
  25.  
  26.       public void setProductName(String name)  // Method to set the item name
  27.        {
  28.          this.productName = productName;
  29.        }
  30.       public String getProductName()  // Method to get the item name
  31.        {
  32.          return productName;
  33.        }
  34.       public void setItemNumber(int number)  // Method to set the item number
  35.        {
  36.          this.itemNumber = itemNumber;
  37.        }
  38.       public int getItemNumber()  // Method to get the item name
  39.        {
  40.          return itemNumber;
  41.        }
  42.        public void setUnitProduct(double unit)  // Method to set the item number
  43.        {
  44.          this.unitProduct = unitProduct;
  45.        }
  46.       public double getUnitProduct()  // Method to get the item name
  47.        {
  48.          return unitProduct;
  49.        }
  50.        public void setPriceProduct(double price)  // Method to set the item number
  51.        {
  52.          this.priceProduct = priceProduct;
  53.        }
  54.       public double getPriceProduct()  // Method to get the item name
  55.        {
  56.          return priceProduct;
  57.        }
  58.  
  59. // Calculation method
  60.   public double itemCalculate()
  61.    {
  62.         return unitProduct * priceProduct; // multiply for total for each item
  63.  
  64.    } // end calculation
  65.   public int compareTo (Object o) // use the compareTo method
  66.     {
  67.       product p = (product)o;
  68.          return productName.compareTo(p.getProductName());
  69.     }
  70.  
  71.   public String toString() // displays products
  72.   {
  73.       return "Title: "+productName+
  74.               "\nBarcode: "+itemNumber+
  75.               "\nNumber of Xbox games: "+(int)unitProduct+
  76.               "\nPrice: $"+priceProduct+
  77.               "\nTotal: $"+itemCalculate();
  78.    } // end toString
  79.  
  80.  
  81. }//end class Supplies
  82.  
  83.  
  84.  
Aug 3 '07 #28
That is ever so true; I tried to find the definition of the value() method in your
post but it was nowhere to be found. Define a method value() in your class:

Expand|Select|Wrap|Line Numbers
  1. double value() {
  2.    return //whatever it has to return
  3. }
  4.  
and try again.

kind regards,

Jos
Ok, so what is the best method in proceeding to add the GUI to this?
Aug 5 '07 #29
JosAH
11,448 Expert 8TB
Ok, so what is the best method in proceeding to add the GUI to this?
I don't know; I don't know what sort of GUI you have in mind. Have you read
about the Swing framework? Look here.

kind regards,

Jos
Aug 5 '07 #30
no1zson
38
Ok, so what is the best method in proceeding to add the GUI to this?

I just went through that class. Get ready to rewrite your entire primary class.
It is fun. :o)
Aug 5 '07 #31

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Jamie Fryatt | last post by:
Hi everyone, here's what id like to do. I have a table with 2 fields, name and value I need to be able to add multiple records quickly, for example I need to add name value abc 1...
10
by: sp0 | last post by:
Is there a reason why to make mix numbers improper when adding? It seems when subtracting and adding, adding a subtracting the whole numbers and fraction parts should be sufficient? what'ch think
1
by: hzgt9b | last post by:
When adding my VB .NET solution (with two sub-projects) the folder structure in VSS gets an extra level of folders... For example, here's the structure of the solution on my C:\...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
3
by: Robin Thomas | last post by:
I am fairly new to ASP.NET so I think I am missing something fundamental. Anyway, quite often I am pulling data from a database, but then I need to use that data to produce more data. A simple...
0
by: Sileesh | last post by:
Hi I have html table and a Button in an Aspx page. I am adding one row with some textboxes to Html table each time i click on the Button thru Javascript. Now problem is when when i try to...
0
by: porky008 | last post by:
I need to add a search button to this and have no clue how to do it. Can some one please help me on this? import java.awt.*; import java.awt.event.*; import javax.swing.*; import...
9
by: Kadett | last post by:
Hi all, I have following problem: I'm creating a ListView (Details) control at run-time and filling it with some records (let's say 10 000). This operation seems to be quite fast, but when I call...
0
by: AndyL69 | last post by:
Hello I've got a very strange Problem. When im adding a new ACE entry to a UNC Direcotry the inherented ACL's will be lost. When I'm adding a new ACE to a directory / file in this UNC path the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.