Question: (JAVA) if anyone can help with these following methods, following the instructions in the method header comments, would really appreciate it! also would really appreciate

(JAVA) if anyone can help with these following methods, following the instructions in the method header comments, would really appreciate it! also would really appreciate if you could write //comments next to the important steps explaining what you did!

// Define final parameters

private static final int CART_CAPACITY = 20; // shopping cart max capacity

private static final double TAX_RATE = 0.05; // sales tax

// a perfect-size two-dimensional array that stores the available items in the market

// MARKET_ITEMS[i][0] refers to a String that represents the description of the item

// identified by index i

// MARKET_ITEMS[i][1] refers to a String that represents the unit price of the item

// identified by index i in dollars.

public static final String[][] MARKET_ITEMS = new String[][] {{"Apple", "$1.59"},

{"Avocado", "$0.59"}, {"Banana", "$0.49"}, {"Beef", "$3.79"}, {"Blueberry", "$6.89"},

{"Broccoli", "$1.79"}, {"Butter", "$4.59"}, {"Carrot", "$1.19"}, {"Cereal", "$3.69"},

{"Cheese", "$3.49"}, {"Chicken", "$5.09"}, {"Chocolate", "$3.19"}, {"Cookie", "$9.5"},

{"Cucumber", "$0.79"}, {"Eggs", "$3.09"}, {"Grape", "$2.29"}, {"Ice Cream", "$5.39"},

{"Milk", "$2.09"}, {"Mushroom", "$1.79"}, {"Onion", "$0.79"}, {"Pepper", "$1.99"},

{"Pizza", "$11.5"}, {"Potato", "$0.69"}, {"Spinach", "$3.09"}, {"Tomato", "$1.79"}};

(above code is given just to add to our class)

/**

* adds the item with the given identifier index at the end of the cart

* simply add the item (description) with the given index to the end of the array cart. It should return the total number of items present within the cart array after the item with identifier index is added

*

* @param index of the item within the marketItems array

* @param cart shopping cart

* @return the number of items present in the cart after the item with identifier index is added

*/

public static int add(int index, String[] cart, int count) {

// TODO complete this method

return 0;

}

/**

* Returns how many occurrences of the item with index itemIndex are present in the shopping cart

* notice that the cart contains elements of type String (items descriptions).

* add a market item to the cart, only given its index. To help you implement occurrencesOf() method (and may be later other ones), you can develop a private helper method that returns the item description (String) given its index (int). For instance, private static String getItemDescription(int index) {}

*

* @param itemIndex identifier of the item to count its occurrences in the cart

* @param cart shopping cart

* @param count number of items present within the cart

* @return the number of occurrences of item in the cart

*/

public static int occurrencesOf(int itemIndex, String[] cart, int count) {

// TODO complete this method

return 0;

}

// Removes the first (only one) occurrence of itemToRemove if found and returns the number of

// items in the cart after remove operation is completed either successfully or not

// itemToRemove represents the item to remove from the cart, cart represents the shopping cart, and count represents the number of market items present in the cart before remove is called

// This method returns the number of items in the cart after remove operation is complete.

// If itemToRemove is found to equal one of the strings referenced by the array cart, remove effectively takes one of the occurrences of the String element (the first match).

public static int remove(String itemToRemove, String[] cart, int count) {}

// TODO complete this method

/**

* Returns the index of an item within the shopping cart

*

* @param item description

* @param cart Shopping cart

* @param count number of items present in the shopping cart

* @return index of the item within the shopping cart, and -1 if the item does not exist in the

* cart

*/

private static int indexOf(String item, String[] cart, int count) {}

// TODO complete this method

// returns the total value (cost) of the cart without tax in $

public static double getSubTotalPrice(String[] cart, int count) {}

// TODO complete this method

// prints this Market Catalog (item identifiers, description, and prices)

public static void printMarketCatalog() {}

// TODO complete this method

// Displays the cart content (items separated by commas)

public static void displayCartContent(String[] cart, int count) {}

// TODO complete this method

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!