Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

More Books

Students also viewed these Databases questions

Question

= s D a) x c = s D a) x c

Answered: 1 week ago

Question

What are the role of supervisors ?

Answered: 1 week ago