Question: 1. Add a Main class with a main method. In the main method, create objects and call methods on the objects to demonstrate their behavior.

1. Add a Main class with a main method. In the main method, create objects and call methods on the objects to demonstrate their behavior. Be sure to print something or include methods that print something.

2. using the Lab 8 App Store project, you could create a AppStore object and call printAppStoreSummaryStats and/or printAppList.

import java.util.ArrayList;

/** * An app store containing apps * * Modifications: * CT: Create AppStore with a list of apps and basic methods to add, clear, and print apps * * @author * @version 2018.05.28 */ public class AppStore { private String appStoreName; private ArrayList appList; /** * Create an app store with the given name * @param name the name of this app store */ public AppStore(String name) { appStoreName = name; appList = new ArrayList(); } /** * Populate the store with a few apps. * Use this method to make testing easier. After creating an AppStore, * call this method to populate the apps, and then test your methods. */ public void populateApps() { addApp("Pandora Music", "Pandora", 0); addApp(new App("Minecraft", "Mojang", 6.99, 3)); addApp(new App("Minecraft", "Mojang", 3)); addApp(new App("Minecraft", "Mojang1", 3)); addApp(new App("Minecraft", "Mojang3", 3)); addApp(new App("TempleRun", "TempleRun1", 6.99, 3)); addApp(new App("BattleBay", "BattleBay3", 9.99, 3)); } /** * Add the given app to the app store * @param anApp an app to add */ public void addApp(App anApp) { appList.add(anApp); } /** * Create an app with the given name, author, and price and add it to the store. * The app starts out unrated. * @param name name of the app * @param author the app author * @param price the price of the app */ public void addApp(String name, String author, double price) { appList.add(new App(name, author, price)); } /** * @return the number of apps in the store */ public int getNumberOfApps() { return appList.size(); } /** * Removes all the apps from the store */ public void clearAppStore() { appList.clear(); } /** * Print all the apps in the store */ public void printAppList() { System.out.println("============= " + appStoreName + " ============="); if (appList.size() == 0) { System.out.println("No apps in the store"); } else { for (App currentApp : appList) { currentApp.printAppInfo(); } } System.out.println("==========================================="); }

/** * Find an app based on its name * @param name the name of the app to search for * @return the app with the given name * or null if there is no app with that name */ public App findApp(String name) { if(name != null && name.length() != 0) { for(App thisApp: appList) { if(thisApp.getName().equalsIgnoreCase(name)) { return thisApp; } } } return null; } /** * Remove an app based on its name. * @param name remove the name of the app * @return the app with the given name or null if there is no app with that name */ public int removeApp(String name) { if(name != null && name.length() != 0) { App appToRemove = findApp(name); if(appToRemove != null) { appList.remove(appToRemove); } } return 0; } /** * Returns all apps by author's name * @param name the name of the app to remove * @return the app with the given name or null if there is * no app with that name */ public ArrayList getAppsByAuthor(String authorName) { ArrayList appsByAuthor = new ArrayList(); if(authorName != null && authorName.length() != 0) { for(App x:appList) { if(x.getAuthor().equalsIgnoreCase(authorName)) { appsByAuthor.add(x); } } } return appsByAuthor; }

/** * Returns the number of apps in the appstore with the given rating * @param rating integer * @return the count of apps in the appstore with the given rating */ public int getNumberAppsWithRating(int rating) { int countOfAppsWithGivenRating = 0; if(rating >= 0 && rating <= 5) { for(App x : appList) { if(x.getRating() == rating) { countOfAppsWithGivenRating++; } } } return countOfAppsWithGivenRating; }

/** * pritns the name of the app store, the total number of apps * the number o apps of each rating * and the number of unrated apps * @param rating integer * @return the count of apps in the app store with the given rating */ public void printAppStoreSummaryStats() { System.out.println("======== SUMMARY STATS for Joe's App Store ========"); int countRating5 = 0; int countRating4 = 0; int countRating3 = 0; int countRating2 = 0; int countRating1 = 0; int countNoRating = 0; System.out.println("Total # of apps: " + getNumberOfApps()); for(App x : appList) { if(x.getRating() == 5)countRating5++; else if(x.getRating() == 4)countRating4++; else if(x.getRating() == 3)countRating3++; else if(x.getRating() == 2)countRating2++; else if(x.getRating() == 1)countRating1++; else countNoRating++; } System.out.println("# apps rated 5: " + countRating5); System.out.println("# apps rated 4: " + countRating4); System.out.println("# apps rated 3: " + countRating3); System.out.println("# apps rated 2: " + countRating2); System.out.println("# apps rated 1: " + countRating1); System.out.println(" # of unrated apps: " + countNoRating); System.out.println("==========================================="); } }

/** * An app for a mobile device * * @author * @version 2018.06.10 */ public class App { private String name; private String author; private double price; private int rating; // valid ratings are 1-4; 0 means not rated /** * Create an app with the given name, author, price, and rating * @param appName the app name * @param appAuthor the app author * @param appPrice the price of the app (0 if the app is free) * @param appRating the app's rating */ public App(String appName, String appAuthor, double appPrice, int appRating) { name = appName; author = appAuthor; price = appPrice; setRating(appRating); } /** * Create an app with the given name, author, and price that is not rated * @param appName the app name * @param appAuthor the app author * @param appPrice the price of the app (0 if the app is free) */ public App(String appName, String appAuthor, double appPrice) { name = appName; author = appAuthor; price = appPrice; rating = 0; }

/** * @return the app name */ public String getName() { return name; } /** * @return the app author */ public String getAuthor() { return author; } /** * @return the app price */ public double getPrice() { return price; } /** * Set the price of this app to the value given * @param newPrice new price for this app */ public void setPrice(double newPrice) { if (newPrice >= 0) { price = newPrice; } else { System.out.println("Error: Price must be greater than or equal to 0"); } } /** * @return true if this app is free, false otherwise */ public boolean isFree() { return price == 0; } /** * @return the app rating */ public int getRating() { return rating; } /** * Set the rating of this app to the value given * @param newRating new rating for this app */ public void setRating(int newRating) { if (newRating >= 1 && newRating <= 4) { rating = newRating; } else { System.out.println("Error: Valid range for rating is 1 to 4"); } } /** * Reset the rating of this app to not rated */ public void resetRating() { rating = 0; } /** * Increase the rating of this app by 1 */ public void increaseRating() { if (rating < 4) { rating = rating + 1; } }

/** * Decrease the rating of this app by 1 */ public void decreaseRating() { if (rating > 1) { rating = rating - 1; } }

/** * Print information on this app */ public void printAppInfo() { System.out.println("---------------------------------"); System.out.println("App: " + name); System.out.println("Author: " + author); if (price == 0) { System.out.println("Price: FREE"); } else { System.out.println("Price: $" + price); } if (rating == 0) { System.out.println("Rating: (not rated)"); } else { System.out.println("Rating: " + rating); } System.out.println("---------------------------------"); } }

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!