Intro Java Programming
project 6: Java Code – 50 points
Objectives
· Write a basic Java program using OOP.
· Design and write Java code for a class, including attributes, accessors, mutators, and constructors.
· Design and write Java code for an application program that instantiates and uses objects of a user-defined class.
Assignment
Practice Problem: This is a practice problem. The service class code and pseudocode for the application are already given. You should complete this exercise so that you are able to do the graded assignment correctly. The graded problem is given after this problem
Given the service class Movie and the java code for it below complete the following activities:
*********************************************************************** Service Class: Analysis - Class Diagram /Template ***********************************************************************/
|
|
|
Part 1: Service Class Java Code
Perform the following steps:
1. Execute jGrasp.
1. Create a new Java file by clicking on File/New/Java. Then choose File/Save As and name the file Movie. Make sure the file has the .java extension.
1. Type the following Java code. Be sure to follow the indentation guidelines and include the comments.
/****************************************************************************
Java Code for the Service Class
****************************************************************************
public class Movie {
//attributes
private String title;
private String genre;
private int rating;
//constructors
public Movie() {
title = "";
genre = "";
rating = 0;
}//movie()
public Movie(String newTitle, String newGenre, int newRating) {
title = newTitle;
genre = newGenre;
rating = newRating;
}//overloaded Movie
//Mutators
public void setTitle (String newTitle) {
title = newTitle;
}
public void setGenre (String newGenre) {
genre = newGenre;
}
public void setRating (int newRating) {
rating = newRating;
}
//Accessors
public String getTitle () {
return title;
}
public String getGenre() {
return genre;
}
public int getRating() {
return rating;
}
//Display all field values
public void showAll() {
System.out.println("______________________________________________________ "); System.out.println(" The Movie Title Genre and Rating ");
System.out.println("______________________________________________________ ");
System.out.println("Title: " + title);
System.out.println("Genre: " + genre);
System.out.println("Rating: " + rating);
System.out.println("");
}
} //movie class
· Save the file.
· Compile the program. If you have errors, correct them and then compile again.
Part 2: Application Java Code
Application class MovieStore with the following requirements: It will have 3 static methods: main (), showGenreTitle() and setupmychoice().
In its main () method:
· Declare (Instantiate) two Movie objects first object named fNf using a default constructor.
· A second object named pokemon using second constructor and send title as U2 strikes back, the genre as Animated and the rating as 3.
Next perform the following tasks:
1) Set the fields of the fNf with title as Fast & Furious, genre as Action and ratings as 5. Then display its attributes.
2) Display all the fields of object pokemon. Use the showAll() service class method to display all the field values.
3) Create a new Movie object name it myChoice using a default constructor.
4) Create a static method setupmychoice(). Call this method and send the myChoice object as an argument. In this method get all the field values for the myChoice movie from keyboard and then use mutators to set the attributes. After setting up the attributes use the showAll() service class method to display all the fields of myChoice movie.
NOTE: there is no method in movie service class to get input from the keyboard.
5) Change the Rating of fNf to 4
6) Create a static method showGenreTitle(). Call this method and send fNf object as an argument. In this method display its genre and title.
Perform the following steps:
1. Choose File/Close All to close all your currently open files.
1. Create a new Java file by clicking on File/New/Java. Then choose File/Save As and name the file MovieStore. Make sure the file has the .java extension.
1. Convert the pseudo-code to Java code. Be sure to follow the indentation guidelines and include the comments.
/****************************************************************************
Design Pseudocode for the Application
****************************************************************************
Public Class MovieStore
Module main()
Declare Movie fNf = = New Movie()
Declare Movie pokemon = New Movie("U2 strikes back","Animated",3)
Declare Movie myChoice = New Movie()
//setup fNf object
Call fNf.setTitle("Fast & Furious")
Call fNf.setGenre("Action")
Call fNf.setRating(5)
Call fNf.showAll()
Call setupmyChoice(mychoice) //Setup myChoice obj
Call pokemon.showAll() //display field values of pokemon obj Call fNf.setRating(4) //update fNf obj
Call showGenreTitle(fNF) //Display specific fields of fNf obj
End Module
Module showGenreTitle (Movie objfNf)
Display "Genre of the movie: ", Call objfNf.getTitle(),
Display "Title of the movie: ", Call objfNf.getGenre()
End Module
Module setupmychoice(Movie objmychoice)
Declare String newTitle
Declare String newGenre
Declare int newRating
Display "Enter a movie title:”
Input newTitle
Display "Now enter the genre:”
Input newGenre
Display "Did you like it? (1=NO, 5=YES):”
Input newRating
Call objmychoice.setTitle(newTitle)
Call objmychoice.setGenre(newGenre)
Call objmychoice.setRating(newRating)
Call objmychoice.showAll()
End Module
End Class
***************************************************************************/
· Save the file.
· Compile the class. If you have errors, correct them, and then compile again.
· Once the program compiles without errors, Run the program. You should save the output in the Results file by using print Screen. Make sure to crop the pic to only display the output.
|
Rubric for grading |
|
Class Diagram (10 points) Java code Service Class (20 points) · Access modifiers specified · Fields/data members specified with correct data types · Default and 2nd constructors · Accessors · Mutators · Other methods Application class Java code (20 points) 5. Class declaration 6. Declarations of instance variable 7. Module/Function definitions for all methods - Header: name and parameter list - Body: statements 8. Comments |
Graded Problem: Spiffy Jacket Store – Create Java code to implement both the Service class and Application.
Part 1: UML Service class diagram: Use word to complete this part.
Jacket service class that contains the following fields: Create a Jacket class that contains a Jacket type, a size, and color. Include the following:
1. A default constructor that initializes each attribute to some reasonable default value for Jacket.
2. Second constructor that has a parameter for each data member. This constructor initializes each attribute to the value provided when an object is instantiated.
3. Accessor and mutator methods for each attribute.
4. A method showFields() that displays all the data about the Jacket.
Part 2: Service class Java Code
Perform the following steps:
1. Execute jGrasp.
1. Create a new Java file by clicking on File/New/Java. Then choose File/Save As and name the file Jacket. Make sure the file has the .java extension.
1. Create the Java code for the Service Class Jacket. Be sure to follow the indentation. guidelines and include the comments.
1. Save the file.
1. Compile the program. If you have errors, correct them, and then compile again.
Part 3: Application Java Code
The application Java program JacketStore contains main () and does the following: It will have 2 static methods: main () and outputType().
1. Create and instantiate two objects of the Jacket class. The first object should be named joeJacket and use the default constructor. The second object should be named maxJacket and use the second constructor to initialize the s to “sports”, the color to “brown”, and the size to 42.
2. Set the color of the joeJacket to “black”.
3. Set the type of the joeJacket to “bomber”.
4. Set the size of the joeJacket to 38.
5. Create a static method outputType().
A. display the type of the jacket in this method. Use the accessor to get the value.
B. Call this method and send the joeJacket object.
6. Change the color of the maxJacket to “tan”.
7. Call the static method outputType() and send the maxJacket to display the type of jacket for maxJacket.
8. Displays all the information about the maxJacket object. Use the method showFields() in the service class.
9. Displays all the information about the joeJacket object. Use the method showFields() in the service class.
Perform the following steps:
1. Choose File/Close All to close all your currently open files.
1. Create a new Java file by clicking on File/New/Java. Then choose File/Save As and name the file JacketStore. Make sure the file has the .java extension.
1. Write the Java code for the Application JacketStore. Be sure to follow the indentation guidelines and include the comments.
1. Save the file.
1. Compile the class. If you have errors, correct them, and then compile again.
1. Once the program compiles without errors, Run the program. You should save the output in the Results file by using print Screen. Make sure to crop the pic to only display the output.
Submission Instructions
1. Create a folder named Module 6 Project OOP
2. Save Graded problem Part1 word file named JacketClassDiagram.docx – contains the Jacket Service Class Diagram.
3. Save problem 2 Part 2 java file – contains the compiled code for Jacket Service Class.
4. Save problem 2 Part 3 java file – contains the compiled code for JacketStore Application.
5. Save the output screen shots in a file – Results.docx– contains the print screens of the results of problem 1 and 2
6. Zip the folder.
7. Submit the zipped folder.
PS Note: Do not attach any files directly in the submit box.