-
-
Save Modoo-Dev/b54df848381313c9f76530d6efcf7509 to your computer and use it in GitHub Desktop.
dartPractice-class
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 'dart:io'; | |
void main(){ | |
Calculator calculator=Calculator(); | |
while(true) { | |
stdout.write('계산식:'); | |
String inputString = stdin.readLineSync()!; | |
if (inputString=='exit') { | |
break; | |
} | |
List<String> splitInput=[]; | |
splitInput = inputString.split(''); | |
calculator.num1=int.parse(splitInput[0]); | |
calculator.num2=int.parse(splitInput[2]); | |
calculator.operator=splitInput[1]; | |
calculator.calculate(); | |
} | |
} | |
class Calculator{ | |
int num1=0; | |
int num2=0; | |
String operator='+'; | |
void calculate(){ | |
int result=0; | |
if (operator.contains('+')) { | |
result=add(); | |
} | |
else if (operator.contains('-')) { | |
result=sub(); | |
} | |
else if (operator.contains('*')) { | |
result=mul(); | |
} | |
else if (operator.contains('/')) { | |
result=div(); | |
} | |
print('계산결과: $result \n'); | |
} | |
int add(){ | |
return num1+num2; | |
} | |
int sub(){ | |
return num1-num2; | |
} | |
int mul(){ | |
return num1*num2; | |
} | |
int div(){ | |
return num1~/num2; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment