Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone please help me with this Java question? the file is as below. sincerely thanks! Create a class of your own and use a

Can someone please help me with this Java question? the file is as below. sincerely thanks!

Create a class of your own and use a test program to try it out

- Define any new class you choose, but not a Person class

- The class you pick should have at least 3 instance variables, not all of the same type (that is, not all int or double or String, but a mixture)

- edit Person.java and save it as NewClassname.java, then change the class name to your new name and create all of the private instance variables you chose

- Modify the readInput() and writeOutput() methods in the class to set and print out the instance variables as appropriate

the file is as below, I dont know how to upload it so here's a picture and a copy. Thanks! public class Person // in file Person.java - change this to your class name { private String name = ""; // one of the attributes of the Person class, their name // this is initialized to the empty string to show that we have no information yet private int age; // the other attribute of the Person class, their age in whole years // Note: when you do the first Lab exercise, add at least one more instance variable, // and change the variables to be appropriate for the class that you are defining // Just like shown here, your instance variables' types should not all be the same public void readInput() // a void method that does not return a value { final int MIN_AGE = 0, MAX_AGE = 130; // constants for age validation System.out.println("Please enter the person's name: "); name = Keyboard.nextLine(); // uses special Keyboard input class (see Note below) System.out.println("Please enter the person's age in whole years: "); age = Keyboard.nextInt(); // Keyboard has all the same methods as Scanner if (age  MAX_AGE) // true condition if age is not valid { System.out.println("That age is not valid, this program is ending"); System.exit(0); // this special statement ends the program immediately } } // Note: if you use Keyboard you don't have to directly use Scanner or import java.util.* // Download Keyboard.java from Sakai's General Resources folder to Java programs on your VM public void writeOutput() // another void method { if (name.equals("")) // only true if no input information yet { System.out.println("no information yet - no name, no age"); } else { System.out.println("name: " + name + ", age: " + age); } } // Note: when you do the Lab exercise you'll print out all of your instance variables } // Note that the Person class does not have a main() method, so it cannot be run directly 
image text in transcribed 
1 public class Person/1 in file Person.java - change this to your class name private String name""; // one of the attributes of the Person class, their name // this is initialized to the empty string to show that we have no information yet private int age; // the other attribute of the Person class, their age in whole years // Note: when you do the first Lab exercise, add at least one more instance variable, // and change the variables to be appropriate for the class that you are defining // Just like shown here, your instance variables' types should not all be the same 10 public void readInput) // a void method that does not return a value 12 13 14 15 16 17 18 19 20 21 final int MIN-AGE = 0, MAX-AGE 130; // constants for age validation System.out.println ( "Please enter the person's name: "); name Keyboard.nextLine II uses special Keyboard input class (see Note below) System.out.println("Please enter the person's age in whole years: "); ageKeyboard.nextInt(O; // Keyboard has all the same methods as Scanner if (age MAX_AGE) // true condition if age is not valid 23 24 25 26 27 28 29 30 31 32 System.out.println("That age is not valid, this program is ending") System.exit(0); // this special statement ends the program immediately > // Note: if you use Keyboard you don't have to directly use Scanner or import java.util. // Download Keyboard.java from Sakai's General Resources folder to Java programs on your VM public void writeOutput) // another void method if (name.equals("") // only true if no input information yet 34 35 36 37 38 39 40 41 42 43 / Note that the Person class does not have a main) method, so it cannot be run directly System.out.println("no information yet-no name, no age") else System.out.println("name: "name", age: "age); > // Note: when you do the Lab exercise you'1l print out all of your instance variables

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 Management With Website Development Applications

Authors: Greg Riccardi

1st Edition

0201743876, 978-0201743876

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago