Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a new project in BlueJ and name it LastName-lab2-app, e.g., Smith-lab2-app . Create a new class using the New Class... button and name it

  1. Create a new project in BlueJ and name it LastName-lab2-app, e.g., Smith-lab2-app.
  2. Create a new class using the "New Class..." button and name it App (be sure the A is capitalized and the other letters are not; Java is case-sensitive and the class must be named exactly as given).
  3. Open the App class to edit the source code.
  4. Select and delete all the source code so that the file is empty.
  5. Copy in the starting source code found here: Lab 2: App Starting Source Code
  6. Update the header comment block and document your changes as you work.
    • Adjust the header comment block at the top of the file: * * Modifications: * ... * CT: Added method to print app basic info * YN: ... List changes you make prefaced by your initials * * @author Cara Tang, Your Name Add your name * @version 2017.12.30 Update the version to the current date */
    • Whenever you add a new method, include a documentation block that describes what the method does. For example: /** * Return the app rating */
  7. Complete the TODOs in the code, modifying and implementing methods as described. Be sure to follow the specifications as given in the TODO comments, for example the methods must be named as given (with correct spelling and capitalization).
  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. Test your changes to make sure everything works! (You should be testing as you go, not just at the end!)
  10. A unit test class is provided for you to help check your code: AppTest.java. The second Lab 2 How-To Video shows you how to use the unit test class.
  11. Adhere to Java style guidelines as described in Appendix J.

Starting source code :

/** * An app for a mobile device * * Modifications: * CT: Added properties for name, author, price, rating * CT: Added constructor that initializes all properties * CT: Added getters for name, author, price * CT: Added setter for price * CT: Added methods to reset and increase rating * CT: Added method to print app basic info * * * @author Cara Tang * @version 2017.12.30 */ 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; } // TODO: ----------------- 1 ------------------- // TODO: Create a second constructor that takes 3 parameters: appName, appAuthor and appPrice // TODO: Update the corresponding 3 fields from the parameters // TODO: Set the rating to 0 // TODO: Hint: start by copying and pasting the constructor above, then update as necessary // TODO: Don't forget the comment header! /** * @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) { price = newPrice; } // TODO: ----------------- 2 ------------------- // TODO: Create the getRating method that returns this app's rating // TODO: Don't forget the comment header! // TODO: ----------------- 3 ------------------- // TODO: Create the setRating method that sets the rating of this app to a new value // TODO: Hint: This method should take the new rating as a parameter; nothing should be returned // TODO: Don't forget the comment header! /** * 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() { // TODO: ----------------- 4 ------------------- // TODO: This method doesn't work as intended. Fix it. rating = 1; } // TODO: ----------------- 5 ------------------- // TODO: Create a method called decreaseRating that decreases this app's rating by 1 // TODO: This method should be similar to increaseRating // TODO: Don't forget the comment header! /** * Print information on this app */ public void printAppInfo() { System.out.println("---------------------------------"); System.out.println("App: " + name); System.out.println("Author: " + author); System.out.println("Price: $" + price); // TODO: ----------------- 6 ------------------- // TODO: Add a line here to print this app's rating System.out.println("---------------------------------"); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions