방치하기

홍대 자바 과제calculator -> C# 으로 사칙연산 계산기 인트.파스 가 핵심. 본문

프로그래밍/C#

홍대 자바 과제calculator -> C# 으로 사칙연산 계산기 인트.파스 가 핵심.

Yi Junho 2009. 7. 20. 22:45
반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Collections.Generic;
using System.Text;
 
namespace ConsoleApplication1
{
    class Calc
    {
        public int a, b;
 
        public Calc(int a, int b)
        {
            this.a = a;
            this.b = b;
        }
 
        public void option(String opt)
        {
            if (opt=="+")
            {
                this.plus();
            }
            else if (opt=="-")
            {
                this.minus();
            }
            else if (opt=="/")
            {
                this.nanum();
            }
            else if (opt=="*")
            {
                this.gob();
            }
            else
            {
 
 
            }
        }
        public void plus()
        {
            System.Console.WriteLine("더한 결과 "+(this.a+this.b));
        }
        public void minus()
        {
            System.Console.WriteLine("뺀 결과 "+(this.a - this.b));
        }
        public void nanum()
        {
            System.Console.WriteLine("나누기 결과"+ (this.a / this.b));
        }
        public void gob()
        {
            System.Console.WriteLine("곱한 결과"+ (this.a * this.b));
        }
 
 
 
    }
 
    class Calculator
    {
        public static void Main(String[] args){
         
        System.Console.WriteLine("숫자 1입력 해주세요");
        int a = int.Parse(Console.ReadLine());
 
        System.Console.WriteLine("숫자 2입력 해주세요");
        int b = int.Parse(Console.ReadLine());
 
        System.Console.WriteLine("연산자를 입력 해주세요");
        String c=Console.ReadLine();
        Calc jh=new Calc(a,b);
        jh.option(c);
    }
    }
}
반응형
Comments