Loading...
Tuesday, October 15, 2013

Contoh Penggunaan Class dan Metod



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace kalkulator
{
    public class operasi
    {
        //field
        public double a;
        public double b;

        //public metod
        public double kali()
        {
            return a*b;
        }

        public double bagi()
        {
            return a / b;
        }
        public double sum()
        {
            return a + b;
        }
        public double min()
        {
            return a - b;
        }
    }

    class MainClass
    {
        static void Main(string[] args)
        {
            operasi hasil = new operasi();

            Console.Write("Masukan Nilai Pertama brow: ");
            hasil.a = int.Parse(Console.ReadLine());
            Console.Write("Masukan Nilai kedua brow: ");
            hasil.b = int.Parse(Console.ReadLine());

            System.Console.WriteLine(" Hasil Perkalian: {0}", hasil.kali());
            System.Console.WriteLine(" Hasil Pembagian: {0}", hasil.bagi());
            System.Console.WriteLine(" Hasil Penjumlahan: {0}", hasil.sum());
            System.Console.WriteLine(" Hasil Pengurangan: {0}", hasil.min());
        }
    }
}

0 comments:

Post a Comment

 
TOP