Skip to content

Instantly share code, notes, and snippets.

@Modoo-Dev
Created October 5, 2023 12:28
Show Gist options
  • Save Modoo-Dev/b54df848381313c9f76530d6efcf7509 to your computer and use it in GitHub Desktop.
Save Modoo-Dev/b54df848381313c9f76530d6efcf7509 to your computer and use it in GitHub Desktop.
dartPractice-class
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