/* * Main.java * * Created: February 27, 2005 * By: Stan Sclaroff * Description: Main class to help test methods developed for * CS111 Spring 05 Programming Assignment 4 * */ package program4; public class Main { /** Creates a new instance of Main */ public Main() { } public static void main(String[] args) { // create an empty grocery list MyGroceryList g = new MyGroceryList(); // add some items g.addItem("Orange",5,10); g.addItem("Apple",12,6); g.addItem("Tofu",5,200); g.addItem("Spinach",2,50); g.addItem("Rice cake",4,60); g.addItem("Rice",1,50); g.addItem("Apple juice",2,190); g.addItem("Apple pie",1,400); g.addItem("Ice cream",1,325); g.addItem("Egg", 12, 20); g.addItem("Olive oil", 1, 900); // test finding some items GroceryItem item; // items that we will try to find String[] names = {"egg", "rice cake", "apple", "banana", "olive"}; // whether or not each item is really in our list boolean[] inList = {true,true,true,false,false}; for(int i=0;i<5;++i){ item = g.getItem(names[i]); System.out.println("Try to find item named " + names[i]); System.out.println("Correct answer: This item " + ((inList[i]) ? "is" : "is not") + " in list."); if(item == null) System.out.println("Your method did not find item in list"); else System.out.println("Your method found item named " + item.getName()); } // test finding the most expensive item = g.getMostExpensive(); System.out.println("Most expensive item is Olive Oil"); if(item == null) System.out.println("Your method returned null (error)"); else System.out.println("Your method reported: " + item.getName()); // test computing total cost System.out.println("Total cost of list is 3757 units"); System.out.println("Your method reported: " + g.getTotalCost()); // test sorting the list alphabetically MyGroceryList gSorted = g.sortAlphabeticalOrder(); if(gSorted == null) System.out.println("Your method returned null for alpha sort (error)"); else{ System.out.println("Your method for alpha sort of the list produced:"); gSorted.output(); } } }