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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!