Can you complete the Temperature class and complete the other classes in problem 2. Write the problems using a text editor known as Visual Studio Code. Send the solution in java file extension
COMP1406 Assignment #2 Due Friday, November 12 at 11:59 pm COMP1006/1406 – Fall 2021 Submit your five .java files to brightspace. There are 30 possible marks. 1 Temperature [10 marks] 10 Marks : All marks for this problem are correctness marks. Complete the provided Temperature class. Add any attributes and helper methods as needed but keep in mind that testing will involve only the methods you are asked to write/complete. You must complete the constructors and methods in the provided class (without changing any signatures, return types, or modifiers). In this problem you will need to be able to convert temperatures between Celsius, Fahrenheit and Kelvin. For help, see https://en.wikipedia.org/wiki/Conversion_of_units_of_temperature A Temperature object holds a single temperature and displays it in one of the three scales. Once a scale has been set, it will display the temperature in that scale until changed. The default scale is Celsius if not specified. The three scales are represented by an Enum class (Scale.java). For this assignment, the pur- pose of the enum class is to provide a consistent naming scheme for the different scales. Essentially, we assign fixed names for the three scales and use these everywhere in the code much like we would if we declared static final strings in our class. The compiler checks if the names are right. If we used Strings instead, and if you spelled the scale incorrectly (easy to do with these words), you would fail all the auto-testing. With enums, if you spell them incorrectly the code won’t compile letting you know. How do you use an enum? They are simple to use. You do not create them with the new operator and you do not need to use .equals to compare them. You just use them as place-holders for the value we want. (Also, see Tutorial 4.) Scale s = Scale.CELCIUS; // a variable of an enum type Temperature t1 = new Temperature(33.1, s); Temperature t2 = new Temperature(87.2, Scale.FAHRENHEIT); boolean b = Scale.CELCIUS == s; // will be true! can compare with == For one of the constructors, you are allowed to pass a string to specify the scale. It should allow for some flexibility in the input by accepting any prefix (in any case) of one of the valid temperature names. For example, ”FAHRENHEIT”, ”Fahr”, ”f” and ”FaHReNHeI” should be all accepted and interpreted as Fahrenheit (Scale.FAHRENHEIT). Inputs that are not valid prefixes must result in a created object that has temperature 0 Kelvin (using the scale Kelvin). So, ”FAR”, ”Selcius” and ”Kalvin” would create this zero Kelvin object. Some examples of using a Temperature object: Temperature t = new Temperature(10.1); System.out.println(t.getScale()); // outputs Scale.CELSIUS.toString() System.out.println(t); // outputs 10.1C t.setScale(Scale.FAHRENHEIT); // change scale System.out.println(t); // outputs 50.18F COMP1006/1406 - Fall 2021 1 https://en.wikipedia.org/wiki/Conversion_of_units_of_temperature Assignment #2 Due Friday, November 12 at 11:59 pm System.out.println(t.getScale()); // outputs Scale.FAHREHEIT.toString() t = new Temperature(12.25, "Kel"); // must recognize short form System.out.println(t); // outputs 12.25K t = new Temerature(99.9, "Far"); // bad input! System.out.println(t); // outputs 0.0K Note: You should have no static attributes or methods in your class (unless they were supplied in the starter code; or unless you have a main method for your own testing). A program called SimpleTemperatureProgram is provided with the code shown above that you can use as a starting point for your own testing if you wish. Submit your Temperature.java file to brightspace along with your .java files. 2 Shapes [20 marks] 20 Marks : All marks for this problem are correctness marks. In this problem, you are given an abstract Shape class and will need to complete four concrete subclasses of it. All shapes have an (x,y) coordinate that anchors the shape in the x-y plane. The XYCoord class is used to store (x,y) coordinates. All shapes can compute their own area and circumference1. Each of the concrete classes will have a constructor that is appropriate for the particular shape detailed as follows: public Rectangle(XYCoord anchor, double length, double width) public Square(XYCoord anchor, double length) // a square’s length and width are the same public Triangle(XYCoord p1, XYCoord p2, XYCOord p3) // p1, p2, p3 are the three coordinates of the corners of the triangle // p1 is also the anchor coordinate for this shape public Circle(XYCoord center, double radius) // center is also the anchor coordinate 1While circumference is usually used for a circle and perimeter is used for rectangles and triangles, we use the word circumference for any shape. It is the total length of the shape’s outline. COMP1006/1406 - Fall 2021 2 Assignment #2 Due Friday, November 12 at 11:59 pm You can use the provided ShapeExampleApp to help test your code. Do NOT change or submit the provided Shape.java file. When testing, we will use the version that was provided with the assignment. Be sure to make all FOUR concrete classes as the example app (and the testing code) will not compile unless all FOUR classes are present. Submit your Rctangle.java, Square.java, Triangle.java and Circle.java files to brightspace along with your other .java file. Submission Recap A complete assignment will consist of a FIVE files: Temperature.java, Rectangle.java, Square.java, Triangle.java and Circle.java. Brightspace will delete your previous submissions. Be sure to submit ALL of your files each time you submit. COMP1006/1406 - Fall 2021 3 Temperature [10 marks] Shapes [20 marks]