SlideShare a Scribd company logo
1 of 11
Write a Temperature class that represents temperatures in
degrees in both Celsius and Fahrenheit. Use a floating-point
number for the temperature and character for the scale: either
'C' for Celsius or 'F' for Fahrenheit. The class should have
Four constructor: one for the number of degrees. one for the
scale, one for both the degrees 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 accessor methods: one to return the temperature in degrees
Celsius, the other to return it in degrees Fahrenheit. Use the
formulas as listed below from Practice Program 5 of Chapter 3
and round to the nearest tenth of a degree. C = 5 (F - 32)/9 F =
9 * C/5 + 32 Three set methods: one to set the number of
degree, one to set 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 less than another. Write a
driver program (a demonstration program using main method)
that tests all the methods. Begin the demo program by
displaying: Program title Java class code (CSCl-125 or 502),
Author name (programmer),ID and sequences of operational
stops Be sure to involve each of the constructors, to include at
least one true and one false 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 -10.0
degrees F, and 100.0 degrees C said 212.0 degrees F. Set up a
loop using Yes/No button for repeating the testing for various
temperature pairs All L/O statements must be in GUI style
Solution
/* Temperature class*/
class Temperature
{
//instant variables//////////////////////////////////////////////
private float value;
private char scale;
/////////////////////the four constructors///////////////////////
public Temperature(float value)
{
this.value=value;
this.scale='C';
}
public Temperature(char scale)
{
this.value=0;
this.scale=scale;
}
public Temperature(float value,char scale)
{
this.value=value;
this.scale=scale;
}
public Temperature()
{
this.value=0;
this.scale='C';
}
////////////////////////Accessor of Celsius/////////////////////
public float getCelsius()
{
if (scale == 'C')
{
return value;
}
else
{
return (5*( value - 32 )) / 9;
}
}
////////////////////////Accessor of Fahrenhite/////////////////
public float getFahrenhite()
{
if (scale == 'C')
{
return ((9*( value / 5 ))/5) + 32;
}
else
{
return value;
}
}
//////////////////////Setting a value/////////////////////////
public void setValue(float value)
{
this.value=value;
}
/////////////////////Setting a scale//////////////////////////
public void setScale(char scale)
{
this.scale=scale;
}
////////////////////Setting val&scale/////////////////////////
public void setBoth(float value,char scale)
{
this.value=value;
this.scale=scale;
}
public boolean equals(Temperature obj)
{
if (scale == 'C')
{
if (value == obj.getCelsius())
{
return true;
}
else
{
return false;
}
}
else
{
if (value == obj.getFahrenhite())
{
return true;
}
else
{
return false;
}
}
}
public boolean isGreater(Temperature obj)
{
if (scale == 'C')
{
if (value > obj.getCelsius())
{
return true;
}
else
{
return false;
}
}
else
{
if (value > obj.getFahrenhite())
{
return true;
}
else
{
return false;
}
}
}
public boolean isLess(Temperature obj)
{
if (scale == 'C')
{
if (value < obj.getCelsius())
{
return true;
}
else
{
return false;
}
}
else
{
if (value < obj.getFahrenhite())
{
return true;
}
else
{
return false;
}
}
}
/////////////////////////////useOfToString/////////////////////////////
public String toString()
{
if (scale == 'C')
{
return "The Temperature in celsius is:ttt"+value+" The
Temperature in Fahrenhite is:tt"+getFahrenhite();
}
else
{
return "The Temperature in celsius
is:ttt"+getCelsius()+" The Temperature in Fahrenhite
is:tt"+value;
}
}
}
///////////////////////// TEST CLASS///////////////////////////
public class TestTemperature
{
public static void main(String[] args)
{
//0.0 Celsius
Temperature obj1 = new Temperature();
//32.0 Fahrenhite
Temperature obj2 = new Temperature(32, 'F');
//-40.0 Celsius
Temperature obj3 = new Temperature(-40);
//-40.0 Fahrenhite
Temperature obj4 = new Temperature(-40,'F');
//100.0 Celsius
Temperature obj5 = new Temperature(100,'C');
//212.0 Fahrenhite
Temperature obj6 = new Temperature(212, 'F');
//Runing the program
//toString of object 1 to test it's Values
System.out.println("Object 1 ");
System.out.println(obj1);
//toString of Object 2 to test it's Values
System.out.println(" Object 2 ");
System.out.println(obj2);
//toString of Object 3 to test it's Values
System.out.println(" Object 3 ");
System.out.println(obj3);
//toString of Object 4 to test it's Values
System.out.println(" Object 4 ");
System.out.println(obj4);
//toString of Object 5 to test it's Values
System.out.println(" Object 5 ");
System.out.println(obj5);
//toString of Object 6 to test it's Values
System.out.println(" Object 6 ");
System.out.println(obj6) ;
System.out.println("--------------- ---------------");
System.out.println("Checking if object 3 is less than object
1");
System.out.println(obj3.isLess(obj1)+" ");
System.out.println("Checking if object 4 is greater than object
5");
System.out.println(obj4.isGreater(obj5)+" ");
System.out.println("Getting Celsius of object 4");
System.out.println(obj4.getCelsius()+"  ");
System.out.println("Getting Fahrenhite of object 3");
System.out.println(obj3.getCelsius()+"  ");
System.out.println("Setting the value 15 to object 1");
obj1.setValue(15);
System.out.println("Printing out the results:");
System.out.println(obj1+"  ");
System.out.println("Setting the scale C to object 2");
obj2.setScale('C');
System.out.println("Printing out the results:");
System.out.println(obj2+"  ");
System.out.println("Setting the scale F and the value 34 to
object 5");
obj5.setBoth(34,'F');
System.out.println("Printing out the results:");
System.out.println(obj5+"  ");
}
}
 Write a Temperature class that represents temperatures in degrees in .docx

More Related Content

Similar to Write a Temperature class that represents temperatures in degrees in .docx

Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3
Dillon Lee
 
These are the outputs which should match they are 4 of them -outp.pdf
These are the outputs which should match they are 4 of them -outp.pdfThese are the outputs which should match they are 4 of them -outp.pdf
These are the outputs which should match they are 4 of them -outp.pdf
udit652068
 
OverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docxOverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docx
gerardkortney
 
Cmis 212 module 2 assignment
Cmis 212 module 2 assignmentCmis 212 module 2 assignment
Cmis 212 module 2 assignment
zjkdg986
 
Csc1100 lecture05 ch05
Csc1100 lecture05 ch05Csc1100 lecture05 ch05
Csc1100 lecture05 ch05
IIUM
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)
aeden_brines
 

Similar to Write a Temperature class that represents temperatures in degrees in .docx (14)

Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3
 
These are the outputs which should match they are 4 of them -outp.pdf
These are the outputs which should match they are 4 of them -outp.pdfThese are the outputs which should match they are 4 of them -outp.pdf
These are the outputs which should match they are 4 of them -outp.pdf
 
Csphtp1 06
Csphtp1 06Csphtp1 06
Csphtp1 06
 
03b loops
03b   loops03b   loops
03b loops
 
OverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docxOverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docx
 
Cmis 212 module 2 assignment
Cmis 212 module 2 assignmentCmis 212 module 2 assignment
Cmis 212 module 2 assignment
 
Cmis 212 module 2 assignment
Cmis 212 module 2 assignmentCmis 212 module 2 assignment
Cmis 212 module 2 assignment
 
Cmis 212 module 2 assignment
Cmis 212 module 2 assignmentCmis 212 module 2 assignment
Cmis 212 module 2 assignment
 
Csphtp1 04
Csphtp1 04Csphtp1 04
Csphtp1 04
 
Csc1100 lecture05 ch05
Csc1100 lecture05 ch05Csc1100 lecture05 ch05
Csc1100 lecture05 ch05
 
Programming for Mechanical Engineers in EES
Programming for Mechanical Engineers in EESProgramming for Mechanical Engineers in EES
Programming for Mechanical Engineers in EES
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)
 
Problem solving and design
Problem solving and designProblem solving and design
Problem solving and design
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
 

More from ajoy21

Please choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docxPlease choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docx
ajoy21
 
Please answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docxPlease answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docx
ajoy21
 
Please answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docxPlease answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docx
ajoy21
 
Please answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docxPlease answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docx
ajoy21
 

More from ajoy21 (20)

Please complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docxPlease complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docx
 
Please cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docxPlease cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docx
 
Please choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docxPlease choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docx
 
Please check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docxPlease check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docx
 
Please answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docxPlease answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docx
 
Please attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docxPlease attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docx
 
Please answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docxPlease answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docx
 
Please answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docxPlease answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docx
 
Please answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docxPlease answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docx
 
Please answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docxPlease answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docx
 
Please answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docxPlease answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docx
 
Please answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docxPlease answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docx
 
Please answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docxPlease answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docx
 
Please answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docxPlease answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docx
 
Please answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docxPlease answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docx
 
Please answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docxPlease answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docx
 
Please answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docxPlease answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docx
 
Please answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docxPlease answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docx
 
Please answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docxPlease answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docx
 
Please answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docxPlease answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docx
 

Recently uploaded

Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 

Recently uploaded (20)

How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 

Write a Temperature class that represents temperatures in degrees in .docx

