I need to create a comlicated java class
Write a class Person that correctly compiles and runs with the following TestPerson code. You cannot change a single thing in the TestPerson class. Your Person class should keep track of a person's name, how much money that have on them (in dollars), and whether or not they are happy. The Person class needs to implement the methods used in the code below. Here are a few special notes on some of the methods:
* The Person constructor sets the amount of dollars the person has to $50 if the initial dollar amount is invalid (i.e., less than zero).
* The spend method does nothing if the value they try to spend is less than zero. If they try to spend more than they currently have, then all that person's money is spent (i.e., if the person has $10 and they try to spend $30, then they spend all of the $10 and the amount they have left is $0).
* The canAfford method just returns true or false, indicating whether or not the person can afford something of the requested amount. The amount of money the person has does not change when this method is called.
* When the says method is called, the person "says" (prints to the console) one of two phrases -- either "My name is X and I am doing great!" if they are currently happy, or else "My name is X and I could be better." if they are not currently happy (X is replaced with their name).
TestPerson
public class TestPerson
{
public static void main(String [] args)
{
Person pete = new Person("Townsend", 100, true);
Person marie = new Person("Osmond", 500, false);
pete.spend(10);
pete.spend(5);
pete.spend(5);
System.out.println(pete.toString());
pete.earned(200);
System.out.println(pete);
pete.says();
System.out.println("Can Pete afford something that is $3?");
if (pete.canAfford(3))
System.out.println("Yes, Pete can afford that");
else
System.out.println("Nope, too much!");
System.out.println("Can Pete afford something that is $500?");
if (pete.canAfford(500))
System.out.println("Yes, Pete can afford that");
else
System.out.println("Nope, too much!");
if (pete.isHappy())
System.out.println("Yes");
else
System.out.println("No");
marie.spend(-10);
System.out.println(marie);
marie.earned(-100);
System.out.println(marie);
marie.spend(20000);
System.out.println(marie);
marie.earned(30);
marie.earned(30);
int current = marie.getDollars();
System.out.printf("Marie currently has %d dollars\n", current);
if (marie.isHappy())
System.out.println("Yes");
else
System.out.println("No");
Person george = new Person("Bush", -10, true);
String s = george.toString();
System.out.println(s);
System.out.printf("Currently has: %d\n", george.getDollars());
george.setHappy(false);
george.says();
}
}
Required Output
Townsend has 80 dollars
Townsend has 280 dollars
My name is Townsend and I am doing great!
Can Pete afford something that is $3?
Yes, Pete can afford that
Can Pete afford something that is $500?
Nope, too much!
Yes
Osmond has 500 dollars
Osmond has 500 dollars
Osmond has 0 dollars
Marie currently has 60 dollars
No
Bush has 50 dollars
Currently has: 50
My name is Bush and I could be better.