I must create a product class the hold and item #, Name, # of units, and price of each unit. It must then display all this information plus the results of the stock multiplied by the price. I must also use an array to store multiple items and display them one product at a time and the value of the entire inventory.
I haven’t gotten to the display portion of my assignment yet, because I’m still having problems getting the array to work.
I have been looking through “bigbluesky’s” post and I still can’t figure it out.
Could someone please help?
OH Yeah My latest error is "Incompatible Types"
import java.util.Scanner;
public class DVDArray
{
public static void main( String args[] )//Begin Program
{
Scanner input = new Scanner ( System.in );
int i;
Product myProduct = new Product[ 5 ];//Initiate DVD Array
for (i=0; i<5; ++i)
myProduct = new Product();
for (i=0; i<5; ++i) //Enter 5 DVD's
{
System.out.println( "Enter the DVD Title: ");
myProduct.setDVDName(input.next()); //read DVD Title
System.out.print( "Enter the DVD's Product #: ");
myProduct.setItemNumber(input.nextDouble());//read Product Number
while( myProduct.getItemNumber() <= 0.0 )//While loop requesting a positive number
{
System.out.println("Try Again");
System.out.println("Please Enter Only Positive Product #'s");
System.out.println( "Enter the DVD's Product #: ");
myProduct.setItemNumber(input.nextDouble());//read Product Number Again
}
System.out.print( "Enter the # of DVD's in Stock: ");
myProduct.setDVDStock(input.nextDouble());//read Stock #
while( myProduct.getDVDStock() <= 0.0 )//While loop requesting a positive number
{
System.out.println("Try Again");
System.out.println("Please Enter Only Positive Product #'s");
System.out.println("Enter the # of DVD's in Stock: ");
myProduct.setDVDStock(input.nextDouble());//read Product Number Again
}
System.out.print( "Enter the DVD's Price: ");
myProduct.setDVDPrice(input.nextDouble());//read Product Number
while( myProduct.getDVDPrice() <= 0.0 )//While loop requesting a positive number
{
System.out.println("Try Again");
System.out.println("Please Enter Only Positive Product #'s");
System.out.println( "Enter the DVD's Price: ");
myProduct.setDVDPrice(input.nextDouble());//read Product Number Again
}
}//End For
}
}
import java.util.Scanner; // Scanne class will be used in the program
class Product
{
private double itemNumber; // class variable that stores the Item Number
private double dvdStock; //class variable that stores the DVD's in stock
private double dvdPrice; //class variable that stores the DVD's price
private String dvdName; //class variable for the DVD Name
//public Product () // Constructor for Poduct class
{
itemNumber = 0.0;
dvdStock = 0.0;
dvdPrice = 0.0;
dvdName = "";
}
public void setItemNumber (double number) //Method to set Item Number
{
itemNumber = number;
}
public double getItemNumber () //Method to get Item Number
{
return itemNumber;
}
public void setDVDStock (double stock) //Method to set DVD's in Stock
{
dvdStock = stock;
}
public double getDVDStock () //Method to get DVD's in Stock
{
return dvdStock;
}
public void setDVDPrice (double price) //Method to set DVD's Price
{
dvdPrice = price;
}
public double getDVDPrice () //Method to get DVD's Price
{
return dvdPrice;
}
public void setDVDName (String name) //Method to set DVD's Name
{
dvdName = name;
}
public String getDVDName () //Method to get DVD's Name
{
return dvdName;
}
//public double calculateStockValue() //Method to calculate The value of the stock
//}
// return dvdStock * dvdPrice;
//}
}//end Product Class

New Topic/Question
Reply




MultiQuote






|