Last active
February 7, 2020 16:59
-
-
Save HoussemNasri/4bc0f9e85e4060e81f8839cc1229ada4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.swing.*; | |
public class GUI { | |
public static void runGui() { | |
System.out.println("----------------------- Hello From GUI -----------------------"); | |
String strObjectMass = JOptionPane.showInputDialog(null, "Enter Object Mass"); | |
double objectMass = 0.0; | |
try { | |
objectMass = Double.parseDouble(strObjectMass); | |
} catch (Exception ignored) { | |
} | |
double objectWeight = ObjectMeasure.calculateObjectWeight(objectMass); | |
String message = ""; | |
if (objectWeight < 10) | |
message = "Too Light"; | |
else if (objectWeight > 1000) | |
message = "Too Heavy"; | |
JOptionPane.showMessageDialog(null, "Object Weight = " + objectWeight + "\n" + message); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
System.out.println("What Type Of Interface Do You Wanna Use"); | |
System.out.println("1 - Graphical User Interface"); | |
System.out.println("2 - Text-Based User Interface"); | |
System.out.print("choice : "); | |
System.out.println(""); | |
Scanner console = new Scanner(System.in); | |
int userInterface = console.nextInt(); | |
if (userInterface == 1) | |
GUI.runGui(); | |
else if (userInterface == 2) | |
TUI.runTui(); | |
else | |
System.out.println("Wrong Input!!!"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ObjectMeasure { | |
public static double calculateObjectWeight(double objectMass) { | |
return objectMass * 9.8; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class TUI { | |
public static void runTui() { | |
System.out.println("----------------------- Hello From TUI -----------------------"); | |
Scanner console = new Scanner(System.in); | |
System.out.print("Enter The Object Mass : "); | |
double objectMass = console.nextDouble(); | |
double objectWeight = ObjectMeasure.calculateObjectWeight(objectMass); | |
System.out.println("Object Weight = " + objectWeight); | |
if (objectWeight > 1000) | |
System.out.println("Too Heavy"); | |
else if (objectWeight < 10) | |
System.out.println("Too Light"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment