473,397 Members | 1,949 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,397 software developers and data experts.

Inventory Program Troubles

I can not get this code right. I keep getting tons of errors and when I try to fix them, it just shows more errors.

Expand|Select|Wrap|Line Numbers
  1. import java.util.Arrays;
  2.  
  3. public class Fish{ 
  4.  
  5. public static void main( String args[] )
  6.    {
  7.       double total = 0.0;
  8.  
  9. public static final int MAXIMUM_ITEMS = 10;
  10.     product[] = new Fish();
  11.  
  12.  
  13.  
  14.     public Fish() {
  15.     buildInventory();
  16.  
  17. }
  18.  
  19.  
  20.         product[1] = new Fish(1, "Huma Huma Picasso Trigger", 2, 35.99);
  21.         product[2] = new Fish(2, "Black Durgeon Trigger",        1, 99.99);
  22.         product[3] = new Fish(3, "Niger Trigger",        2, 45.99);
  23.         product[4] = new Fish(4, "Jack Dempsey Cichlid", 4, 19.99);
  24.         product[5] = new Fish(5, "Midas Cichlid",        1, 69.99);
  25.         product[6] = new Fish(6, "Neon Tetra",        25, 2.99);
  26.         product[7] = new Fish(7, "Convict Cichlid",        2, 15.99);
  27.         product[8] = new Fish(8, "Oscar", 4, 37.99);
  28.         product[9] = new Fish(9, "Albino Cory Cat",        1, 29.99);
  29.         product[10] = new Fish(10, "Fancy Tailed Guppy",        25, 4.99);
  30. {
  31.  
  32.  
  33.  
  34.         name                  = "";
  35.         identificationNumber  = 0;
  36.         unitsInStock          = 0;
  37.         unitPriceInDollars    = 0.0;
  38.  
  39.     }
  40.  
  41.     {
  42.  
  43.  
  44.         setName( nameIn );
  45.  
  46.  
  47.         setIdentificationNumber( identificationNumberIn );
  48.  
  49.  
  50.         setUnitsInStock( unitsInStockIn );
  51.  
  52.  
  53.         setUnitPriceInDollars( unitPriceInDollarsIn );
  54.  
  55.     }
  56.  
  57.     {
  58.         name = nameIn; 
  59.  
  60.     }
  61.  
  62.  
  63.  
  64.  
  65.     {
  66.  
  67.         identificationNumber = ( (identificationNumberIn >0) ? identificationNumberIn : 0 );
  68.     }
  69.  
  70.     setUnitsInStock ( ( unitsInStockIn ) );
  71.  
  72.  
  73.         unitsInStock = ( (unitsInStockIn > 0)?unitsInStockIn:0 );
  74.  
  75.     }
  76.  
  77.  
  78.     public void setUnitPriceInDollars( double unitPriceInDollarsIn )
  79.     {
  80.  
  81.         unitPriceInDollars = ( (unitPriceInDollarsIn > 0.0)?unitPriceInDollarsIn:0.0);
  82.  
  83.     }
  84.  
  85.  
  86.  
  87.     public String getName()
  88.     {
  89.         return ( name ); 
  90.  
  91.     } 
  92.  
  93.  
  94.     public int getIdentificationNumber()
  95.     {
  96.         return ( identificationNumber ); 
  97.  
  98.     }
  99.  
  100.  
  101.     public int getUnitsInStock()
  102.     {
  103.         return( unitsInStock );
  104.  
  105.     }
  106.  
  107.  
  108.     public double getUnitPriceInDollars()
  109.     {
  110.         return( unitPriceInDollars ); 
  111.  
  112.     }
  113.  
  114.  
  115.     public double stockValueInDollars()
  116.     {
  117.         return ( unitsInStock * unitPriceInDollars );
  118.  
  119.     }
  120.  
  121.     public static double totalInventoryValue (Product inventory[] )
  122.          {
  123.              double value = 0.0;
  124.              for (Product p: inventory)
  125.              {
  126.                  value += p.stockValueInDollars();
  127.              }
  128.              return (value);
  129.          }
  130.  
  131.  
  132.     public int compareTo (Object o)
  133.     {
  134.         String s2 = ((Product)o).name.toUpperCase();
  135.         String s1 = name.toUpperCase();
  136.         return ( s1.compareTo(s2) );
  137.  
  138.      } 
  139.  
  140.  
  141.  
  142.     public String toString()
  143.     {
  144.         String formatString = "Identification Number : %d\n";
  145.         formatString       += "Product               : %s\n";
  146.         formatString       += "Units In Stock        : %d\n";
  147.         formatString       += "Unit Price            : $%.2f\n";
  148.         formatString       += "Stock Value           : $%.2f\n\n";
  149.  
  150.         return (
  151.                  String.format(
  152.                                 formatString, identificationNumber, name, unitsInStock,
  153.                                 unitPriceInDollars, stockValueInDollars));
  154.  
  155.  
  156.  
  157.     }
  158.  
  159. }
  160.  
