Assignment #2  Temperature


Rate this product

Assignment #2
Submit a single file called to cuLearn.
The assignment is out of 100 marks.
1: Temperature [30 marks]
Complete the provided Temperature class. Add any attributes and helper methods as needed.
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
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.
Temperature t = new Temperature(10.1);
System.out.println(t.getScale()); // outputs the char ’C’
System.out.println(t); // outputs 10.1C
System.out.println(t); // outputs 50.18F
System.out.println(t.getScale()); // outputs the char ’F’
Note: Repeatedly changing the scale should not ”change” the value of the temperature. For
Temperature t = new Temperature(10.1);
for(int i=0; i<10000; i+=1){
Should print out identical strings.
Note: You should have no static attributes or methods in your class (unless they were supplied in
the starter code).
Note: Your code must use encapsulation. Your grade will be reduced by 5 marks if you do not use
Mark breakdown: 5 marks for Style, 25 marks for Correctness
Put your file in your file.

2: Extreme Temperatures [30 marks]
Complete the MaxTemp class. The class consists of a single constructor and a single getter method.
• The constructor takes an array of Temperature objects as input.
• The getter method either returns an array of doubles with exactly two doubles in it or returns
null. If the object was created with one more more Temperature objects in the constructor’s
input array then the output consists of the maximum temperature of all Temperature objects
passed to the constructor and a count of how many times that maximum was present in the
array passed to the constructor (in that order). If zero Temperature objects were passed to
the constructor (in the array) then the getter returns null.
Note: The max temperature returned must be displayed in the Kelvin scale.
Note: Different Temperature objects in the array passed to the constructor may have different
temperature scales set for themselves.
Since the Temperature objects will store a floating point number for the temperature, you will
use the provided EPSILON constant in the MaxTemp class and consider two temperatures as equal
if their absolute difference is smaller than EPSILON. Therefore, if Math.abs(temp1 – temp2) <
ESILON then temp1 and temp2 are considered equal.
For example, if the array
new Temperature[]{new Temperature(1001.12, “K”),
new Temperature(-200.0, “F”),
new Temperature(1001.11, “K”)}
is passed to the constructor, and EPSILON = 0.1, then the getMax getter will return [1001.12,
The return value should still display the maximum temperature (in K). In the example above,
even though we consider 1001.11 and 1001.12 the ”same”, 1001.12 is still the max to be returned.
Note: Your code must use encapsulation. Your grade will be reduced by 5 marks if you do not use
Mark breakdown: 5 marks for Style, 25 marks for Correctness
Put your file in your file.

3: Tic-Tac-Toe [40 marks]
Implement the game of Tic-Tac-Toe. Your game must consist of at least three (3) classes: Board,
Player, and TicTacToeApp. You can add more classes if you wish.
• The TicTacToeApp program will run the game, using a Board object and two Player objects.
• The Player class will implement a player in the game. A player could be a human user (and
so user input will be needed) or a computer.
• The Board class will be the board in the game. It can either be a 3×3 grid or a 5×5 grid. The
constructor of the class will create an appropriate grid.
• User input for specifying which grid element in the board will be a comma separated list of
two numbers, where the first number is row (starting at 0) and the second number is the
column (starting at 0). The amount of whitespace around the numbers (and comma) can be
• A single command line argument (for the TicTacToeApp program) will specify if the game
is a 3×3 or 5×5 grid. Acceptable command line arguments will be “3”, “5”, “three” and
“five”. For any other command line argument (or lack) your program will terminate with a
usage message (of how to run the program properly).
• The game board must be displayed before any player makes a move.
• The game should be easy to play.
Note: Style for this problem includes class design. Encapsulation is required.
Mark breakdown: 15 marks for Style, 25 marks for Correctness
Put your,, and any other .java files you
created in your file.
Submission Recap
A complete assignment will consist of a single file ( with at least following five files
included:,,, and

Open chat
Need help?
Can we help you?