  • 1. Write a Temperature class that represents temperatures in degrees in both Celsius and Fahrenheit. Use a floating-point number for the temperature and character for the scale: either 'C' for Celsius or 'F' for Fahrenheit. The class should have Four constructor: one for the number of degrees. one for the scale, one for both the degrees 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 accessor methods: one to return the temperature in degrees Celsius, the other to return it in degrees Fahrenheit. Use the formulas as listed below from Practice Program 5 of Chapter 3 and round to the nearest tenth of a degree. C = 5 (F - 32)/9 F = 9 * C/5 + 32 Three set methods: one to set the number of degree, one to set 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 less than another. Write a driver program (a demonstration program using main method) that tests all the methods. Begin the demo program by displaying: Program title Java class code (CSCl-125 or 502), Author name (programmer),ID and sequences of operational stops Be sure to involve each of the constructors, to include at least one true and one false 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 -10.0 degrees F, and 100.0 degrees C said 212.0 degrees F. Set up a loop using Yes/No button for repeating the testing for various temperature pairs All L/O statements must be in GUI style Solution
  • 2. /* Temperature class*/ class Temperature { //instant variables////////////////////////////////////////////// private float value; private char scale; /////////////////////the four constructors/////////////////////// public Temperature(float value) { this.value=value; this.scale='C'; } public Temperature(char scale) { this.value=0; this.scale=scale; } public Temperature(float value,char scale) { this.value=value; this.scale=scale; } public Temperature() {
  • 3. this.value=0; this.scale='C'; } ////////////////////////Accessor of Celsius///////////////////// public float getCelsius() { if (scale == 'C') { return value; } else { return (5*( value - 32 )) / 9; } } ////////////////////////Accessor of Fahrenhite///////////////// public float getFahrenhite() { if (scale == 'C') { return ((9*( value / 5 ))/5) + 32; } else { return value;
  • 4. } } //////////////////////Setting a value///////////////////////// public void setValue(float value) { this.value=value; } /////////////////////Setting a scale////////////////////////// public void setScale(char scale) { this.scale=scale; } ////////////////////Setting val&scale///////////////////////// public void setBoth(float value,char scale) { this.value=value; this.scale=scale; } public boolean equals(Temperature obj) { if (scale == 'C') { if (value == obj.getCelsius()) {
  • 5. return true; } else { return false; } } else { if (value == obj.getFahrenhite()) { return true; } else { return false; } } } public boolean isGreater(Temperature obj) { if (scale == 'C') { if (value > obj.getCelsius()) {
  • 6. return true; } else { return false; } } else { if (value > obj.getFahrenhite()) { return true; } else { return false; } } } public boolean isLess(Temperature obj) { if (scale == 'C') { if (value < obj.getCelsius()) {
  • 7. return true; } else { return false; } } else { if (value < obj.getFahrenhite()) { return true; } else { return false; } } } /////////////////////////////useOfToString///////////////////////////// public String toString() { if (scale == 'C') { return "The Temperature in celsius is:ttt"+value+" The
  • 8. Temperature in Fahrenhite is:tt"+getFahrenhite(); } else { return "The Temperature in celsius is:ttt"+getCelsius()+" The Temperature in Fahrenhite is:tt"+value; } } } ///////////////////////// TEST CLASS/////////////////////////// public class TestTemperature { public static void main(String[] args) { //0.0 Celsius Temperature obj1 = new Temperature(); //32.0 Fahrenhite Temperature obj2 = new Temperature(32, 'F'); //-40.0 Celsius Temperature obj3 = new Temperature(-40); //-40.0 Fahrenhite Temperature obj4 = new Temperature(-40,'F'); //100.0 Celsius Temperature obj5 = new Temperature(100,'C');
  • 9. //212.0 Fahrenhite Temperature obj6 = new Temperature(212, 'F'); //Runing the program //toString of object 1 to test it's Values System.out.println("Object 1 "); System.out.println(obj1); //toString of Object 2 to test it's Values System.out.println(" Object 2 "); System.out.println(obj2); //toString of Object 3 to test it's Values System.out.println(" Object 3 "); System.out.println(obj3); //toString of Object 4 to test it's Values System.out.println(" Object 4 "); System.out.println(obj4); //toString of Object 5 to test it's Values System.out.println(" Object 5 "); System.out.println(obj5); //toString of Object 6 to test it's Values System.out.println(" Object 6 "); System.out.println(obj6) ; System.out.println("--------------- ---------------"); System.out.println("Checking if object 3 is less than object 1"); System.out.println(obj3.isLess(obj1)+" ");
  • 10. System.out.println("Checking if object 4 is greater than object 5"); System.out.println(obj4.isGreater(obj5)+" "); System.out.println("Getting Celsius of object 4"); System.out.println(obj4.getCelsius()+" "); System.out.println("Getting Fahrenhite of object 3"); System.out.println(obj3.getCelsius()+" "); System.out.println("Setting the value 15 to object 1"); obj1.setValue(15); System.out.println("Printing out the results:"); System.out.println(obj1+" "); System.out.println("Setting the scale C to object 2"); obj2.setScale('C'); System.out.println("Printing out the results:"); System.out.println(obj2+" "); System.out.println("Setting the scale F and the value 34 to object 5"); obj5.setBoth(34,'F'); System.out.println("Printing out the results:"); System.out.println(obj5+" "); } }