ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 25 May 2017 My Price 9.00

This class represents a Person

1. Use the Person file below to create a Person class. All the code needed should be in that file.
2. Create the PersonExample class starting with the file below and following the instructions in its comments.
3. Create an ObjectsStart file to create an ObjectsStart class and follow the instructions in its comments.

 

Exercise 15.2. Transform the following class method into an object method.

public static double abs(Complex c) {return Math.sqrt(c.real * c.real + c.imag * c.imag);}

Exercise 15.3. Transform the following object method into a class method.

public boolean equals(Complex b) {return(real == b.real && imag == b.imag);}

 

/*This class represents a Person. It stores information regarding theperson's first and last name, age and height.*/public class Person {// The first name of the personprotected String firstName;// The last name of the personprotected String lastName;// The age of the personprotected int age;// The height of the person (in feet)protected double height;// Default person constructor initializes a person to be "Joe Schmo",// age 17 and height 5.11.public Person() {firstName = "Joe";lastName = "Schmo";age = 17;height = 5.11;} // Person()// Constructor initializes a person with first name.public Person(String vName) {firstName = vName;lastName = "Schmo";age = 17;height = 5.11;} // Person(String vName)// Constructor initializes a person with input arguments.public Person(String vFirstName, String vLastName, int vAge, double vHeight){firstName = vFirstName;lastName = vLastName;age = vAge;height = vHeight;} // Person(String vFirstName, String vLastName, int vAge, double vHeight))// Returns the full name of the person.public String getFullName() {return firstName + " " + lastName;} // getFullName// Returns whether the peron's age is under 18.public boolean isAdult() {return age >= 18;} // isAdult// Called if person has had birthday, increments the age of the person.public void hadBirthday() {age = age + 1;} // hadBirthday// Return a string representation of the person.public String toString() {// Create the resulting string.

class PersonExample {public static void main(String[] args) {// Task 1: Declare a Person object reference variable called "x"// Task 2: Using the "new" operator, create a new Person object//with your first name, your last name, your age,//and your height. Assign the object to variable "x".// Task 3: Output the age of the person "x".// Task 4: Call the "hadBirthday()" method on the person "x".// Task 5: Again, output the age of the person "x"// Task 6: Output whether person "x" is an adult// Task 7: Set person "x" first name to be "Jane".// Task 8: Output the full name of person "x"// Output all of the details of person "x".System.out.println(x.toString());} // main} // PersonExample

Attachments:

Answers

(11)
Status NEW Posted 25 May 2017 02:05 AM My Price 9.00

-----------

Not Rated(0)