Aug 7 '07 #1
5 1221
r035198x
13,262 8TB
product[] = new Fish();
What is this line supposed to be doing?
Aug 7 '07 #2
JosAH
11,448 Expert 8TB
product[] = new Fish();
What is this line supposed to be doing?
The line above that line is a nono as well:

Expand|Select|Wrap|Line Numbers
  1. public static final int MAXIMUM_ITEMS = 10;
  2.  
That doesn't make sense (and isn't allowed) inside a method definition.

kind regards,

Jos
Aug 7 '07 #3
I was following the example from the teacher when I put those in. I took them out and I still am getting a lot of errors. Seems the more I work on the code and take stuff out, I get more and more errors.
Aug 7 '07 #4
madhoriya22
252 100+
I was following the example from the teacher when I put those in. I took them out and I still am getting a lot of errors. Seems the more I work on the code and take stuff out, I get more and more errors.
Hi,
what errors you are getting?

thanks and regards,
madhoriya
Aug 8 '07 #5
r035198x
13,262 8TB
I was following the example from the teacher when I put those in. I took them out and I still am getting a lot of errors. Seems the more I work on the code and take stuff out, I get more and more errors.
That is not the correct way to write code. Understand the code that you're trying to write not just guess the lines that will make it work.
Aug 8 '07 #6

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

Similar topics

13
by: royaltiger | last post by:
I am trying to copy the inventory database in Building Access Applications by John L Viescas but when i try to run the database i get an error in the orders form when i click on the allocate...
109
by: zaidalin79 | last post by:
I have a java class that goes for another week or so, and I am going to fail if I can't figure out this simple program. I can't get anything to compile to at least get a few points... Here are the...
0
by: south622 | last post by:
I'm taking a beginning Java course and I'm stuck in week eight of a nine week course. If anyone could help me I would greatly appreciate it. This assignment was due yesterday and each day I go past...
9
by: xxplod | last post by:
I am suppose to modify the Inventory Program so the application can handle multiple items. Use an array to store the items. The output should display the information one product at a time, including...
3
by: cblank | last post by:
I need some help if someone could help me. I know everyone is asking for help in java. But for some reason I'm the same as everyone else when it comes to programming in java. I have an inventory...
2
by: pinkf24 | last post by:
I cannot figure out how to add the following: Modify the Inventory Program to include an Add button, a Delete button, and a Modify button on the GUI. These buttons should allow the user to perform...
1
by: jcato77 | last post by:
I need help with a class project I'm working on, Below is my assignment and the code I have currently created. Assignment: Modify the Inventory Program by creating a subclass of the product class...
3
by: 100grand | last post by:
Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price...
2
by: blitz1989 | last post by:
Hello all, I'm new to this forum and Java and having a alot of problems understanding this language. I am working on an invetory program part 4. The assignment requirements are listed but the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.