3.Modify the Java Class template:(a)In the Toolsmenu, select Templates.(b)In the dialog box that comes up, open the Javafolder, select Java Classand click the Open in Editorbutton.(c)A new file should open up containing the following text:<#assign licenseFirst = "/*"><#assign licensePrefix = " * "><#assign licenseLast = " */"><#include"${project.licensePath}"><#if package?? && package != "">package ${package};/**** @author ${user}*/ public class ${name} {}(d)Delete the first four lines and after @authorreplace the text ${user}with your first and last name. The file should now look like this (except with your name):<#assign licenseFirst = "/*"><#assign licensePrefix = " * "><#assign licenseLast = " */"><#include "${project.licensePath}"><#if package?? && package != "">package ${package};/*** * @author Alice Guy-Blache*/public class ${name} {}(e)In the Filemenu select Save. You can also click on the Save Allicon to save your files.(f)Close the Java Classfile by clicking the X on the tab.4.Create a Java class file for a Movieclass.(a)In the Filemenu select New File...(b)Under Categories:make sure that Javais selected.(c)Under File Types:make sure that Java Classis selected.(d)Click Next.(e)For Class Name:type Movie.(f)For Package:select csci1011.lab7.(g)Click Finish.(h)A text editor window should pop up with the following source code (except with your actual name):package csci1011.lab7; /**** @author Alice Guy-Blache*/public class Movie {}5.Implement the Movieclass.(a)Add the following public instance variables to the Movieclass:•An instance variable called titleof type String.•An instance variable called directorof type String.•An instance variable called yearof type int.(b)Add the following methods to the Movieclass:•A voidmethod called readInputthat prompts the user for a title, a director, and a year, and initializes the title, director, and yearinstance variables to those values.•A voidmethod called writeOutputthat displays the title and director of the movie followed by the year in parentheses. For example, if the title of the movie is Blade Runner, the director is Ridley Scott and the year is 1982, it should display Blade Runner dir. Ridley Scott (1982).6.Write code in the mainmethod of your main class to test the Movieclass:(a)Create a newMovieobject.(b)Call the readInputmethod on the object.(c)Call the writeOutputmethod on the object.(d)Prompt the user for a new title for the movie.(e)Set the titleinstance variable to the new title.(f)Call the writeOutputmethod on the object again.7.Test your program. The output should look something like this:Enter the title of the movie:Extra Terrestrial VisitorsEnter the director of the movie:Juan Piquer SimonEnter the year the movie was released: 1983Extra Terrestrial Visitors dir. Juan Piquer Simon (1983)Enter a new title:Pod PeoplePod People dir. Juan Piquer Simon (1983)8.Modify your program so it uses information hiding.(a)Change all of the public instance variables to private instance variables.(b)Add accessor methods getTitle, getDirector, and getYearthat each return the values of the corresponding instance variables.(c)Add a mutator method called setMoviethat takes three arguments and uses them to initialize the three instance variables.9.Modify the mainmethod to test the new methods.(a)Remove the line that sets the titleinstance variable directly.(b)Use the getDirectorand getYearmethods to store the director and year in variables.(c)Use the setMoviemethod to reset the instance variables using the new title, the old director, and the old year.(d)Make sure that you display the movie as you did before.10.Test your program. The output should look exactly the same as it did before.
Write a class to represent a real-world concept.•Write voidmethods and methods that return values.•Write methods that have parameters.•Implement information hiding using private instance variables, accessors, and mutators.
3.Modify the Java Class template:(a)In the Toolsmenu, select Templates.(b)In the dialog box that comes up, open the Javafolder, select Java Classand click the Open in Editorbutton.(c)A new file should open up containing the following text:<#assign licenseFirst = "/*"><#assign licensePrefix = " * "><#assign licenseLast = " */"><#include"${project.licensePath}"><#if package?? && package != "">package ${package};</#if>/**** @author ${user}*/
public class ${name} {}(d)Delete the first four lines and after @authorreplace the text ${user}with your first and last name. The file should now look like this (except with your name):<#assign licenseFirst = "/*"><#assign licensePrefix = " * "><#assign licenseLast = " */"><#include "${project.licensePath}"><#if package?? && package != "">package ${package};</#if>/*** * @author Alice Guy-Blache*/public class ${name} {}(e)In the Filemenu select Save. You can also click on the Save Allicon to save your files.(f)Close the Java Classfile by clicking the X on the tab.4.Create a Java class file for a Movieclass.(a)In the Filemenu select New File...(b)Under Categories:make sure that Javais selected.(c)Under File Types:make sure that Java Classis selected.(d)Click Next.(e)For Class Name:type Movie.(f)For Package:select csci1011.lab7.(g)Click Finish.(h)A text editor window should pop up with the following source code (except with your actual name):package csci1011.lab7;
/**** @author Alice Guy-Blache*/public class Movie {}5.Implement the Movieclass.(a)Add the following public instance variables to the Movieclass:•An instance variable called titleof type String.•An instance variable called directorof type String.•An instance variable called yearof type int.(b)Add the following methods to the Movieclass:•A voidmethod called readInputthat prompts the user for a title, a director, and a year, and initializes the title, director, and yearinstance variables to those values.•A voidmethod called writeOutputthat displays the title and director of the movie followed by the year in parentheses. For example, if the title of the movie is Blade Runner, the director is Ridley Scott and the year is 1982, it should display Blade Runner dir. Ridley Scott (1982).6.Write code in the mainmethod of your main class to test the Movieclass:(a)Create a newMovieobject.(b)Call the readInputmethod on the object.(c)Call the writeOutputmethod on the object.(d)Prompt the user for a new title for the movie.(e)Set the titleinstance variable to the new title.(f)Call the writeOutputmethod on the object again.7.Test your
1983Extra Terrestrial Visitors dir. Juan Piquer Simon (1983)Enter a new title:Pod PeoplePod People dir. Juan Piquer Simon (1983)8.Modify your program so it uses information hiding.(a)Change all of the public instance variables to private instance variables.(b)Add accessor methods getTitle, getDirector, and getYearthat each return the values of the corresponding instance variables.(c)Add a mutator method called setMoviethat takes three arguments and uses them to initialize the three instance variables.9.Modify the mainmethod to test the new methods.(a)Remove the line that sets the titleinstance variable directly.(b)Use the getDirectorand getYearmethods to store the director and year in variables.(c)Use the setMoviemethod to reset the instance variables using the new title, the old director, and the old year.(d)Make sure that you display the movie as you did before.10.Test your program. The output should look exactly the same as it did before.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 8 images