computer programming 2
Tester Class 6. (15 points) Implement a P2Tester class (with main method) that will test all the classes and all its methods. Below is a general pattern you can follow but make necessary adjustments according to the class: a. Create object from class b. Print the instance variables c. Modify the instance variables d. Print the instance variables again e. Repeat Steps b-d if there are multiple methods that modify the instance variables of the object Submission Upload your Java Project as a .zip file to Blackboard under Submit Assignments -> Project 2. Name your file as YourUsername_P2.zip e.g. If I were to upload it, it would be mutsuday_P2.zip Include the following information as a comment at the top of the P2Tester file: your name your Bearcat email address Yaragraph 1. (10 points) Model an Employee as a class. An employee has a name (a string) and a salary (a double). These are the instance variables. Provide a constructor with no parameters and sets the employee's name to and salary to 0. public Employee Write appropriate mutator/setter and accessor/getter methods for each instance variable, 2. (10 points) Implement a class Balloon. A balloon has a radius (a double) which is the instance variable. A balloon can be inflated, PO Provide a constructor with no parameters but sets the radius of a Balloon to 0. public Balloon Write a mutator method which increases the radius of the balloon by a certain amount pubise vosdanflats double amount) Write an accessor method to return the radius puble double stad Write another accessor method that returns the current volume of a Balloon puble doute Volume (4.0/2.0 PUN dive an example with correct values Use Math for the value of no computer just user Tel. Focus 3. (10 points) Write a class Battery that models a rechargeable battery. A battery has capacity (Instance variable) which can be drained. Capacity is a double value measured in milliampere hours.(mAh. re IT 2045 Proved Spring 2021 Assume that a typical AA battery has a capacity of 3000 mAh, Use a Class Variable called totalCapacity of type double to store this number in your class. Write a constructor with no parameters and sets the capacity to totalCapacity as every battery created from this class will have a total capacity of 3000 mAh, puble Batter Write an accessor method that gets the current capacity of the battery Dubladouble stet part Write a mutator method that drains the capacity of the battery by a certain amount Tube wond in den Whiteutator method that changes the battery to its original capacity. Notice that this method has no argument but it changes the instance Variable soita mutator. Foare Styles 4. (10 points) Left Initial Position Right Write a class Bug that models a bug moving along a horizontal line. The bug moves either to the right or left. Initially, the bug moves to the right, but it can turn to change its direction. In each move, its position changes by one unit in the current direction. Declare two instance variables: current Peristen and direction Provide a constructor public Buaint Animal Region) and accessor/mutator methods public int geraison public void movie public void turn Sample code for testing; Bug busta = new Bug (10) scarta at initial position 10 buggy.move(): V Now the position 15 11 hugsove ( Now the position 11 12 Syatem.out.println(bussy.getBeton) should print 12 bugeturn Now the direction has changed buce og Now the position 11 Semus.Prin und should prang 1 5. (10 points) Create a class called Message that models an email message. A message has a recipient, a sender and a message text. It also has a class/Static variable called Qum Message: a. An email message has three properties: sender, recipient and text. T 2045 Project 2 Spring 2021 b. Write a constructor that takes a sender and a recipient as arguments. It also increments the class variable by 1. c. Write a method append that adds/sets text to the message text. Should this method have any arguments or return a value? Is this a mutator or an accessor method? d. Write a method composeMessage that formats the recipient, sender and message text into one long string like this "From: Harry MorganinTo: Mary Smithin Message... M and returns it. Should this method have any arguments or return a value? Is this a mutator or an accessor method? e Print the class/static variable in your Tester class. 12:08 Project 2. Name your file as YourUsername_P2.zip e.g. If I were to upload it, it would be mutsuday_P2.zip Include the following information as a comment at the top of the P2Tester file: your name your Bearcat email address Dashboard Calendar To Do Notifications Inbox 4. (10 points) Left Position Binitial Right Write a class Bug that models a bug moving along a horizontal line. The bug moves either to the right or left. Initially, the bug moves to the right, but it can turn to change its direction. In each move, its position changes by one unit in the current direction. Declare two instance variables: current Position and direction Provide a constructor public Bug (int initialPosition) and accessor/mutator methods public int get Position() public void move() public void turn() Sample code for testing: Bug bugsy = new Bug (10); //starts at initial position 10 bugsy.move(); // Now the position is 11 bugsy.move(); // Now the position is 12 System.out.println (bugsy.get Position (); // should print 12 bugsy.turn(); // Now the direction has changed bugsy.move(); // Now the position is 11 System.out.println (bugsy.get Position (); // should print 11 2. (10 points) Implement a class Balloon A balloon has a radius (a double, which is the instance variable. A balloon can be inflated Provide a constructor with no parameters but sets the radius of a Balloon to 0. public Balloon () Write a mutator method which increases the radius of the balloon by a certain amount public void inflate (double amount) Write an accessor method to return the radius public double getRadius() Write another accessor method that returns the current volume of a Balloon. public double getVolume () Volume = (4.0/3.0) * Pl*r3. ---give an example with correct values Use Math.PI for the value of n. To compute r^3, just use rrr. 3. (10 points) Write a class Battery that models a rechargeable battery. A battery has capacity (instance variable) which can be drained. Capacity is a double value measured in milliampere hours (mAh) Assume that a typical AA battery has a capacity of 3000 mAh. Use a Class Variable called totalCapacity of type double to store this number in your class. Write a constructor with no parameters and sets the capacity to totalCapacity as every battery created from this class will have a total capacity of 3000 mAh. public Battery() Write an accessor method that gets the current capacity of the battery. public double getCapacity () Write a mutator method that drains the capacity of the battery by a certain amount public void drain (double amount) Write a mutator method that charges the battery to its original capacity. Notice that this method has no argument but it changes the instance variable so it is a mutator. public void charge() 1. (10 points) Model an Employee as a class. An employee has a name (a string) and a salary (a double). These are the instance variables. Provide a constructor with no parameters and sets the employee's name to and salary to 0. public Employee () Write appropriate mutator/setter and accessor/getter methods for each instance variable. 5. (10 points) Create a class called Message that models an email message. A message has a recipient, a sender and a message text. It also has a Class/Static variable called numMessage. a. An email message has three properties: sender, recipient and text. b. Write a constructor that takes a sender and a recipient as arguments. It also increments the class variable by 1. c. Write a method append that adds/sets text to the message text. Should this method have any arguments or return a value? Is this a mutator or an accessor method? d. Write a method composeMessage that formats the recipient, sender and message text into one long string like this "From: Harry Morgan To: Mary Smith Message:..." and returns it. Should this method have any arguments or return a value? Is this a mutator or an accessor method? e. Print the class/static variable in your Tester class. Tester Class 6. (15 points) Implement a P2 Tester class (with main method) that will test all the classes and all its methods. Below is a general pattern you can follow but make necessary adjustments according to the class: a. Create object from class b. Print the instance variables c. Modify the instance variables d. Print the instance variables again e. Repeat Steps b-d if there are multiple methods that modify the instance variables of the object