Write a Temperature class that represents temperatures in degrees in both Celsius and Fahrenheit. Use a floating-point number for the temperature and a character for the scale: either ‘C’ for Celsius or ‘F’ for Fahrenheit. The class should have
- Four constructors one for the number of decrees, one for the scale, one for both the decrees and the scale, and a default constructor. For each of these constructors, assume zero degrees if no value is specified and Celsius if no scale is given.
- Two accessory methods one to return the temperature in degrees Celsius, the other to return it in degrees Fahrenheit. Use me formulas from Practice Program 5 of Chapter 3 and round to the nearest tenth of a degree.
- Three set methods: one to set the number of degrees, one to set the scale, and one to set both.
- Three comparison methods: one to test whether two temperatures are equal, one to test whether one temperature is greater than another, and one to test whether one temperature is a less man another.
Write a driver program that tests all the methods. Be sure to invoke each of the constructors, to include at least one true and one false case for each comparison method, and to test at least the following three temperature pairs for equality; 0.0 degrees C and 32.0 degrees F, –40.0 degrees C and –40.0 degrees F, and 100.0 degrees C and 212 0 degrees F.
Want to see the full answer?
Check out a sample textbook solutionChapter 6 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Additional Engineering Textbook Solutions
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Starting Out with Java: From Control Structures through Objects (6th Edition)
C++ How to Program (10th Edition)
Digital Fundamentals (11th Edition)
Modern Database Management (12th Edition)
Modern Database Management
- You have to make a class and in which a variable is present and you have to perform addition of 2 number which is passed from one constructor to another constructor means both are overloaded. You have to make object of that and print the result In javaarrow_forwardCreate a class named Pay that includes five double variables that hold hours worked, rate of pay per hour, withholding rate, gross pay, and net pay. Create three overloaded computeNetPay() methods. When computeNetPay() receives values for hours, pay rate, and withholding rate, it computes the gross pay and reduces it by the appropriate withholding amount to produce the net pay. (Gross pay is computed as hours worked multiplied by pay per hour.) When computeNetPay() receives two parameters, they represent the hours and pay rate, and the withholding rate is assumed to be 15%. When computeNetPay() receives one parameter, it represents the number of hours worked, the withholding rate is assumed to be 15%, and the hourly rate is assumed to be 5.85. Write a main() method that tests all three overloaded methods. Save the application as Pay.java.arrow_forwardWrite a class that prompts the user for the day’s high and low temperatures. If the high is greater than or equal to 90 degrees, display the message, “Heat warning.” If the low is less than 32 degrees, display the message “Freeze warning.” If the difference between the high and low temperatures is more than 40 degrees, display the message, “Large temperature swing.”arrow_forward
- Write a class to represent a thermometer. The class must provide aparameterless constructor that initializes the temperature of the thermometer to37o Celsius (the average human body temperature). Store the temperature as afield in the celsius scale.Your class should provide methods to get and set the temperature using degreesCelsius, Fahrenheit, or Kelvin. For example, assume that the Celsius methodmay be used to set the temperature to 100oC. If the method to get thetemperature in Fahrenheit is called, it should return 212 (the equivalent of100oC). If the Fahrenheit method is used to set the temperature to 32oF, then themethod to retrieve the temperature in degrees Kelvin should return 273.15.To be clear, your thermometer keeps track of one temperature value (that youmay store using any scale that you like). It provides methods to set and retrievethe value using any of the three scales.Make sure to include a toString method that prints the current temperature inall 3 scales. Update…arrow_forwardWrite Rectangle class to represent a rectangle. The class contains:a. Two double data fields named width and height that specify the width and height ofthe rectangle. The default values are 1 for both width and height.b. A no-arg constructor that creates a default rectangle.c. A constructor that creates a rectangle with the specified width and height.d. A method named getArea() that returns the area of this rectangle.e. A method named getPerimeter() that returns the perimeter. in Javaarrow_forwardI just want you to do the second part only using java class, but i have attached the answer for assignment 1. Assignment 1 question Loan Account Class: Create class LoanAccount. Use a static variable annualInterestRate to store the annual interest rate for all account holders. Each object of the class contains a private instance variable principal indicating the amount the person is borrowing. Provide method: public double calculateMonthlyPayment(int numberOfPayments) to calculate the monthly payment by using the following formula: double monthlyPayment = principal * ( monthlyInterest / (1 - Math.pow(1 + monthlyInterest, -numberOfPayments))); where monthly interest = annualInterestRate/12. Provide a static method setAnnualInterestRate that sets the annualInterestRate to a new value. Set the initial loan amount (Principal) for a new loan through the constructor. Write a program to test class LoanAccount. Instantiate two LoanAccount objects, loan1 and loan2, with principal loan…arrow_forward
- PYTHON Build the ItemToPurchase class with the following specifications: Attributes item_name (string)item_price (int)item_quantity (int)Default constructor Initializes item's name = "none", item's price = 0, item's quantity = 0Methodprint_item_cost() Ex. of print_item_cost() output: Bottled Water 10 @ $1 = $10In the main section of your code, prompt the user for two items and create two objects of the ItemToPurchase class. Ex: Item 1Enter the item name:Chocolate ChipsEnter the item price:3Enter the item quantity:1 Item 2Enter the item name:Bottled WaterEnter the item price:1Enter the item quantity:10 Add the costs of the two items together and output the total cost. Ex: TOTAL COSTChocolate Chips 1 @ $3 = $3Bottled Water 10 @ $1 = $10 Total: $13arrow_forwardWrite a convertToMetric class that has the following field: standard - holds a double, standard length value in feet. The class should have the following methods: Constructor - that accepts a length in feet (as a double) and stores it in the standard field. setStandard - accepts a standard length in feet and stores it in standard. getStandard - returns the value of the standard field, as a length in feet, no conversion required. getMeters - returns the value of the standard field converted to meters. getCentimeters - returns the value of the standard field converted to centimeters A second class will be created and used to test the new object class. This, executable class, is to instantiate an object of 'convertToMetric' type. Then it will allow the user to use keyboard input to input a value for standard. That value will then be converted to meters and centimeters, and displayed. Make sure that your output (or display) is user-friendly or easy to read and understand. You should…arrow_forwardI need to write a jave program to keep track of a team sport. Write a class, Team.java, that has the following: * two private instance variables: a String named color and an int named score. * a default constructor with no parameters that initializes color to "Red" and score to zero. * a constructor that takes two parameters (one for each instance variable) and sets the values of the instance variables. * a public getter and setter method for each instance variable. * a toString method that returns the color and score in the following format: "Red Team with 0 points."arrow_forward
- In this exercise, you have to calculate the student's total marks using the concept of Classes Problem Statement# Write a Java class called Student with ● private fields: ○ name(String type) ○ mark1 and mark2 (double type) And methods: ● getMarks(int markNumber), a method which should return mark1 if markNumber equals 1 and mark2 otherwise. ● calcTotal() method should take the two marks entered and return their sum. Also define two constructors: ● A default constructor that takes no parameters and initializes the values to zeros and null. ● A constructor that takes the three variables and sets them as the values of the appropriate fields. Input# Name of the student and the marks obtained in the first and second tests Output# Sum of both marks Sample Input# Student student = new Student("Jack", 60, 70); Sample Output# getMarks(1) => 60 getMarks(2) => 70 calcTotal() => 130.0 Part of solution class Student { // Define private fields here public Student() { // Write…arrow_forwardIn this assignment, you will implement a simple game in a class called SimpleGame. Thisgame has 2 options for the user playing. Based on user input, the user can choose to eitherconvert time, from seconds to hours, minutes, and seconds, or calculate the sum of all digits inan integer.arrow_forwardI need to create this coding: (JAVA PROGRAMMING) Write a program by creating an Employee class. This class has three instance variables: name, which is a String representing the name of the Employee numberOfHoursPerDay, which is an int representing the number of hours the employee has worked per day salary, which is an int representing the salary of the employee per-hourly basis 1. Create getter and setter methods of all the instance variables 2. Write a constructor for the class Employee, which takes a String representing the name 3. Write a method getInfo() which takes the salary, number of hours of work per day of an employee as a parameter 4. Write a method addSal() which adds $10 to the salary of the employee if it is less than $500. 5. Write a method addWork() which adds $5 to the salary of the employee if the number of hours of work per day is more than 6 hours. 6. Write a caller class and create an object of class Employee then call the methods getInfo, addSal, addWork and…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT