Question
In the class definition, initialize the private fields author (string) and year (integer) with the default values Undefined and -1, respectively. Ex: If the input
In the class definition, initialize the private fields author (string) and year (integer) with the default values "Undefined" and -1, respectively.
Ex: If the input is Choi 2001, then the output is:
Default values: Author: Undefined, Year: -1 After mutator methods: Author: Choi, Year: 2001
Note: The class's print() method is called before and after the input is passed to the setters.
Plays.java coding
public class Play {
private /* Your code goes here */ private /* Your code goes here */
public void setAuthor(String playAuthor) { author = playAuthor; } public void setYear(int playYear) { year = playYear; } public void print() { System.out.println("Author: " + author + ", Year: " + year); } }
MyPlays.java coding.
import java.util.Scanner;
public class MyPlays { public static void main (String[] args) { Scanner scnr = new Scanner(System.in); String newAuthor; int newYear; Play favoritePlay = new Play(); System.out.println("Default values: "); favoritePlay.print(); newAuthor = scnr.next(); newYear = scnr.nextInt(); favoritePlay.setAuthor(newAuthor); favoritePlay.setYear(newYear); System.out.println("After mutator methods: "); favoritePlay.print(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started