Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculator #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

## Description

In this project your team will build a small app to function as a calculator. This app will be built in Java, and will use the topics and techniques discussed during the week.
In this project your team will build a small app to function as a calculatorEngine. This app will be built in Java, and will use the topics and techniques discussed during the week.

Your team should work on this project in a single repository. Click the `fork` button in the top right corner to create a copy of this repository in one of your github accounts. You can go through the [GitHub forking tutorial](https://help.github.com/articles/fork-a-repo/) if you need additional practice with this.

Expand All @@ -23,7 +23,7 @@ You must produce UML diagrams for your program. All classes (excluding test clas

All calculators should have the following features:

- A state, representing the value currently displayed on the calculator (default 0) *
- A state, representing the value currently displayed on the calculatorEngine (default 0) *
- Get the current number on the display *
- Clear the display *
- Change the number on the display *
Expand Down Expand Up @@ -67,7 +67,7 @@ Each operation should automatically update the display

### Custom Features

In addition to the Core and Scientific features, you are required to create at least two of your own features for the calculator. They can be any two features that are not already covered and that you can implement as you see fit. These features must be properly tested.
In addition to the Core and Scientific features, you are required to create at least two of your own features for the calculatorEngine. They can be any two features that are not already covered and that you can implement as you see fit. These features must be properly tested.

### Hints

Expand Down
8 changes: 6 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
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>
<artifactId>scientific_calculator</artifactId>
<groupId>org.example</groupId>
<artifactId>Calculator</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.zipcodewilmington.scientificcalculator;

public class CalcDisplay{
//sets calc value to 0
public double value = 0.00;

public void setValue(double value) {

this.value = value;
}
public double getValue() {
return value;
}

public void clearDisplay() {
this.value = 0.00;
}
public double showDisplay() {
return value;
}

public double clearError() {
return this.value = 0.00;
}


}


Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.zipcodewilmington.scientificcalculator;
import java.util.Scanner;
import java.util.Locale;

public class Calculator {
private CalculatorEngine calculatorEngine = new CalculatorEngine();

double memory = 0;

public double getMemory() {
return memory;
}

public void setMemory(double memory) {
this.memory = memory;
}

public void clearMemory() {
this.memory = 0;
}


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
package com.zipcodewilmington.scientificcalculator;
import java.util.Scanner;
import java.util.Locale;


public class CalculatorEngine {

private final CalculatorEngine calculatorEngine = new CalculatorEngine(); // does calculations
private static final CalcDisplay display = new CalcDisplay(); //displays calculation

public void run() {
Console.println("Welcome to our Calculator");
Console.println("Select option below");
getInitialInput();

}

public void showDisplay(){
CalculatorEngine.display();
}

private static void display() {
}

//get input
public void getInitialInput() {
String initialSelection = Console.getStringInput("basic, scientific, switch, display");
switch (initialSelection.toLowerCase(Locale.ROOT)) {
case "basic":
basicMath();
break;


case "scientific":
scientificMath();
break;

case "switch":
switchMode();

case "display":
showDisplay();
break;

case "quit":
return;


default:
break;
}


}



private void switchMode() { }

private void scientificMath() { }

private void basicMath() { }


public String userInput() {

String userInput = Console.getStringInput("add, subtract, multiply, divide, square, sqRoot, exponent, inverse");
switch (userInput.toLowerCase()) {

/*
public void switchMode() {

}

public void switchMode(String "mode"){
}

public void doBasicScientific() {

}

*/

public void doBasicMath() {

public static Double getDoubleInput(toString()){
Scanner scanner = new Scanner(System.in);

}


switch (userInput.toLowerCase(Locale.ROOT)) {
case "add":
calculatorEngine.addNumber(display.getValue(), userInput.isNumber);
break;

public void addNumber(){
double firstValue = Console.getDoubleInput("enter first double");
double secondValue = Console.getDoubleInput("enter second double");
Double newValue = add(firstValue, secondValue);
display.setValue(Double.parseDouble(newValue.toString()));
}

case "subtract":
subtractNumber(display.getValue(), userInput.isNumber);
break;

public void subtractNumber(){
double firstValue = Console.getDoubleInput("enter first double");
double secondValue = Console.getDoubleInput("enter second double");
Double newValue = calculatorEngine.subtract(firstValue, secondValue);
display.setValue(Double.parseDouble(newValue.toString()));

}



case "multiply":
calculatorEngine.multiplyNumber(display.getValue(), userInput.isNumber);
break;

public void multiplyNumber(){
double firstValue = Console.getDoubleInput("enter first double");
double secondValue = Console.getDoubleInput("enter second double");
Double newValue = multiply(firstValue, secondValue);
display.setValue(Double.parseDouble(newValue.toString()));
}

case "divide":
calculatorEngine.divideNumber(display.getValue(), userInput.isNumber);
break;

public void divideNumber(){
double firstValue = Console.getDoubleInput("enter first double");
double secondValue = Console.getDoubleInput("enter second double");
Double newValue = calculatorEngine.divide(firstValue, secondValue);
display.setValue(Double.parseDouble(newValue.toString()));
}

}

case "square":
square(user.isNumber);
break;

public void squareNumber(){
double firstValue = Console.getDoubleInput("enter first double");
double secondValue = Console.getDoubleInput("enter second double");
Double newValue = square(firstValue, secondValue);
display.setValue(Double.parseDouble(newValue.toString()));
}


case "sqRoot:
squareRoot(user.isNumber);
break;



public void squareRoot() {
double firstValue = Console.getDoubleInput("enter first double");
double secondValue = Console.getDoubleInput("enter second double");
Double newValue = squareRoot(firstValue);
display.setValue(Double.parseDouble(newValue.toString()));
}


case "exponent":
exponent(display.getValue(), user.isNumber);
break;

public void exponent() {
double firstValue = Console.getDoubleInput("enter first double");
double secondValue = Console.getDoubleInput("enter second double");
Double newValue = exponent(firstValue, secondValue);
display.setValue(Double.parseDouble(newValue.toString()));

}





} }

}

public static double add(double firstValue, double secondValue) {

return firstValue + secondValue;
}

public static double subtractNumber(double firstValue, double secondValue) {
return firstValue - secondValue;
}

public double divide(double firstValue, double value2) {
if(value2 == 0) { (Console.println("Error");)
}
return firstValue / value2;
}

public static double multiply(double firstValue, double value2) {git
return firstValue * value2;
}

public static double square(double firstValue) {
return firstValue * firstValue;
}

public static double squareRoot(double firstValue) {

return Math.sqrt(firstValue);
}

public static double exponent(double firstValue, double secondValue) {
return Math.pow(firstValue, secondValue);
}





}

Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,63 @@

/**
* Created by leon on 2/9/18.
*/

/1 what're objects in this ecosystem'
/1.1 create test cases
/2 create those classes for objects
/3 create the behaviors for the classes
/4 define the behaviors
**/

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.");

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);
}
}

CalculatorEngine calculatorEngine = new CalculatorEngine();
calculatorEngine.run();








//first try
/*
int num1 = 0;
int num2 = 0;
char operator;
double answer = 0.0;

*/


// scientific calc code
/*
public class DecimalToAll {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int decimal;

System.out.println("Enter a decimal number: ");
decimal = scanner.nextInt();

String binary, octal, hexadecimal;

binary = Integer.toBinaryString(decimal);
octal = Integer.toOctalString(decimal);
hexadecimal = Integer.toHexString(decimal);

System.out.println("Binary: " + binary + " Octal: " + octal + " Hexadecimal: " + hexadecimal );
}
}
//
*/


}

}