Question

Create a new project in BlueJ and name it LastName-lab8-appstore, e.g., Smith-lab8-appstore. If your App class from Lab 4 is fully functional, copy it into the project. (You can drag a file from File...

  1. Create a new project in BlueJ and name it LastName-lab8-appstore, e.g., Smith-lab8-appstore.
  2. If your App class from Lab 4 is fully functional, copy it into the project. (You can drag a file from File Explorer onto the BlueJ project window.) Otherwise, use the instructor's App class:
    • Create a new class using the "New Class..." button and name it App.
    • Open the App class to edit the source code. Select and delete all the source code so that the file is empty.
    • Copy in the starting source code found here: Lab 8: App Starting Source Code. (This link will not work for you until you have received feedback on Lab 4. Email the instructor if you think you should be able to access it but can't.)
  3. Create an AppStore class and copy in the starting source code found here: Lab 8: AppStore Starting Source Code.
  4. For this lab, you will be editing the AppStore class. You should not change the App class for this lab.
  5. In AppStore, update the header comment block and document your changes as you work. Use the javadoc tags @param and @return in method header comments as appropriate.
  6. As usual, adhere to Java style guidelines as described in Appendix J.
  7. Complete the TODOs in the AppStore code, modifying and implementing methods as described. Be sure to follow the specifications as given in the TODO comments.
  8. Before submitting your project, delete the TODO comments. TODOs represent a task that still needs to be done, and when you complete a TODO it should be removed. There should not be any TODOs in your submitted project (unless you didn't complete the project).
  9. As usual, you should be testing as you go to make sure everything works!
    AppStore Class Starting Source Code
    
    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 Cara Tang
     * @version 2018.02.17
     */
    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));
            // TODO: ------------------------ 1 --------------------------
            // TODO: Add a few more apps.
        }
        
        /**
         * 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)
        // {
            // TODO: ------------------------ 2 --------------------------
            // TODO: Uncomment the method wrapper and implement according to the header comment.
            // TODO: Do not change the method signature that is given.
            // TODO: Hint: One approach is to use a for-each to loop over each app in the list.
            // TODO: Inside the loop check if the app name matches and if so, return the app.
            // TODO: If the loop completes without returning, the app is not in the list and 
            // TODO: you can return null.
        // }
        
        // TODO: ------------------------ 3 --------------------------
        // TODO: Write a method called removeApp that takes a String parameter.
        // TODO: and removes the app with that name.
        // TODO: Hint: ArrayList has a remove method that takes an object that is the element
        // TOOD: to remove. You can call findApp to find the app to remove, and pass it to remove.
        
        // TODO: ------------------------ 4 --------------------------
        // TODO: Write a method called getAppsByAuthor that takes a String parameter
        // TODO: and returns a list of apps by the given author.
        // TODO: If there are no apps with that author, return an empty list (not null).
        // TODO: Do not print anything in this method.
        // TODO: Hint: The structure of this method will be the same as the getUnsold method
        // TODO: from the Auction project.
        
        // TODO: ------------------------ 5 --------------------------
        // TODO: Write a method called getNumAppsWithRating that takes an int parameter
        // TODO: representing a rating, and returns the number of apps in the app store
        // TODO: that have the given rating.
        // TODO: Example: If two apps in the store have rating 3, then the call
        // TODO: getNumAppsWithRating(3) will return 2.
        
        // OPTIONAL TODO: ------------------------ 6 --------------------------
        // OPTIONAL TODO: This TODO is optional.
        // OPTIONAL TODO: Write a method called getMaxRatingOfAnApp (no parameters) that
        // OPTIONAL TODO: returns the maximum rating of an app in the app store.
        // OPTIONAL TODO: Example: If the store has 3 apps, one with rating 2 and two unrated,
        // OPTIONAL TODO: then the max rating is 2.
    
        // TODO: ------------------------ 7 --------------------------
        // TODO: Write a method called printAppStoreSummaryStats (no parameters, no return)
        // TODO: that prints the name of the app store, the total number of apps, the number of
        // TODO: apps of each rating, and the number of unrated apps.
        // TODO: If you implemented getMaxRatingOfAnApp, print the max rating as well.
        // TODO: Sample output:
        // ======== SUMMARY STATS for Joe's App Store ========
        // Total # of apps: 3
        // # apps rated 4: 0
        // # apps rated 3: 0
        // # apps rated 2: 1
        // # apps rated 1: 0
        // # of unrated apps: 2
        // Max rating: 2
        // ===========================================
    
    }
0 0
Add a comment Improve this question Transcribed image text
Answer #1

App.java

public class App {
private String name, author;
private double price;
private int rating;
  
public App()
{
this.name = "";
this.author = "";
this.price = 0;
this.rating = 0;
}
  
public App(String name, String author, double price)
{
this.name = name;
this.author = author;
this.price = price;
}

public App(String name, String author, double price, int rating)
{
this.name = name;
this.author = author;
this.price = price;
this.rating = rating;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getAuthor() {
return author;
}

public void setAuthor(String author) {
this.author = author;
}

public double getPrice() {
return price;
}

public void setPrice(double price) {
this.price = price;
}

public int getRating() {
return rating;
}

public void setRating(int rating) {
this.rating = rating;
}
  
public void printAppInfo()
{
System.out.println("Name: " + getName()
+ ", Author: " + getAuthor()
+ ", Price: $" + String.format("%.2f", getPrice())
+ ", Rating: " + getRating());
}
}

AppStore.java

import java.util.ArrayList;

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(new App("Pandora Music", "Pandora", 4.45, 0));
addApp(new App("Minecraft", "Mojang", 6.99, 3));
addApp(new App("Soltaire", "Mojang", 3.53, 3));
addApp(new App("Facebook", "Facebook Inc", 12.33, 4));
addApp(new App("Instagram", "Instagram Corp", 6.29, 4));
addApp(new App("Cred", "Dreamplug", 3.50, 4));
addApp(new App("The Tour", "Pandora", 4.00, 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();
System.out.println("App Store has been wiped out of all apps!");
}
  
/**
* Print all the apps in the store
*/
public void printAppList()
{
System.out.println("======================= " + appStoreName + " =======================");
if (appList.isEmpty()) {
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)
{
int index = 0;
boolean found = false;
  
for(int i = 0; i < appList.size(); i++)
{
if(appList.get(i).getName().equals(name))
{
found = true;
index = i;
break;
}
}
if(found)
return appList.get(index);
else
return null;
}
  
/**
* Remove an app based on its name
* @param name the name of the app to search for
*
*/
public void removeApp(String name)
{
if(findApp(name) == null)
System.out.println("There is no App with the name: " + name);
else
{
appList.remove(findApp(name));
System.out.println("App with the name " + name + " was removed successfully!");
}
}
  
/**
* Returns a list of Apps with the given Author name
* @param authorName the name of the author to search for
* @return a list of apps with the given author name
* or null if there is no author with the name
*/
public ArrayList<App> getAppsByAuthor(String authorName)
{
ArrayList<App> apps = new ArrayList<>();
boolean found = false;
for(int i = 0; i < appList.size(); i++)
{
if(appList.get(i).getAuthor().equals(authorName))
{
found = true;
apps.add(appList.get(i));
}
}
if(!found)
return null;
else
return apps;
}
  
/**
* Returns a list of Apps with the given Author name
* @param rate the app rating as a reference
* @return number of apps with a rating equal to "rate"
*/
public int getNumAppsWithRating(int rate)
{
int numOfApps = 0;
for(int i = 0; i < appList.size(); i++)
{
if(appList.get(i).getRating() == rate)
numOfApps++;
}
return numOfApps;
}
  
/**
* Returns the maximum rating an App has
*/
public int getMaxRatingOfAnApp()
{
int maxRating = appList.get(0).getRating();
for(int i = 0; i < appList.size(); i++)
{
if(appList.get(i).getRating() > maxRating)
maxRating = appList.get(i).getRating();
}
return maxRating;
}
  
/**
* Prints a statistical summary of all the apps in the app store
*/
public void printAppStoreSummaryStats()
{
System.out.println("============= SUMMARY STATS FOR " + appStoreName + " =============");
System.out.println("Total # of apps: " + getNumberOfApps());
System.out.println("# apps rated 4: " + getNumAppsWithRating(4));
System.out.println("# apps rated 3: " + getNumAppsWithRating(3));
System.out.println("# apps rated 2: " + getNumAppsWithRating(2));
System.out.println("# apps rated 1: " + getNumAppsWithRating(1));
System.out.println("# of unrated apps: " + getNumAppsWithRating(0));
System.out.println("Max rating: " + getMaxRatingOfAnApp());
System.out.println("=============================================================");
}
}

AppStoreMain.java (Main class)

import java.util.ArrayList;

public class AppStoreMain {
  
public static void main(String[]args)
{
// create an instance of the App Store class
AppStore appStore = new AppStore("Joe's App Store");
  
// populate the app store with some apps
appStore.populateApps();
  
// manually add 2 apps: unrated
appStore.addApp(new App("Nykaa", "Nykaa Corp", 9.77));
appStore.addApp(new App("CamScanner", "INTSIG Info", 8.47));
  
// prints all apps in the app store
System.out.println("Displaying all apps in the store...");
appStore.printAppList();
  
// finding an app with it's name
System.out.println("\nFinding two apps with names...");
App app1 = appStore.findApp("Cred");
App app2 = appStore.findApp("InstEdu");
if(app1 != null)
app1.printAppInfo();
else
System.out.println("No such app found!");
  
if(app2 != null)
app1.printAppInfo();
else
System.out.println("No such app found!");
  
// removing an app from the store
System.out.println("\nRemoving 2 apps from the store...");
appStore.removeApp("Cred");
appStore.removeApp("InstaEdu");
appStore.printAppList();
  
// get apps by a particular author
System.out.println("\nDisplaying apps by aparticular author name...");
ArrayList<App> appsByAuthor = appStore.getAppsByAuthor("Pandora");
if(appsByAuthor != null)
{
for(App apps : appsByAuthor)
{
apps.printAppInfo();
}
}
  
// printing app store summary stats
System.out.println("\nPrinting summary stats for the app store...");
appStore.printAppStoreSummaryStats();
}
}

******************************************************************** SCREENSHOT *******************************************************

un: Displaying all apps in the store. . . Joes App Store Name : Pandora Music, Author: Pandora, Price : 두4.45, Rating : 0 Na

Displaying apps by aparticular author name. - Name: Pandora Music, Author: Pandora, Price $4.45. Rating: 0 Name: The Tour, Au

Add a comment
Know the answer?
Add Answer to:
Create a new project in BlueJ and name it LastName-lab8-appstore, e.g., Smith-lab8-appstore. If your App class from Lab 4 is fully functional, copy it into the project. (You can drag a file from File...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Open BlueJ and create a new project (Project->New Project...). Create a new class named ListsDemo. Open the source code and delete all the boilerplate code. Type in the code to type (code to type...

    Open BlueJ and create a new project (Project->New Project...). Create a new class named ListsDemo. Open the source code and delete all the boilerplate code. Type in the code to type (code to type with bigger font) exactly as shown, filling in your name and the date in the places indicated. The code is provided as an image because you should type it in rather than copy-paste. If you need the code as text for accessibility, such as using a...

  • Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src...

    Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src folder, create a package named: edu.ilstu · Import the following files from T:\it168\Labs\lab13. Note that the .txt file must be in the top level of your project, not inside your src folder. o Student.java o StudentList.java o students.txt Carefully examine the Student.java and StudentList.java files. You are going to complete the StudentList class (updating all necessary Javadoc comments), following the instruction in the code....

  • PART 1: GETTING STARTED 1. Create a new Java Project. 2. Create a new Tree class...

    PART 1: GETTING STARTED 1. Create a new Java Project. 2. Create a new Tree class and enter this code. You do not have to type in the comments public class Tree { private String name; private int age; private bogJsAn evergreen; // true if evergreen // false if deciduous //CONSTRUCTORS public Tree( { name 0; evergreen = true; age } // you fill this one public Tree (String n, jnt a, bgalean e) //PUT YOUR CODE HERE } //...

  • C++ Lab 9A Inheritance Employee Class Create a project C2010Lab9a; add a source file Lab9a.cpp to...

    C++ Lab 9A Inheritance Employee Class Create a project C2010Lab9a; add a source file Lab9a.cpp to the project. Copy and paste the code is listed below: Design a class named Employee. The class should keep the following information in member variables: Employee name Employee number Hire date // Specification file for the Employee class #ifndef EMPLOYEE_H #define EMPLOYEE_H #include <string> using namespace std; class Employee { private:        // Declare the Employee name string variable here. // Declare the Employee...

  • Below, you can find the description of your labwork for today. You can also find the...

    Below, you can find the description of your labwork for today. You can also find the expected output of this code in the Application Walkthrough section. You are going to improve your existing Money & Stock Trading Platform on previous week’s labwork by incorporating Collections. In previous labworks, you have used arrays for holding Customer and Item objects. For this labwork you need to use ArrayList for holding these objects. So, rather than defining Customer[] array, you need to define...

  • Using your Dog class from earlier this week, complete the following: Create a new class called...

    Using your Dog class from earlier this week, complete the following: Create a new class called DogKennel with the following: Instance field(s) - array of Dogs + any others you may want Contructor - default (no parameters) - will make a DogKennel with no dogs in it Methods: public void addDog(Dog d) - which adds a dog to the array public int currentNumDogs() - returns number of dogs currently in kennel public double averageAge() - which returns the average age...

  • Finish FormatJavaProgram.java that prompts the user for a file name and assumes that the file contains...

    Finish FormatJavaProgram.java that prompts the user for a file name and assumes that the file contains a Java program. Your program should read the file (e.g., InputFile.java) and output its contents properly indented to ProgramName_Formatted.java (e.g., InputFile_Formatted.java). (Note: It will be up to the user to change the name appropriately for compilation later.) When you see a left-brace character ({) in the file, increase your indentation level by NUM_SPACES spaces. When you see a right-brace character (}), decrease your indentation...

  • signature 1. Create a new NetBeans Java project. The name of the project has to be...

    signature 1. Create a new NetBeans Java project. The name of the project has to be the first part of the name you write on the test sheet. The name of the package has to be testo You can chose a name for the Main class. (2p) 2. Create a new class named Address in the test Two package. This class has the following attributes: city: String-the name of the city zip: int - the ZIP code of the city...

  • Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java...

    Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java //package simple; public class PartTest { public static void main(String[] args) { ArrayList<ExpendablePart> system=new ArrayList<ExpendablePart>();   // creating Part Object Part part1 = new ExpendablePart("Last, First"); part1.setNumber("AX-34R"); part1.setNcage("MN34R"); part1.setNiin("ABCD-RF-WDE-KLJM"); // printing information System.out.println(part1.toString());       //Create a part2 object of class Part Part part2=new ConsumablePart("Widget, purple"); part2.setNumber("12345"); part2.setNcage("OU812"); part2.setNiin("1234-12-123-1234");    // printing information System.out.println(part2.toString());    //checking equality of two Part class objects if(part1.equals(part2)) System.out.println("part1 and...

  • C++ Lab 9B Inheritance Class Production Worker Create a project C2010Lab9b; add a source file Lab...

    C++ Lab 9B Inheritance Class Production Worker Create a project C2010Lab9b; add a source file Lab9b.cpp to the project. Copy and paste the code is listed below: Next, write a class named ProductionWorker that is derived from the Employee class. The ProductionWorker class should have member variables to hold the following information: Shift (an integer) Hourly pay rate (a double) // Specification file for the ProductionWorker Class #ifndef PRODUCTION_WORKER_H #define PRODUCTION_WORKER_H #include "Employee.h" #include <string> using namespace std; class ProductionWorker...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT