Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

class Card { private String name; /** A default constructor method that initializes name to unknown */ //-----------Start below here. To do: approximate lines of

class Card { private String name; /** A default constructor method that initializes name to "unknown" */ //-----------Start below here. To do: approximate lines of code = 2 // 1-2. write a default constructor which sets name to "unknown"

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. /** A constructor method that initializes name to the given parameter name1 @param name1 the given name */ public Card(String name1) { //-----------Start below here. To do: approximate lines of code = 1 //-----------Start below here. To do: approximate lines of code = 1 // 3. fill in this constructor method //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } /** Accessor method for the name @return the name */ public String getName() { return name; } /** Tests whether the card is expired. @return false, since this type of card is never expired */ public boolean isExpired() { return false; } /** Produces a string representation of the object Note: use getClass().getName() for "Card" so that the subclass name will be correct. @return a string representation */ //-----------Start below here. To do: approximate lines of code = 2 //-----------Start below here. To do: approximate lines of code = 2 // 4-5. write a toString method that produces something like: "Card[name = Joe Turner]" using getClass().getName() //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. }

/** CardTester -- to test the Card class in which you have to write a default constructor and a toString method. Change nothing here. */ public class CardTester { public static void main(String[] args) { Card card ;

card = new Card() ; System.out.println(card) ; System.out.println("Card[name = unknown] WAS EXPECTED") ;

card = new Card("Jane Doe") ; System.out.println(card) ; System.out.println("Card[name = Jane Doe] WAS EXPECTED") ; } }

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

Students also viewed these Databases questions

Question

code returned by a web server for unauthorized access

Answered: 1 week ago

Question

e. What difficulties did they encounter?

Answered: 1 week ago