473,324 Members | 2,248 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,324 software developers and data experts.

Is anyone there that can help with a couple simple Java program exersizes?

Please-if anyone is online that can help me with a couple beginner Java programs... I have spent all day looking at them and I just can't figure out what I need to do...

Please help!!
Nov 30 '06 #1
5 2121
sicarie
4,677 Expert Mod 4TB
Please-if anyone is online that can help me with a couple beginner Java programs... I have spent all day looking at them and I just can't figure out what I need to do...

Please help!!
Ummmm.........42!

(You didn't ask any questions - post your code, any error messages you are getting, and your questions - preferably one at a time - about your code; otherwise we can't help!)
Nov 30 '06 #2
Expand|Select|Wrap|Line Numbers
  1. //Inventory.java
  2. //Class created to store item information for Inventory purposes
  3. //Created November 15, 2006
  4. //Modified November 29, 2006
  5. //Audrey A. Paige
  6. //IT315
  7.  
  8. class Product
  9. {
  10.    private String name;     // class variable that stores the item name
  11.    private int number;      // class variable that stores the item number
  12.    private long stockQuantity;   // class variable that stores the quantity in stock
  13.    private double price;      // class variable that stores the item price
  14.    public Product() // Constructor for the Supplies class
  15.    {
  16.       name = "";
  17.       number = 0;
  18.       stockQuantity = 0L;
  19.       price = 0.0;
  20.    }
  21.    public Product(String name, int number, long stockQuantity, double price) // Constructor for the Supplies class
  22.       {
  23.          this.name = name;
  24.          this.number = number;
  25.          this.stockQuantity = stockQuantity;
  26.          this.price = price;
  27.    }
  28.    public void setItemName(String name)  // Method to set the item name
  29.    {
  30.       this.name = name;
  31.    }
  32.    public String getItemName()  // Method to get the item name
  33.    {
  34.       return name;
  35.    }
  36.    public void setItemNumber(int number)  // Method to set the item number
  37.    {
  38.       this.number = number;
  39.    }
  40.    public int getItemNumber()  // Method to get the item number
  41.    {
  42.       return number;
  43.    }
  44.    public void setStockQuantity(long quantity)  // Method to set the quantity in stock
  45.    {
  46.       stockQuantity = quantity;
  47.    }
  48.    public long getStockQuantity()  // Method to get the quantity in stock
  49.    {
  50.       return stockQuantity;
  51.    }
  52.    public void setItemPrice(double price)  // Method to set the item price
  53.    {
  54.       this.price = price;
  55.    }
  56.    public double getItemPrice()  // Method to get the item price
  57.    {
  58.       return price;
  59.    }
  60.    public double calculateInventoryValue()  // Method to calculate the value of the inventory
  61.    {
  62.       return price * stockQuantity;
  63.    }
  64. }//end class Product
  65.  
  66. public class Inventory
  67. {
  68.    // main methods begins execution of java application
  69.    public static void main( String args[])
  70.    {
  71.     Product p = new Product("Pencil", 5460, 125, 1.5);
  72.     System.out.printf("\n\nItem Name: %s\n",p.getItemName()); //display item name
  73.     System.out.printf("Item Number: %s\n",p.getItemNumber()); //display item number
  74.     System.out.printf("Quantity in Stock: %s\n",p.getStockQuantity()); //display quantity in stock
  75.     System.out.printf("Item Price: $%.2f\n",p.getItemPrice()); //display item price
  76.     System.out.printf("Value of Inventory: $%.2f\n",p.calculateInventoryValue()); //display total value of inventory for this item
  77.  
  78.  
  79.    } // end main method
  80. }//end class Inventory
This is my Inventory program that works... I am trying to add an array and variables to the main method, and have the items display. Then I will need to sort them, but I can't even get the array to work...

