Use the following template in your HW3.java file. Place yourmethod definitions (with the required identifying
comments) where indicated.
public class HW3 {
/* place your method definitions (with the required identifyingcomments) after this comment */
/* place your method definitions (with the required identifyingcomments) before this comment */
}
Prof. Pitts CS505A: Computer Science Fundamentals Fall 2019 Homework Assignment 4 Submit your answers to the problems below in a sip file called HW4.zip through Canvas by the due date. For each of the programs below, use the exact name given for the java filename. Points will be deducted otherwise. 1. Write a program in Problem1.java. In this program, in addition to the public class Probleml, define a new class called Airplane. The Airplane class should have two private variables to represents the airplane object’s heading (from 0 to 359 degrees as an integer) and the airplane object’s altitude (from 0 to 40,000 as an integer). The Airplane class as the following methods: Airplane(int h, inta): a constructor that initializes the new airplane object with a heading (from h) and an altitude (from a) . String toStringO: a method that represents the airplane object as a Java String . int getHeading0: a method that shows the current heading of the airplane object int get Altitude(): a method that shows the current altitude of the airplane object void change Heading(int v): a method that changes the heading by v degrees. The heading must remain between 0 and 359. That is, if the heading is 355 and it is changed by 20, then the new heading should be (355+20)%360=15. If the heading is 15 and it is changed by -30, then the new heading should be (15+(-30)) + 360 = 345. void change Altituteint v): a method that changes the altitude by v feet. The altitude can not be below O or above 40,000. Write a main method in your problemi class to test your Airplane class that does the following: . Create an airplane object with heading 180 degrees at altitude 20,000 feet. . Then use get Heading and get Altitude() to display the heading and altitude of the new airplane objects. Change the heading by 270 degrees and the altitude by 25,000 feet and display the airplane object (use the variable name with System.out.println() so that the toString will be used. . Change the heading by – 180 degrees and the altitude by -45,000 feet and display the airplane object. . Change the heading by -90 degrees and the altitude by 20,000 feet and display the airplane object. 2. Write a program in Problem2.java. Include the includes AList class. Write two new methods for the AList class: AList append(AList al): this method adds the elements in the AList al to the end of the calling list and retum the calling list. For example, let listi be an AList object with elements 1, 2, 3 (in that order) and list2 be an AList object with elements 4,5,6. Then, list1.append(list2) changes list1 so that it holds elements 1, 2, 3, 4, 5, 6. The other AList object, list2, is unchanged. AList join(AList al): this method does the same a the previous, except list1 is also unchanged. Instead, the method creates a new AList object, copies the calling object to the new object, and then appends al to the new object. That is, AList list3 = list1.join(list2) retums a new object into list3 and list1 and list2 are unchanged. Show transcribed image text Prof. Pitts CS505A: Computer Science Fundamentals Fall 2019 Homework Assignment 4 Submit your answers to the problems below in a sip file called HW4.zip through Canvas by the due date. For each of the programs below, use the exact name given for the java filename. Points will be deducted otherwise. 1. Write a program in Problem1.java. In this program, in addition to the public class Probleml, define a new class called Airplane. The Airplane class should have two private variables to represents the airplane object’s heading (from 0 to 359 degrees as an integer) and the airplane object’s altitude (from 0 to 40,000 as an integer). The Airplane class as the following methods: Airplane(int h, inta): a constructor that initializes the new airplane object with a heading (from h) and an altitude (from a) . String toStringO: a method that represents the airplane object as a Java String . int getHeading0: a method that shows the current heading of the airplane object int get Altitude(): a method that shows the current altitude of the airplane object void change Heading(int v): a method that changes the heading by v degrees. The heading must remain between 0 and 359. That is, if the heading is 355 and it is changed by 20, then the new heading should be (355+20)%360=15. If the heading is 15 and it is changed by -30, then the new heading should be (15+(-30)) + 360 = 345. void change Altituteint v): a method that changes the altitude by v feet. The altitude can not be below O or above 40,000. Write a main method in your problemi class to test your Airplane class that does the following: . Create an airplane object with heading 180 degrees at altitude 20,000 feet. . Then use get Heading and get Altitude() to display the heading and altitude of the new airplane objects. Change the heading by 270 degrees and the altitude by 25,000 feet and display the airplane object (use the variable name with System.out.println() so that the toString will be used. . Change the heading by – 180 degrees and the altitude by -45,000 feet and display the airplane object. . Change the heading by -90 degrees and the altitude by 20,000 feet and display the airplane object. 2. Write a program in Problem2.java. Include the includes AList class. Write two new methods for the AList class: AList append(AList al): this method adds the elements in the AList al to the end of the calling list and retum the calling list. For example, let listi be an AList object with elements 1, 2, 3 (in that order) and list2 be an AList object with elements 4,5,6. Then, list1.append(list2) changes list1 so that it holds elements 1, 2, 3, 4, 5, 6. The other AList object, list2, is unchanged. AList join(AList al): this method does the same a the previous, except list1 is also unchanged. Instead, the method creates a new AList object, copies the calling object to the new object, and then appends al to the new object. That is, AList list3 = list1.join(list2) retums a new object into list3 and list1 and list2 are unchanged.
Expert Answer
Answer to Use the following template in your HW3.java file. Place your method definitions (with the required identifying comments)…