public class Mall { private final int NUM_STORES = 2; private String name; Store
ID: 3739507 • Letter: P
Question
public class Mall {
private final int NUM_STORES = 2;
private String name;
Store[] storeList;
public Mall()
{
storeList = new Store[NUM_STORES];
}
//TODO 01: create a setter for name
//TODO 02: create a setter for a store in location i
//TODO 03: create a getter for a store in location i
//TODO 15: override toString to represent the mall as follows:
/*
* Mall Name:
* Store 1:
* Name: <store name>
* Type: <store type> (Grocery or Restaurant)
* Rating or itemList
* Store 2:
* Name: <store name>
* Type: <store type> (Grocery or Restaurant)
* Rating or itemList
*/
}
____________________________________________________________________
public class GroceryStore {
private String[] items;
private final int MAX_ITEMS = 3;
//TODO 05: create a constructor that initializes all instance variables.
//TODO 06: create a setter for an item in location i
//TODO 07: create a getter for the item in location i
}
__________________________________________________________________
public class RestaurantStore {
private int rating;
//TODO 08: create a constructor that initializes all variables
}
Explanation / Answer
public class Mall {
private final int NUM_STORES = 2;
private String name;
Store[] storeList;
public Mall()
{
storeList = new Store[NUM_STORES];
}
//TODO 01: create a setter for name
public void setName(String nme)
{
name = nme;
}
//TODO 02: create a setter for a store in location i
public void setItem(int i, String name, String type, int rating)
{
if(i < NUM_STORES)
{
items[i].setName(name);
items[i].setType(type);
items[i].setRating(rating);
}
else
{
System.out.println("Index " + i + " is out of range");
}
}
//TODO 03: create a getter for a store in location i
public Store setItem(int i)
{
if(i < NUM_STORES)
{
return storeList[i];
}
else
{
System.out.println("Index " + i + " is out of range");
}
}
//TODO 15: override toString to represent the mall as follows:
public String toString()
{
String result = "Mall name: " + name;
for (int i; i < NUM_STORES; i++ )
{
result = result + " Store " + (i+1) + ": Name: "+ storeList[i].getName() + " Type: " + storeList[i].getType() + " Rating: " + storeList[i].getRating();
}
}
/*
* Mall Name:
* Store 1:
* Name: <store name>
* Type: <store type> (Grocery or Restaurant)
* Rating or itemList
* Store 2:
* Name: <store name>
* Type: <store type> (Grocery or Restaurant)
* Rating or itemList
*/
}
public class GroceryStore {
private String[] items;
private final int MAX_ITEMS = 3;
//TODO 05: create a constructor that initializes all instance variables.
public GroceryStore()
{
for (int i ; i < 3 ; i++ )
{
items[i] = "";
}
}
//TODO 06: create a setter for an item in location i
public void setItem(int i, String itemname)
{
if(i < MAX_ITEMS)
{
items[i] = itemname;
}
else
{
System.out.println("Index " + i + " is out of range");
}
}
//TODO 07: create a getter for the item in location i
public String getItem(int i)
{
if(i < MAX_ITEMS)
{
return items[i] ;
}
else
{
System.out.println("Index " + i + " is out of range");
}
}
}
public class RestaurantStore {
private int rating;
//TODO 08: create a constructor that initializes all variables
public RestaurantStore()
{
rating = 0;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.