Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.zipcodewilmington</groupId>
Expand Down Expand Up @@ -48,6 +48,12 @@
<version>4.12</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>eu.tortitas.utils</groupId>
<artifactId>lib</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,36 @@
/**
* Created by leon on 2/9/18.
*/


public class Console {

public static int add(int a, int b) {
int sum = a + b;
System.out.println(sum);
return sum;
}

public static int subtract(int a, int b) {
int difference = a - b;
System.out.println(difference);
return difference;
}

public static int multiply(int a, int b) {
int product = a * b;
System.out.println(product);
return product;
}

public static int divide(int a, int b) {
int quotient = a / b;
System.out.println(quotient);
return quotient;
}



public static void print(String output, Object... args) {
System.out.printf(output, args);
}
Expand All @@ -23,10 +51,18 @@ public static String getStringInput(String prompt) {
}

public static Integer getIntegerInput(String prompt) {
return null;
Scanner scanner = new Scanner(System.in);
println(prompt);
Integer userInput = scanner.nextInt();
return userInput;
}

public static Double getDoubleInput(String prompt) {
return null;
Scanner scanner = new Scanner(System.in);
println(prompt);
Double userInput = scanner.nextDouble();
return userInput;
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,67 @@
/**
* Created by leon on 2/9/18.
*/


public class MainApplication {
public static void main(String[] args) {
Console.println("Welcome to my calculator!");
String s = Console.getStringInput("Enter a string");
Integer i = Console.getIntegerInput("Enter an integer");
Double d = Console.getDoubleInput("Enter a double.");

public static int calculate(int a, int b, String operator) {
int result = 5;
switch (operator) {
case "+":
result = Console.add(a, b);
break;
case "-":
result = Console.subtract(a, b);
break;
case "*":
result = Console.multiply(a, b);
break;
case "/":
result = Console.divide(a, b);
break;
default:
System.out.println("Invalid operator");
}
return result;
}


// Console.println("");
// String s = Console.getStringInput("Enter a string");
// Integer i = Console.getIntegerInput("Enter an integer");
// Double d = Console.getDoubleInput("Enter a double");
// }


// public static void main(String[] args, Object userInput, Object prompt, String operator) {

// if (userInput instanceof String) {
// System.out.println();
// String userInputStr = Console.getStringInput(prompt);
// Console.println(userInputStr);
// } else if (userInput instanceof Integer) {
// System.out.println();
// Integer userInputInt = Console.getIntegerInput(prompt);
// Console.println(userInputInt);
// } else if (userInput instanceof Double) {
// System.out.println();
// Double userInputDbl = Console.getDoubleInput(prompt);
// Console.println(userInputDbl);
// }
// else {
// System.out.println("Invalid input type");
// }
// System.out.println(prompt);
// }

Console.println("The user input %s as a string", s);
Console.println("The user input %s as a integer", i);
Console.println("The user input %s as a d", d);
public static void main(String[] args) {
String prompt = "Enter an operator (+, -, *, /): ";
String operatorInput = Console.getStringInput(prompt);
Integer num1Input = Console.getIntegerInput("Enter the first number: ");
Integer num2Input = Console.getIntegerInput("Enter the second number: ");
int result = calculate(num1Input, num2Input, operatorInput);
Console.println("Result: %d", result);

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,37 @@
/**
* Created by leon on 2/9/18.
*/

class Prompt {
private String prompt;
private String userInput;

public Prompt(String prompt, String userInput) {
this.prompt = prompt;
this.userInput = userInput;
}

public String getPrompt() {
return prompt;
}

public String getUserInput() {
return userInput;
}
}
public class TestMainApplication {


public static int add(int a, int b) {
int sum = a + b;
System.out.println(sum);
return sum;
}

public static int multiply(int a, int b) {
int product = a * b;
System.out.println(product);
return product;
}

}
Loading