PDA

View Full Version : Anyone know Java?



boywonder
10-06-2006, 01:47 AM
I need help with programming for an assignment in my class. If you are interested, PM me so we can get rolling.

boywonder
10-06-2006, 10:27 PM
This is the code I have so far:



import java.io.*;

import java.text.*;



class inventory

{

//initialize variables

String TextInput = ""

String Performer = ""

String RecordLabel = ""

String Genre = ""

String Studio = ""

String ParentalAdvisory = ""

String Price = ""



//initialize array

int array []; //declare array



inventory array = new int[ 10 ]; //create the space for array



System.out.printf( "%s%8s\n" , "Performer" , "RecordLabel" , "Genre", "Studio" , "ParentalAdvisory" ); // column headings





Errors:



Inventory.java:10: `;` expected

String Performer = ""

^

Inventory.java:22: <identifier> expected

System.out.printf( "%s%8s\n" , "Performer" , "RecordLabel" , "Genre", "Studio" , "ParentalAdvisory" ); // column headings



Instructions:



Choose a product that lends itself to an inventory (for example, products at your workplace, office supplies, music CDs, DVD movies, or software).

• Create a product class that holds the item number, the name of the product, the number of units in stock, and the price of each unit.

• Create a Java application that displays the product number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory (the number of units in stock multiplied by the price of each unit). Pay attention to the good programming practices in the text to ensure your source code is readable and well documented.



I am really stuck!!

Black240SX
10-06-2006, 11:16 PM
This is the code I have so far:



import java.io.*;

import java.text.*;



class inventory

{

//initialize variables

String TextInput = ""

String Performer = ""

String RecordLabel = ""

String Genre = ""

String Studio = ""

String ParentalAdvisory = ""

String Price = ""



//initialize array

int array []; //declare array



inventory array = new int[ 10 ]; //create the space for array



System.out.printf( "%s%8s\n" , "Performer" , "RecordLabel" , "Genre", "Studio" , "ParentalAdvisory" ); // column headings





Errors:



Inventory.java:10: `;` expected

String Performer = ""

^

Inventory.java:22: <identifier> expected

System.out.printf( "%s%8s\n" , "Performer" , "RecordLabel" , "Genre", "Studio" , "ParentalAdvisory" ); // column headings



Instructions:



Choose a product that lends itself to an inventory (for example, products at your workplace, office supplies, music CDs, DVD movies, or software).

• Create a product class that holds the item number, the name of the product, the number of units in stock, and the price of each unit.

• Create a Java application that displays the product number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory (the number of units in stock multiplied by the price of each unit). Pay attention to the good programming practices in the text to ensure your source code is readable and well documented.



I am really stuck!!



lol, ok, I`ll help a bit.



You need a semicolon at the end of each statement. So the field declarations in your class should look like:

String performer;

NB: the convention is to start the field name with a lower case letter.



The price could be represented as a String, though an "int" with the price in cents would make math easier.



I`m not sure what you intend to use TextInput for.



You`ll need to define a constructor for your class. This is a function that gets called to initialize the fields when you create an instance of your class.



You need to end the definition of your Inventory class with a "}". NB: The convention is to start class names with an upper case letter. Also, "Product" might be a more meaningful name for the class.



An array declaration looks like this:

Product[] inventory = new Product[10];

boywonder
10-08-2006, 05:59 PM
Black240: :thx: for the help