Skip to content

Instantly share code, notes, and snippets.

@HoussemNasri
Last active February 7, 2020 16:59
Show Gist options
  • Save HoussemNasri/4bc0f9e85e4060e81f8839cc1229ada4 to your computer and use it in GitHub Desktop.
Save HoussemNasri/4bc0f9e85e4060e81f8839cc1229ada4 to your computer and use it in GitHub Desktop.
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);
}
}
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!!!");
}
}
public class ObjectMeasure {
public static double calculateObjectWeight(double objectMass) {
return objectMass * 9.8;
}
}
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