guidelines must have at least 1 method extra credit: 1) using a void method outp
ID: 3633968 • Letter: G
Question
guidelines
must have at least 1 method
extra credit:
1) using a void method output the table, use printf instead of print or println
2) have the program keep repeating until the word exit
is entered for the temperature
(this means you will have to enter the data as a string.
do a string comparison on the input data, and if it is not the word exit
you will have to convert the number that was input as a string into an integer (see parseInt(); --you may want to look up the while, and do..while. it can be done with a for loop, - look up break; ))
Explanation / Answer
Dear,
import java.io.*;
import java.util.Scanner; // Needed for Scanner class
class Substance
{
private int temperature;
//constructor
public Substance()
{
temperature=0;
}
//parameterized constructor
public Substance(int temp)
{
temperature=temp;
}
//mutator function sets temperature value
public void setTemperature(int temp)
{
temperature=temp;
}
//accessor function returns temperature
public int getTemperature()
{
return temperature;
}
// returns true if ethyl freezes
public boolean isEthylFreezing()
{
if(temperature<=-173 )
return true;
else
return false;
}
// returns true if ethyl boils
public boolean isEthylBoiling()
{
if(temperature>=172)
return true;
else
return false;
}
// returns true if oxygen freezes
public boolean isOxygenFreezing()
{
if(temperature<=-362)
return true;
else
return false;
}
// returns true if oxygen boils
public boolean isOxygenBoiling()
{
if(temperature>=-306)
return true;
else
return false;
}
// returns true if water freezes
public boolean isWaterFreezing()
{
if(temperature<=32)
return true;
else
return false;
}
// returns true if water boils
public boolean isWaterBoiling()
{
if(temperature>=212)
return true;
else
return false;
}
}//end substance class
class TestClass
{
public static void main(String [] args)
{
//creating instances
Substance item1=new Substance();
int temp;
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
//inputting temperature from console
System.out.println("Enter Temperature :");
temp= keyboard.nextInt();
item1.setTemperature(temp);
//check for temperature freezing and boiling
//validate for ethyl boiling
if(item1.isEthylBoiling())
System.out.println("Ethyl will boil");
//validate for ethyl freezing
if(item1.isEthylFreezing())
System.out.println("Ethyl will Freeze");
//validate for oxygen freezing
if(item1.isOxygenFreezing())
System.out.println("Oxygen will Freeze");
//validate for oxygen boiling
if(item1.isOxygenBoiling())
System.out.println("Oxygen will Boil");
//validate for water freezing
if(item1.isWaterFreezing())
System.out.println("Water will Freeze");
//validate for water boiling
if(item1.isWaterBoiling())
System.out.println("Water will Freeze");
//exit program
System.exit(0);
}
}
Hope this will help you.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.