Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with the steps of the code. I have attached the person.java, main.java, and helper.java after the list. Put a breakpoint in Person.java

I need help with the steps of the code.

I have attached the person.java, main.java, and helper.java after the list.

Put a breakpoint in Person.java in setName (line 21)

Put a breakpoint in Main.java at the call to inputYN (line 22)

Start debugging the program

Enter Phil as the name. Hit [Enter]. IDEA will then pause at your breakpoint in Person.java

Using the debugger, change the value of the argument name to your own name.

Show in the debugger that the value changed.

Step Over line 21. Show in the debugger that this.name has been assigned

While on line 22, Step Out to return to line 19 in Main.java

Step Over line 19. Show that the Console tab is active again, waiting for you to enter the age. Enter your age. Hit [Enter]. You will wind up on line 20 in Main.java

While on line 20:

Show that you are now in the list of people. Show the values of your name and age.

Use the debugger to set the person object to null

While still on line 20, Resume the program. IDEA will pause you at line 22 in Main.java

Step Into Helper.inputYN

Step Over line 54, then line 55

[2] Step Out of Helper.inputYN.

Show how you need to answer "Another (Y/N)" in the console before you actually return to Main.java.

Step Over until you reach line 29 in Main.java. Do Force Step Into to show the source code for println

Step Out to return to Main.java

Hit the Stop button to end the program early

This is person.java.

public class Person { // Name of the person private String name; // Age of the person private int age; // Return the String representation of the person @Override public String toString() { String returnValue; returnValue = name + " (" + age + ")"; return returnValue; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } } 

This is Main.java

import java.util.ArrayList; import java.util.List; public class Main { public static void main(String[] args) { Helper helper = new Helper(); List people = new ArrayList<>(); do { // Reference variable pointing to an instance of the Person class Person person = new Person(); // Store the Person object in the list people.add(person); // Store the data in the object person.setName(helper.inputName()); person.setAge(helper.inputAge()); System.out.println(); // blank line } while (helper.inputYN().equals("Y")); // Keep reading in people as long as the user answers "Y" System.out.println(); // blank line System.out.println("You entered " + people.size() + " names:"); for (Person onePerson : people) { System.out.println(onePerson); } } }

This is helper.java

import java.util.Scanner; public class Helper { private static final Scanner keyboard = new Scanner(System.in); public int inputAge() { int age = 0; boolean validAge = false; do { // Prompt for the age System.out.print("Enter age: "); // The line of data entered by the user String lineEntered; lineEntered = keyboard.nextLine(); try { // Convert string input to an integer age = Integer.parseInt(lineEntered); } catch (Exception e) { System.out.println("Invalid input"); age = -1; // Will result in an invalid age } validAge = (age >= 0); if (!validAge) { System.out.println("ERROR: age must be 0 or higher"); } } while (!validAge); return age; } public String inputName() { String name = ""; boolean validName = false; do { // Prompt for the name System.out.print("Enter name: "); // Read the name from the keyboard name = keyboard.nextLine(); validName = (name.length() > 0); if (!validName) { System.out.println("ERROR: Please enter a name"); } } while (!validName); return name; } public String inputYN() { String answer = ""; boolean validAnswer = false; do { // Prompt the user to continue System.out.print("Another (Y/N) :"); // Read the answer from the keyboard answer = keyboard.nextLine(); validAnswer = answer.equals("Y") || answer.equals("N"); if (!validAnswer) { System.out.println("ERROR: Enter Y or N"); } } while (!validAnswer); return answer; } 

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

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago