import java.util.ArrayList; // There is another class that goes with this one called App. I'll include it on the bottom.
import java.util.Scanner;
public class AppStore
{
private String appStoreName;
private ArrayList<App> 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<App>();
}
/**
* 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("Coinbase", "Coinbase Global Inc.", 0, 0));
addApp(new App("Telegram Messenger", "Telegram FZ LLC", .99, 0));
addApp(new App("IPTV Extreme", "Paolo Turatti", 1.99, 0));
}
/**
* 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 by name
* @param the name of the app being looked for
* @return the name of the app if found
*/
public App findApp(String name)
{
populateApps();
String name1 = new name;
String name2 = appList.getAppName();
int diff = name1.compareTo(name2);
for(App app : appList) {
if(diff <= 0) {
System.out.println("App was found.");
}
return null;
}
}
/**
* @remove an app from the App store
* @param is name of app to remove
*/
public void removeApp(String name)
{
populateApps();
int index = 0;
for(App app : appList) {
}
}
/**
* @locate an app by the author name
*/
public App getAppsByAuthor(String name)
{
populateApps();
ArrayList<App> author = new ArrayList<App>();
for(App app : appList) {
String appAuthor = app.getAuthor();
if(app.getAuthor().equals(null)){
return null;
}
return author;
}
}
/**
*@locate apps that have been rated
*/
public void getNumAppsWithRating(int rating)
{
}
/**
* @prints a summary of the app store
* prints total number of apps, name of store,
* number of apps with each rating and unrated apps
*/
public void printAppStoreSummaryStats()
{
}
}
public class App
{
private String name;
private String author;
private double price;
private int rating; // valid ratings are 1-4 or 0 meaning 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;
rating = 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;
}
/**
* @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()
{
if(price == 0) {
return true;
}
else {
return false;
}
}
/**
* @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
* Valid rating is 1-4
*/
public void setRating(int newRating)
{
if((newRating >= 1) && (newRating <= 4)) {
rating = newRating;
}
else if((newRating == 0) || (newRating > 4)) {
System.out.println("Error: Valid rating range is 1-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 >= 0 && rating <= 3) {
rating = rating + 1;
}
else if(rating == 0 || rating >= 4) {
rating = rating;
}
}
/**
* Decrease the rating of this app by 1
*/
public void decreaseRating()
{
if(rating == 1) {
rating = 1;
}
else if(rating >= 2 && rating <= 4){
rating = rating - 1;
}
else if(rating == 0){
rating = rating;
}
}
/**
* 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("---------------------------------");