Expand|Select|Wrap|Line Numbers
  1. //Inventory.java
  2. //Class created to store item information for Inventory purposes
  3. //Created November 15, 2006
  4. //Modified November 29, 2006
  5. //Audrey A. Paige
  6. //IT315
  7.  
  8. class Product
  9. {
  10.    private String name;     // class variable that stores the item name
  11.    private int number;      // class variable that stores the item number
  12.    private long stockQuantity;   // class variable that stores the quantity in stock
  13.    private double price;      // class variable that stores the item price
  14.    public Product() // Constructor for the Supplies class
  15.    {
  16.       name = "";
  17.       number = 0;
  18.       stockQuantity = 0L;
  19.       price = 0.0;
  20.    }
  21.    public Product(String name, int number, long stockQuantity, double price) // Constructor for the Product class
  22.       {
  23.          this.name = name;
  24.          this.number = number;
  25.          this.stockQuantity = stockQuantity;
  26.          this.price = price;
  27.    }
  28.    public void setItemName(String name)  // Method to set the item name
  29.    {
  30.       this.name = name;
  31.    }
  32.    public String getItemName()  // Method to get the item name
  33.    {
  34.       return name;
  35.    }
  36.    public void setItemNumber(int number)  // Method to set the item number
  37.    {
  38.       this.number = number;
  39.    }
  40.    public int getItemNumber()  // Method to get the item number
  41.    {
  42.       return number;
  43.    }
  44.    public void setStockQuantity(long quantity)  // Method to set the quantity in stock
  45.    {
  46.       stockQuantity = quantity;
  47.    }
  48.    public long getStockQuantity()  // Method to get the quantity in stock
  49.    {
  50.       return stockQuantity;
  51.    }
  52.    public void setItemPrice(double price)  // Method to set the item price
  53.    {
  54.       this.price = price;
  55.    }
  56.    public double getItemPrice()  // Method to get the item price
  57.    {
  58.       return price;
  59.    }
  60.    public double calculateInventoryValue()  // Method to calculate the value of the inventory
  61.    {
  62.       return price * stockQuantity;
  63.    }
  64.    public String toString()
  65.    {
  66.          return "Name :"+name + "\nNumber"+number+"\nPrice"+price+"\nQuantity"+stockQuantity + "\nValue"+calculateInventoryValue();
  67.    }
  68. }//end class Product
  69.  
  70. public class Inventory2
  71. {
  72.    // main methods begins execution of java application
  73.    public static void main( String args[])
  74.    {
  75.     String Products[] = new Products[3];
  76.     //instantiate Products array
  77.  
  78.     for (i=0; i<3; ++i)
  79.         pencil = new Products ("Pencil", 5460, 125, 1.5);
  80.  
  81.  
  82.     //Product p = new Product("Pencil", 5460, 125, 1.5);
  83.     //System.out.printf("\n\nItem Name: %s\n",products[pencil] + Product.getItemName()); //display item name
  84.     //System.out.printf("Item Number: %s\n",products.pencil.getItemNumber()); //display item number
  85.     //System.out.printf("Quantity in Stock: %s\n",products.pencil.getStockQuantity()); //display quantity in stock
  86.     //System.out.printf("Item Price: $%.2f\n",products.pencil.getItemPrice()); //display item price
  87.     //System.out.printf("Value of Inventory: $%.2f\n",products.pencil.calculateInventoryValue()); //display total value of inventory for this item
  88.  
  89.  
  90.    } // end main method
  91. }//end class Inventory2
  92.  
  93.  
Nov 30 '06 #3
sicarie
4,677 Expert Mod 4TB
Do you need to use an array? It looks like a Data Structure such as a Linked List would be more suited to your needs.

If you are set on arrays, here are some links that should help:

This will help correct your 'for' loop

And then this and this will help correct your array declaration / instantiation.
Nov 30 '06 #4
Do you need to use an array? It looks like a Data Structure such as a Linked List would be more suited to your needs.

If you are set on arrays, here are some links that should help:

This will help correct your 'for' loop

And then this and this will help correct your array declaration / instantiation.
It is not that I am set, but that is the assignment...
Dec 1 '06 #5
r035198x
13,262 8TB
It is not that I am set, but that is the assignment...
Last time I checked I had give you program that works with arrays like you are requesting right now.

http://www.thescripts.com/forum/thread570714.html
Dec 1 '06 #6

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

Similar topics

3
by: S C A | last post by:
Dear All: I'm not sure if this is even possible but does anyone know about using ActiveX controls (a Microsoft-specific technology) in Java? I am having a heck of a time finding some similar...
10
by: Dr. Mercury | last post by:
Greetings to all - Someone suggested that Java might be the answer for a little conversion program I need. It's pretty simple, really. Just take a column of numbers: 139 259 433 637
15
by: Brandon J. Van Every | last post by:
Is anyone using Python for .NET? I mean Brian's version at Zope, which simply accesses .NET in a one-way fashion from Python. http://www.zope.org/Members/Brian/PythonNet Not the experimental...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
133
by: Gaurav | last post by:
http://www.sys-con.com/story/print.cfm?storyid=45250 Any comments? Thanks Gaurav
7
by: Jim | last post by:
Hi people. I was hoping someone could help me as this is driving me up the wall. I'm trying to write a program that deals with matrix multiplication. The Program uses a couple of typedefined...
13
by: nigel.t | last post by:
I want to draw some fairly simple flow charts and process method charts to illustrate my PHP site and its local network operation. I dont need anything clever like code generation or stuff like...
1
by: mayurapink | last post by:
Hello, I've been banging my metaphorically banging my head again the wall all day attempting to use a simple servlet to connect to a db2 database and update a table. I eventually run into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.