Question

Preezing and Bolling Points The following cable lisrs the freezing and boiling points of several substanices. Substance Ethyl Alcohol Oxygen -173 -362 32 Boiling Point 172 -306 212 ter Design a class that stores a temperature in a temperature field and has the appropriate accessor and mutator methods for the field. In addition to appropriate constructors, the class should have the following methods: issthylFreezing. This method should return the boolean value true if the temipera- ture stored in the temperature field is at or below the freezing point of ethyl alcohol. Otherwise, the method should return false. 4sEthylBoiling. This method should return the boolean value true if the tempera- ture stored in the temperature field is at or above the boiling point of ethyl alcohol. Otherwise, the method should return false. , soxygenFreezing. This method should return the boolean value true if the tem perature stored in the temperature field is at or below the freezing point of oxygen Otherwise, the method should return false. isoxygenBoiling. This merhod should return the boolean value true if the e ture stored in the cemperature field is at or above the boiling point of oxygen. Other wise, the method should return false. * İskaterFreezing. This method should return the boolean value true if the tempera- tuce stored in the tempecature field is at or below the freezing point of water Other- . isผatorBoiling. This method should return the boolean value true if the tempera. ture stored in the temper ture field is at or above the boiling point of water Ocher wise, the method should return Ealse. wise, the method should return false. Wrice a program that demonscrares rhe class. The program should ask the user to enter a rempecatere, and then display a list of the substances chat will frecze at that remperature and those chát will boil at chat temperature. For example, if the temperature is -20 the class
Java basic programming course simple as possible use java import and comments to explain the code thanks in advance
0 0
Add a comment Improve this question Transcribed image text
Answer #1

package abc;

public class TemperatureClass {

private float temperature;

public float getTemperature() {

return temperature;

}

public void setTemperature(float temperature) {

this.temperature = temperature;

}

public boolean isEthylFreezing(){

if(this.temperature<=-173){

return true;

}

else{

return false;

}

}

public boolean isEthylBoliing(){

if(this.temperature>=172){

return true;

}

else{

return false;

}

}

public boolean isOxygenFreezing(){

if(this.temperature<=-362){

return true;

}

else{

return false;

}

}

public boolean isOxygenBoliing(){

if(this.temperature>=-306){

return true;

}

else{

return false;

}

}

public boolean isWaterFreezing(){

if(this.temperature<=32){

return true;

}

else{

return false;

}

}

public boolean isWaterBoliing(){

if(this.temperature>=212){

return true;

}

else{

return false;

}

}

}

package abc;

import java.util.Scanner;

public class TempTester {

public static void main(String[] args) {

TemperatureClass temp=new TemperatureClass();

Scanner sc=new Scanner(System.in);

System.out.println("Enter temperature :");

float tempture=sc.nextFloat();

temp.setTemperature(tempture);

System.out.println(checkTemp(temp));

temp.setTemperature(65);

System.out.println(checkTemp(temp));

temp.setTemperature(-264);

System.out.println(checkTemp(temp));

temp.setTemperature(-43);

System.out.println(checkTemp(temp));

}

public static String checkTemp(TemperatureClass temp){

String freeze="";

String boil="";

if(temp.isEthylFreezing()){

freeze=freeze+"Ethyl Alcohol ";

}

if(temp.isOxygenFreezing()){

freeze=freeze+"Oxygen ";

}

if(temp.isWaterFreezing()){

freeze=freeze+"Water";

}

if(temp.isEthylBoliing()){

boil=boil+"Ethyl Alcohol ";

}

if(temp.isOxygenBoliing()){

boil=boil+"Oxygen ";

}

if(temp.isWaterBoliing()){

boil=boil+"Water";

}

if(freeze==""){

freeze="Nothing";

}

if(boil==""){

boil="Nothing";

}

String finalstr=freeze+" will freeze and "+boil+" will boil at this temperature";

return finalstr;

}

}

Expected output:

