I am doing an inventory control progam and trying to output a multiple array, I am getting an illegal conversion error java.lang.doubl e !d. Can somebody tell me what I am doing wrong or if there is another way?
Code:
/*
* Main.java
*
* Created on April 29, 2007, 6:57 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package inventory2;
/**
*
* @author SandK
*/
import java.util.*;
import java.text.*;
import java.lang.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.text.DecimalFormat;
public class Main
{ //declare variables
private static String Choice;
private static double movieTotal;
private static double movieValue;
private static double gameTotal;
private static double gameValue;
private static double appsTotal;
private static double appsValue;
private double movieNumber[][];
private double gameNumber[][];
private double appsNumber[][];
private Product[] stores;
double itemNumber[][];
static double value;
static double grandTotal;
public static void main(String[] args)
{//set values for multiple array
//assign empty set to clear final variable
double itemNumber[][] = { {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0} };
//assign values to Movie array
double movieNumber[][] = { {5,10,29.95}, {6,15,24.95}, {7,20,14.95},
{8,20,15.95} };
//assign values to Game array
double gameNumber[][] = { {9,10,229.95}, {10,5,199.95}, {11,4,4999.95},
{12,20,699.95} };
//assign value to Apps array
double appsNumber[][] = { {1,10,19.95}, {2,25,25.95}, {3,20,20.95},
{4,15,19.95} };
Main inventory = new Main();
{
Scanner input = new Scanner (System.in);
//Query user for inventory to view
System.out.println("Would you like to view the movies, games, or apps inventory?");
String userChoice = input.nextLine();
Choice = userChoice;
//Load values into array for movies selection
if( userChoice.equalsIgnoreCase("movies"))
{
//add new DVD's to inventory
//Create subclass objects for DVD subclass including style
inventory.addProduct(new DVD("White Noise", 1, 10, 19.95, "Action"));
inventory.addProduct(new DVD("Jeff Foxworthy", 2, 25, 25.95, "Comedy"));
inventory.addProduct(new DVD("Cars", 3, 20, 20.95, "Comedy"));
inventory.addProduct(new DVD("Monster-In-Law", 4, 15, 19.95, "Comedy"));
//assign multiple variable movieNumber[][] to
//itemNumber[][] for array output
for (int disc = 0; disc < itemNumber.length; disc++)
{
for(int column = 0; column < itemNumber[disc].length; column++)
{
itemNumber = movieNumber;
}
}
}
else if (userChoice.equalsIgnoreCase("games"))
{
//add new games to inventory
//Create subclass objects for Game subclass without style
inventory.addProduct(new Games("Command and Conquer", 5, 10, 29.95 ));
inventory.addProduct(new Games("Delta Force II", 6, 15, 24.95));
inventory.addProduct(new Games("Roller Coaster Tycoon", 7, 20, 14.95));
inventory.addProduct(new Games("Half-Life", 8, 20, 15.95));
//assign multiple variable gameNumber[][] to
//itemNumber[][] for array output
for (int disc = 0; disc < itemNumber.length; disc++)
{
for(int column = 0; column < itemNumber[disc].length; column++)
{
itemNumber = gameNumber;
}
}
}
else if (userChoice.equalsIgnoreCase("apps"))
{
//add new games to inventory
//Create subclass objects for Game subclass with style
inventory.addProduct(new Apps("Wiindows Vista 32 bit", 9, 10, 229.95,
"Operating System" ));
inventory.addProduct(new Apps("Windows Vista 64 bit", 10, 5, 199.95,
"Operating System"));
inventory.addProduct(new Apps("Autocad 2007", 11, 5, 4999.95, "Drafting"));
inventory.addProduct(new Apps("Microsoft Office 2007", 12, 20, 699.95,
"Business"));
//assign multiple variable appsNumber[][] to
//itemNumber[][] for array output
for (int disc = 0; disc < itemNumber.length; disc++)
{
for(int column = 0; column < itemNumber[disc].length; column++)
{
itemNumber = appsNumber;
}
}
}
//Determine individual totals for arrays to compute grand total
//Compute movie total from array for part of grand total
for (int disc = 0; disc < movieNumber.length; disc++)
{
for(int column = 0; column < movieNumber[disc].length; column++)
{
movieValue = movieNumber[disc][1] * itemNumber[disc][2];
movieTotal += movieValue;
}
}
//Compute game total from array for part of grand total
for (int disc = 0; disc < gameNumber.length; disc++)
{
for(int column = 0; column < gameNumber[disc].length; column++)
{
gameValue = gameNumber[disc][1] * itemNumber[disc][2];
gameTotal += gameValue;
}
}
//Compute apps total from array for part of grand total
for (int disc = 0; disc < appsNumber.length; disc++)
{
for(int column = 0; column < appsNumber[disc].length; column++)
{
appsValue = appsNumber[disc][1] * itemNumber[disc][2];
appsTotal += appsValue;
}
}
grandTotal = movieTotal + gameTotal + appsTotal;
}
System.out.println("Inventory of: ");
System.out.println(Choice);
System.out.println();
System.out.println();
//Call to superclass methods
inventory.displayInv();
inventory.nameSort();
System.out.println();
inventory.displayInv();
double total = inventory.totalInvCalc();
System.out.println("Total Value is: $" + total);
System.out.println();
System.out.println("The grand stock inventory value is: $");
System.out.println(grandTotal);
outputArray(itemNumber);
}
public static void outputArray(double itemNumber[][])
{
//Print Column headings and set spacing
System.out.printf("%5s%6s%5s%12s\n", "Disc", "Qty", "Cost", "Inv Value");
//Print values from array and set spacing between values
//set row (aka disc) and column to zero before starting
for (int disc = 0; disc < itemNumber.length; disc++)
{
for(int column = 0; column < itemNumber[disc].length; column++)
//print information from array
System.out.printf("%5d", itemNumber[disc][column]);
value = 0;
//determine next value
value = itemNumber[disc][1] * itemNumber[disc][2];
grandTotal += value;
//print next value
System.out.printf("%8d",value);
//Return to start new line
//Clear values before determing next value
System.out.println();
}
System.out.print("The total inventory value is: $");
System.out.println(grandTotal);
System.out.println();
}
// method to sort inventory by name
public void nameSort()
{
for (int i = 1; i < stores.length; i++)
{
int j;
Product val = stores[i];
for (j = i - 1; j > -1; j--)
{
Product temp = stores[j];
if (temp.compareTo(val) <= 0)
{
break;
}
stores[j + 1] = temp;
}
stores[j + 1] = val;
}
}
//method to create a String representation of array of class products
public String toString()
{
String s = "";
for (Product p : stores)
{
s = s + p.toString();
s = s + "\n\n";
}
return s;
}
//method to increase array size to add products
public void addProduct(Product p1)
{
if (stores == null)
{
stores = new Product[0];
}
//Copy all products into p first
Product[] p = stores;
//create bigger array
Product[] temp = new Product[p.length + 1];
//add the new product at the last position
for (int i = 0; i < p.length; i++)
{
temp[i] = p[i];
}
temp[(temp.length - 1)] = p1;
stores = temp;
}
//method to calculate Total Inventory Value
public double totalInvCalc()
{
double total = 0.0;
for (int i = 0; i < stores.length; i++)
{
total = total + stores[i].inventoryValue();
}
return total;
}
//method to display inventory
public void displayInv()
{
//call toString method
System.out.println(toString());
}
}
//Setup Products subclass to Main and superclass to DVD's
}
Comment