problems with arrays program
public class Item
{
private String description; //variable to store the name
private double dCost; //variable to store the price
//Constructor to set the item
//Data members description and dCost are set according to the parameters
//Postcondition: description = name; dCost = price;
public Item(String names, double costs)
{
names = description;
costs = dCost;
}
//Method to return the name
//Postcondition: The value of description is returned
public String getName()
{
return description;
}
//Method to return the price
//Postcondition: The value of dCost is returned
public double getPrice()
{
return dCost;
}
//Method to set the item
//Data members description and dCost are set according to the parameters
//Postcondition: description = name; dCost = price;
public void setItem(String names, double costs)
{
description = names;
dCost = costs;
}
//Method to print the name of the item
public String printName()
{
return (description);
}
//Method to print the price of the item
public double printPrice()
{
return (dCost);
}
//Method to print the Item
public String printItem()
{
return (description + " " + dCost);
}
}
Derived class:
public class MallItem extends Item
{
private Item []names;
private Item []costs;
private int mallStoreNumber;
public MallItem(String names, double costs, int stores)
{
super(names, costs);
mallStoreNumber = stores;
}
public void printInfo()
{
System.out.println(super.toString());
System.out.println(mallStoreNumber);
}
public void setInfo(String names, double costs, int stores)
{
super.setItem(names,costs);
mallStoreNumber = stores;
}
public int getStoreNumber()
{
return mallStoreNumber;
}
public void setMallStoreNumber(int stores)
{
mallStoreNumber = stores;
}
}
import java.io.*;
public class MallList
{
private int length;
int maxSize = 5;
private Item[] names;
private Item[] costs;
private MallItem list[];
public MallList(String[] names, double[] costs, int[] stores)
{
list = new MallItem[5];
for(int i = 0; i < 5; i++)
list[i] = null;
length = 0;
}
public void print()
{
for(int i = 0; i < list.length;i++)
{
list[i].printInfo();
}
}
public boolean isFull()
{
return (length == maxSize);
}
public void insert(MallItem mI)
{
list[length] = mI;
length++;
}
}
Testing class
import java.io.*;
public class TestListStudent
{
public static void main (String [] args)
{
String[] names = {"jeans", "shirt", "boots"};
double[] costs = {39.99, 24.75, 105.00};
int[] stores = {16, 29, 3};
MallList listOne = new MallList(names, costs, stores);
System.out.println("Is the list full? " + listOne.isFull());//check to see if list is full
listOne.print();
}
}
Can someone please tell me what I'm doing wrong or give me examples to give me ideas on how to correct what I'm doing wrong. I know I must not be setting the array objects up right. Not sure if my constructor is right in my MallList class.
I have much more to do to this program...I just want to get to a point where it is printing the items out as follows:(formatting need not be an issue, I already know how to do that.)
jeans 39.99 16
shirt 24.75 29
boots 105.00 3