Add a comment
Know the answer?
Add Answer to:
Java basic programming course simple as possible use java import and comments to explain the code...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java programming course use java import. Follow instructions and comments to explain the code tha...

    java programming course use java import. Follow instructions and comments to explain the code thanks in advance Print L A polymomial can be represented as a linked list, where each node called a polyhede contoins the coefficient and the exponent of a term of the pelynomial For example, The pelynomial 4x-31-5 would be represented as the linked list 3 3xa Write a Polynomial class that has methods for creating a polhynomial, reading and writing a polynomial, and adding a pair...

  • Please help with Java programming! This code is to implement a Clock class. Use my beginning...

    Please help with Java programming! This code is to implement a Clock class. Use my beginning code below to test your implementation. public class Clock { // Declare your fields here /** * The constructor builds a Clock object and sets time to 00:00 * and the alarm to 00:00, also. * */ public Clock() { setHr(0); setMin(0); setAlarmHr(0); setAlarmMin(0); } /** * setHr() will validate and set the value of the hr field * for the clock. * *...

  • this is for java programming Please Use Comments I am not 100% sure if my code...

    this is for java programming Please Use Comments I am not 100% sure if my code needs work, this code is for the geometric if you feel like you need to edit it please do :) Problem Description: Modify the GeometricObject class to implement the Comparable interface and define a static max method in the GeometricObject class for finding the larger (in area) of two GeometricObject objects. Draw the UML and implement the new GeometricObject class and its two subclasses...

  • *** FOR A BEGINNER LEVEL JAVA CLASS, PLEASE KEEP CODE SIMPLE, AND WE USE BLUE J...

    *** FOR A BEGINNER LEVEL JAVA CLASS, PLEASE KEEP CODE SIMPLE, AND WE USE BLUE J IN CLASS (IF IT DOESNT MATTER PLEASE COMMENT TELLING WHICH PROGRAM YOU USED TO WRITE THE CODE, PREFERRED IS BLUE J!!)*** ArrayList of Objects and Input File Use BlueJ to write a program that reads a sequence of data for several car objects from an input file. It stores the data in an ArrayList<Car> list . Program should work for input file containing info...

  • Java Homework Help. Can someone please fix my code and have my program compile correctly? Thanks...

    Java Homework Help. Can someone please fix my code and have my program compile correctly? Thanks for the help. Specifications: The class should have an int field named monthNumber that holds the number of the month. For example, January would be 1, February would be 2, and so forth. In addition, provide the following methods. A no- arg constructor that sets the monthNumber field to 1. A constructor that accepts the number of the month as an argument. It should...

  • please do in java and comments the code so i can understand Requirements: Create a Java...

    please do in java and comments the code so i can understand Requirements: Create a Java class named “MyRectangle2D.java”. Your class will have double two variables named x and y. These will represent the center point of your rectangle. Your class will have two double variables named width and height. These will represent the width and height of your rectangle. Create getter and setter methods for x, y, width, and height. Create a “no argument” constructor for your class that...

  • please explain this Java problem with source code if possible Project: Strictly identical arrays Problem Deseription:...

    please explain this Java problem with source code if possible Project: Strictly identical arrays Problem Deseription: Two arrays are strictly identical if their correspondimg elements are equal Write a program with class name StrictlyIdentical that prompts the user to enter two lists ed integers of size 5 and displays whether the two are strictly identical. Usc following method header to pass two arrays and retum a Boolcan public static boolean cualsint[] array 1, int[] array2) Method will return true if...

  • Write code in Java programming language. The ShoppingCart class will be composed with an array of...

    Write code in Java programming language. The ShoppingCart class will be composed with an array of Item objects. You do not need to implement the Item class for this question, only use it. Item has a getPrice() method that returns a float and a one-argument constructor that takes a float that specifies the price. The ShoppingCart class should have: Constructors: A no-argument and a single argument that takes an array of Items. Fields: • Items: an array of Item objects...

  • In Java programming language Please write code for the 6 methods below: Assume that Student class...

    In Java programming language Please write code for the 6 methods below: Assume that Student class has name, age, gpa, and major, constructor to initialize all data, method toString() to return string reresentation of student objects, getter methods to get age, major, and gpa, setter method to set age to given input, and method isHonors that returns boolean value true for honors students and false otherwise. 1) Write a method that accepts an array of student objects, and n, the...

  • [Continued] Your Course class should have: 1)a getter for the course 'code', so that it is...

    [Continued] Your Course class should have: 1)a getter for the course 'code', so that it is read-only; 2)a getter and setter for the lecturer attribute, so that it is readable and writable; 3)a constructor that creates the associations shown in the UML diagram; 4)an enrolStudent method that adds a given Student object into the 'enrolled' set; 5)a withdrawStudent method that removes a given Student object from the 'enrolled' set and returns true if the student was successfully found and removed,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT