Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>1) don't pass the temp inside methods, because you already have this value in member variable.</p> <p>2) you can change if (condition) then true else false into return (condition) and it will be the same result, just for readability .</p> <p>3) you should return boolean not Boolean wrapper until you need the wrapper.</p> <pre><code>public final class FreezingBoilingPoints { private int temperature; public FreezingBoilingPoints(int temp) { temperature = temp; } public void setTemperature(int temp) { temperature = temp; } public int getTemperature() { return temperature; } private boolean isEthylFreezing() { return (temperature &lt;= -173); } private boolean isEthylBoiling() { return (temperature &gt;= 172); } private boolean isOxygenFreezing() { return (temperature &lt;= -362); } private boolean isOxygenBoiling() { return (temperature &gt;= -306); } private boolean isWaterFreezing() { return (temperature &lt;= 32) ; } private boolean isWaterBoiling() { return (temperature &gt;= 212); } public String showTempinfo() { StringBuilder result = new StringBuilder(); if (isEthylFreezing()) { result.append("Ethyl will freeze"); result.append("\n"); } if (isEthylBoiling()) { result.append("Etheyl will boil"); result.append("\n"); } if (isOxygenFreezing()) { result.append("Oxygen will freeze"); result.append("\n"); } if (isOxygenBoiling()) { result.append("Oxygen will Boil"); result.append("\n"); } if (isWaterFreezing()) { result.append("Water will freeze"); result.append("\n"); } if (isWaterBoiling()) { result.append("Water will boil"); result.append("\n"); } return result.toString(); } } </code></pre> <p>Main:</p> <pre><code>import java.util.Scanner; public class FreezingBoilingTester { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Please enter a temperature: "); int temperature = scan.nextInt(); FreezingBoilingPoints temp1 = new FreezingBoilingPoints(temperature ); System.out.println(temp1.showTempinfo()); } } </code></pre> <p><strong>updated</strong>: you can use String concatenation:</p> <pre><code>String result = ""; if ( condition ) { result += "new result"; result += "\n"; } </code></pre> <p>but this is not recommended in term of performance, because each += operation will create another String object in memory holding the new result.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload