Untitled
public class WaterFlask { private double temperature; // Current temperature in Celsius public WaterFlask(double initialTemperature) { this.temperature = initialTemperature; } // Method to heat the flask public void heat(double degrees) { temperature += degrees; System.out.println("Heated by " + degrees + "°C."); display(); } // Method to cool the flask public void cool(double degrees) { temperature -= degrees; System.out.println("Cooled by " + degrees + "°C."); display(); } // Method to display the flask with ASCII art based on temperature public void display() { System.out.println("\nCurrent Temperature: " + temperature + "°C"); if (temperature < 0) { displayCold(); } else if (temperature >= 0 && temperature <= 20) { displayCool(); } else if (temperature > 20 && temperature <= 25) { displayRoomTemp(); } else if (temperature > 25 && temperature <= 40) { displayWarm(); } else { displayHot(); } System.out.println(); // Extra line for readability } // ASCII Art for Cold temperatures private void displayCold() { System.out.println(" * * * * *"); System.out.println(" * *"); System.out.println(" * ICE *"); System.out.println(" * *"); System.out.println(" * *"); System.out.println(" * * * *"); System.out.println(" |||"); System.out.println(" |||"); System.out.println(" |||"); } // ASCII Art for Cool temperatures private void displayCool() { System.out.println(" _______"); System.out.println(" / \\"); System.out.println(" | COOL |"); System.out.println(" | |"); System.out.println(" \\_______/"); System.out.println(" |||"); System.out.println(" |||"); System.out.println(" |||"); } // ASCII Art for Room Temperature private void displayRoomTemp() { System.out.println(" _______"); System.out.println(" / \\"); System.out.println(" | ROOM |"); System.out.println(" | TEMP |"); System.out.println(" \\_______/"); System.out.println(" |||"); System.out.println(" |||"); System.out.println(" |||"); } // ASCII Art for Warm temperatures private void displayWarm() { System.out.println(" _______"); System.out.println(" / \\"); System.out.println(" | WARM |"); System.out.println(" | |"); System.out.println(" \\_______/"); System.out.println(" |||"); System.out.println(" ~|||~"); System.out.println(" ~ ||| ~"); } // ASCII Art for Hot temperatures private void displayHot() { System.out.println(" _______"); System.out.println(" / \\"); System.out.println(" | HOT |"); System.out.println(" | |"); System.out.println(" \\_______/"); System.out.println(" |||"); System.out.println(" ~ ~|||~ ~"); System.out.println(" ~ ~ ||| ~ ~"); System.out.println(" ~ ~ ||| ~ ~"); } // Main method to demonstrate the WaterFlask class public static void main(String[] args) { WaterFlask flask = new WaterFlask(25); // Initialize with 25°C flask.display(); // Example interactions flask.heat(10); // Increase to 35°C flask.heat(10); // Increase to 45°C flask.cool(20); // Decrease to 25°C flask.cool(30); // Decrease to -5°C } }
Leave a Comment