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!!
5 2121
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!)
- //Inventory.java
-
//Class created to store item information for Inventory purposes
-
//Created November 15, 2006
-
//Modified November 29, 2006
-
//Audrey A. Paige
-
//IT315
-
-
class Product
-
{
-
private String name; // class variable that stores the item name
-
private int number; // class variable that stores the item number
-
private long stockQuantity; // class variable that stores the quantity in stock
-
private double price; // class variable that stores the item price
-
public Product() // Constructor for the Supplies class
-
{
-
name = "";
-
number = 0;
-
stockQuantity = 0L;
-
price = 0.0;
-
}
-
public Product(String name, int number, long stockQuantity, double price) // Constructor for the Supplies class
-
{
-
this.name = name;
-
this.number = number;
-
this.stockQuantity = stockQuantity;
-
this.price = price;
-
}
-
public void setItemName(String name) // Method to set the item name
-
{
-
this.name = name;
-
}
-
public String getItemName() // Method to get the item name
-
{
-
return name;
-
}
-
public void setItemNumber(int number) // Method to set the item number
-
{
-
this.number = number;
-
}
-
public int getItemNumber() // Method to get the item number
-
{
-
return number;
-
}
-
public void setStockQuantity(long quantity) // Method to set the quantity in stock
-
{
-
stockQuantity = quantity;
-
}
-
public long getStockQuantity() // Method to get the quantity in stock
-
{
-
return stockQuantity;
-
}
-
public void setItemPrice(double price) // Method to set the item price
-
{
-
this.price = price;
-
}
-
public double getItemPrice() // Method to get the item price
-
{
-
return price;
-
}
-
public double calculateInventoryValue() // Method to calculate the value of the inventory
-
{
-
return price * stockQuantity;
-
}
-
}//end class Product
-
-
public class Inventory
-
{
-
// main methods begins execution of java application
-
public static void main( String args[])
-
{
-
Product p = new Product("Pencil", 5460, 125, 1.5);
-
System.out.printf("\n\nItem Name: %s\n",p.getItemName()); //display item name
-
System.out.printf("Item Number: %s\n",p.getItemNumber()); //display item number
-
System.out.printf("Quantity in Stock: %s\n",p.getStockQuantity()); //display quantity in stock
-
System.out.printf("Item Price: $%.2f\n",p.getItemPrice()); //display item price
-
System.out.printf("Value of Inventory: $%.2f\n",p.calculateInventoryValue()); //display total value of inventory for this item
-
-
-
} // end main method
-
}//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... - //Inventory.java
-
//Class created to store item information for Inventory purposes
-
//Created November 15, 2006
-
//Modified November 29, 2006
-
//Audrey A. Paige
-
//IT315
-
-
class Product
-
{
-
private String name; // class variable that stores the item name
-
private int number; // class variable that stores the item number
-
private long stockQuantity; // class variable that stores the quantity in stock
-
private double price; // class variable that stores the item price
-
public Product() // Constructor for the Supplies class
-
{
-
name = "";
-
number = 0;
-
stockQuantity = 0L;
-
price = 0.0;
-
}
-
public Product(String name, int number, long stockQuantity, double price) // Constructor for the Product class
-
{
-
this.name = name;
-
this.number = number;
-
this.stockQuantity = stockQuantity;
-
this.price = price;
-
}
-
public void setItemName(String name) // Method to set the item name
-
{
-
this.name = name;
-
}
-
public String getItemName() // Method to get the item name
-
{
-
return name;
-
}
-
public void setItemNumber(int number) // Method to set the item number
-
{
-
this.number = number;
-
}
-
public int getItemNumber() // Method to get the item number
-
{
-
return number;
-
}
-
public void setStockQuantity(long quantity) // Method to set the quantity in stock
-
{
-
stockQuantity = quantity;
-
}
-
public long getStockQuantity() // Method to get the quantity in stock
-
{
-
return stockQuantity;
-
}
-
public void setItemPrice(double price) // Method to set the item price
-
{
-
this.price = price;
-
}
-
public double getItemPrice() // Method to get the item price
-
{
-
return price;
-
}
-
public double calculateInventoryValue() // Method to calculate the value of the inventory
-
{
-
return price * stockQuantity;
-
}
-
public String toString()
-
{
-
return "Name :"+name + "\nNumber"+number+"\nPrice"+price+"\nQuantity"+stockQuantity + "\nValue"+calculateInventoryValue();
-
}
-
}//end class Product
-
-
public class Inventory2
-
{
-
// main methods begins execution of java application
-
public static void main( String args[])
-
{
-
String Products[] = new Products[3];
-
//instantiate Products array
-
-
for (i=0; i<3; ++i)
-
pencil = new Products ("Pencil", 5460, 125, 1.5);
-
-
-
//Product p = new Product("Pencil", 5460, 125, 1.5);
-
//System.out.printf("\n\nItem Name: %s\n",products[pencil] + Product.getItemName()); //display item name
-
//System.out.printf("Item Number: %s\n",products.pencil.getItemNumber()); //display item number
-
//System.out.printf("Quantity in Stock: %s\n",products.pencil.getStockQuantity()); //display quantity in stock
-
//System.out.printf("Item Price: $%.2f\n",products.pencil.getItemPrice()); //display item price
-
//System.out.printf("Value of Inventory: $%.2f\n",products.pencil.calculateInventoryValue()); //display total value of inventory for this item
-
-
-
} // end main method
-
}//end class Inventory2
-
-
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.
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...
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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
|
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...
|
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...
|
by: Gaurav |
last post by:
http://www.sys-con.com/story/print.cfm?storyid=45250
Any comments?
Thanks
Gaurav
|
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...
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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...
|
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)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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
| |