Write a class called temperature that has two variables

Assignment Help Computer Engineering
Reference no: EM132170643

Using JAVA

Write a class called Temperature that has two instance variables: a temp value (a floating-point number - data type double) and a character for the scale, either ‘C' for Celsius or ‘F' for Fahrenheit. The class should have a constructor that sets each instance variable (assume zero degrees if no temp value is specified and Celsius if no scale is specified), and it should include the following methods:

1. two accessor methods: one to return the degrees Celsius and the other to return the degrees Fahrenheit- use the following formulas to write the two methods: DegreesC = 5(degreesF - 32)/9 DegreesF = (9(degreesC)/5) + 32

2. three mutator methods: one to set the value, one to set the scale ( F or C ), and one to set both;

3. a comparison method: it should return -1 if the invoking temperature is less than the argument temperature, 0 if they are equal and 1 if the invoking temperature is greater than the argument one;

4. a toString method: returns a String representing the calling Temperature object. The numeric value of the temperature should be rounded to the nearest tenth of a degree. For example, System.out.println(new Temperature(98.164555, F)); //should print: 98.2 F

Then write a driver program called TempTester that tests all the methods from the Temperature class. Example tests: 0.0 degrees C = 32.0 degrees F, -40.0 degrees C = -40.0 degrees F, and 100.0 degrees C = 212.0 degrees F.

Reference no: EM132170643

Questions Cloud

Yield the maximum net benefits : Suppose total benefits and total costs are given by B(Y) = 100Y - 8Y2 and C(Y) = 10Y2. What level of Y will yield the maximum net benefits?
What is the net present value of purchasing the tractor : The tractor costs $9,000 today, while the above cost savings will be realized at the end of each year. If the interest rate is 7 percent.
Write a test program to declare and initialize two integer : Write a test program (main) to declare and initialize two integer arrays of size entered by the user, invoke the method logicAnd, then display the array result.
Demand for a good tends to be more inelastic when : Other things equal, the demand for a good tends to be more inelastic when?
Write a class called temperature that has two variables : Write a class called Temperature that has two instance variables: a temp value (a floating-point number - data type double) and a character for the scale.
Sustain the company competitive advantage : How can new Starbucks CEO Kevin Johnson sustain the company's competitive advantage? What are some growth opportunities he could pursue?
Write a program that detects a palindrome : Using Java Write a program that detects a palindrome. A palindrome is a word or phrase that reads the same backwards and forwards.
Functions and responsibilities of the federal reserve : What are the components of U.S. money supply and what are the functions and responsibilities of the Federal Reserve?
Implement the the given operations as their own methods : Implement the the given operations as their own methods. You are allowed to use the code provided under Support Documents as a starting point.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Define the random variable x to be the amount

In order to attract more customers, the Hyacintho Cactus Bar and Grill in downtown Ottawa organizes a game night, hosted by their star employee Tan Tran.

  What is the difference between a clock cycle and a bus cycle

The 68000 has three interrupt request inputs, IPL0*--IPL2*, that indicate the level of the interrupt request. Because peripherals have a single interrupt.

  Draw binary search trees that function insert will construct

Draw the binary search trees that function insert will construct for the list of 14 names presented in each of the following orders and inserted.

  Combine all 16 numbers into a single vector

Transform each row separately using an eight-point DCT. Plot the resulting 16 transform coefficients.- Combine all 16 numbers into a single vector and transform it using a 16-point DCT. Plot the 16 transform coefficients.

  Explaining the hci theories

Imagine you are the manager of a medium-sized IT department. While walking through the hall one day, you overhear a senior-level software developer telling.

  Writing into file utilizing fileinputstream

Write down an application utilizing the FileInputStream which opens a file which consists of the name of user's favourite book and then show it to the user.

  What is the highest temperature experienced by any of fluid

Computer analysis of Problem with q"s = const and constituted properties: Calculate the flow, starting with initial conditions of flat velocity and temperature.

  Recognizing the error in code

Suppose that the variable A is an arrays of ints. Take the following code segment:Boolean flag = false;

  Design a sequential circuit whose state diagram is given

Design a sequential circuit whose state diagram is given in Fig. using a 3-bit register and a 16 x 4 ROM.

  What classes and methods will you need

Think through problems that you need to solve. What classes and methods will you need? Produce a set of CRC cards, a UML diagram, and a set of javadoc comments.

  Prepare a professional web

Prepare a professional web design and development proposal in the form of a PowerPoint presentation (25-30 slides) that will inform and impress the client

  What are the two models of interprocess communication

What are the two models of interprocess communication? What are the strengths and weaknesses of the two approaches?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd