Intellectual Property Threats and Mineral Rights
July 13, 2020
Diagnosing and Treating PTSD
July 13, 2020
Show all

Objects and Classes

Use Netbeans
One class, one file. Don’t create multiple classes in the same .java file
Don’t use static variables and methods
Encapsulation: make sure you protect your class variables and provide access to them through get and set methods
all the classes are required to have a constructor that receives all the attributes as parameters and updates the attributes accordingly
all the classes are required to have an “empty” constructor that receives no parameters but updates all the attributes as needed
Follow Horstmann’s Java Language Coding Guidelines
Organized in packages (MVC – Model – View Controller)

Create a NetBeans project with
<default package>
App.java
Person.java
Functionality
The application App creates 5 Person objects
using the data below
name=Marcus Allen, weight=200, hometown=Upper Marlboro, Md., highSchool=Dr. Henry A. Wise, Jr.
name=Kyle Alston, weight=180, hometown=Robbinsville, N.J., highSchool=Robbinsville
name=Troy Apke, weight=220, hometown=Mt. Lebanon, Pa., highSchool=Mount Lebanon
name=Matthew Baney, weight=225, hometown=State College, Pa., highSchool=State College
name=Saquon Barkley, weight=222, hometown=Coplay, Pa., highSchool=Whitehall

The classes

App
it has the main method which is the method that Java looks for and runs to start any application
it creates creates 5 Person objects
it displays information about each object using the toString() method

Person
uses encapsulation
private attributes
a get and a set method for each attribute
has the following attributes
String name;
int weight;
String hometown;
String highSchool;
has two constructors
one with no parameters
one with all the parameters (one for each attribute)
a toString( ) method

Output
The display information will look like:

Person{name=Marcus Allen, weight=200, hometown=Upper Marlboro, Md., highSchool=Dr. Henry A. Wise, Jr.}
Person{name=Kyle Alston, weight=180, hometown=Robbinsville, N.J., highSchool=Robbinsville}
Person{name=Troy Apke, weight=220, hometown=Mt. Lebanon, Pa., highSchool=Mount Lebanon}
Person{name=Matthew Baney, weight=225, hometown=State College, Pa., highSchool=State College}
Person{name=Saquon Barkley, weight=222, hometown=Coplay, Pa., highSchool=Whitehall}

Leave a Reply

Your email address will not be published. Required fields are marked *