Experiment OOPS C#

Experimet OOPS C#
 

Setelah BlogHWP memposting materi OOPS, yaitu  OOPS Using C# part 1  dan  OOPS Using C# part 2 ( Creating Object ) .
  Kali Ini BlogHWP akan memposting tentang file latihan 1-6 :

1. Exercise 1( Click Untuk Download File )
Scriptnya :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Excercise_1
{
    class Geometrical_Shape
    {
        double No_of_Coordinates, Area;
        string Color;
        public void create()
        {
            Console.WriteLine("Coordinates: ");
            No_of_Coordinates= Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Area       : ");
            Area=Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Color      : ");
            Color=Console.ReadLine();
        }
        public void diplay()
        {
            Console.WriteLine("No of Coordinate = {0}", No_of_Coordinates);
            Console.WriteLine("Area = {0}", Area);
            Console.WriteLine("Colour = {0}", Color);
        }

    }
    class Program
    {
        static void Main(string[] args)
        {
            Geometrical_Shape geo = new Geometrical_Shape();
            geo.create();
            geo.diplay();
            Console.ReadLine();

        }
    }
}

Ketika Di Execute, Hasilnya akan seperti ini :


2. Exercise 2 ( Click Untuk Download File )
Scriptnya :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Exercise_2
{
    class Booking
    {
        string name;
        int numplay, level;
        public void create()
        {
            Console.WriteLine("Name Of Game = ");
            name = Console.ReadLine();
            Console.WriteLine("Number Of Player =");
            numplay = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Complexcity Level = ");
            level = Convert.ToInt32(Console.ReadLine());
        }

        public void display()
        {
            Console.WriteLine("\n\nName Of Game = {0}", name);
            Console.WriteLine("Number Of Player = {0}", numplay);
            Console.WriteLine("Complexcity Level = {0}", level);
            Console.ReadLine();
        }
    }

    class MyClass
    {
        static void Main(String[] args)
        {
            Booking booking1 = new Booking();
            booking1.create();
            booking1.display();
        }
    }
}

Hasilnya setelah di execute :

3. Exercise 3 ( Click Untuk Download File )
Scriptnya :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Exercise_3
{
    class Program
    {
        static void Main()
        {
            string Answer = "Y";
            string Response_Code = "66";
            int Counter = 60;
            Console.WriteLine(Answer);
            Console.WriteLine(Response_Code);
            Console.WriteLine(Counter);
            Console.ReadLine();
        }
    }
}
Hasil setelah di execute :

4. Exercise 4 ( Click Untuk Download File )
Scriptnya :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Exercise_4
{
    class mobil
    {
        public int tyres;
    }
    class Program
    {
        static void Main(string[] args)
        {
            mobil motor = new mobil();
            mobil mobil1 = new mobil();
            Console.WriteLine("Enter the Number of wheels in a car : ");
            mobil1.tyres = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter The Number of Wheels in a Motorcycle : ");
            motor.tyres = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("\n");
            Console.Write(mobil1.tyres);
            Console.WriteLine(" : is the number of wheels in a car \n");
            Console.Write(motor.tyres);
            Console.WriteLine(" : is the number of wheels in a motorcycle \n");
            Console.ReadLine();
        }
    }
}
Hasilnya Setelah di Execute :

5. Exercise 5 ( Click Untuk Download File )
Scriptnya :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Exercise_5
{
    class Interchange
    {
        int Topskor, newskor, tmp;
        public void swap()
        {
            Topskor=5;
            newskor=10;
            tmp=Topskor;
            Topskor=newskor;
            newskor=tmp;
        }
        public void play()
        {
            Console.WriteLine(" The New Top Scorer is = {0}", Topskor);
            Console.WriteLine(" The Old Score is = {0}", newskor);
        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            Interchange I1 = new Interchange();
            I1.swap();
            I1.play();
            Console.ReadLine();
        }
    }
}
Hasil Setelah Di Execute :


6. Exercise 6 ( Click Untuk Download File )
Scriptnya :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Exercise_6
{
    class Masuk
    {
        int isbn, copies;
        string categori, author;
        public void asep ()
        {
            Console.WriteLine(" Enter The ESBN Number = ");
            isbn = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine(" Book Category ( Fiction or Non Fiction ) = ");
            categori = Console.ReadLine();
            Console.WriteLine(" Author = ");
            author = Console.ReadLine();
            Console.WriteLine("Number of Copies = ");
            copies = Convert.ToInt32(Console.ReadLine());
        }
        public void dis()
        {
            Console.WriteLine("\n \nThe ESBN Number = {0}",isbn);          
            Console.WriteLine(" Book Category ( Fiction or Non Fiction ) = {0}",categori);          
            Console.WriteLine(" Author = {0}",author);          
            Console.WriteLine(" Number of Copies = {0}",copies);
            Console.ReadLine();
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Masuk masuk1 = new Masuk();
            masuk1.asep();
            masuk1.dis();
        }
    }
}
Hasil Setelah di execute :

Itulah sedikit latihan dari BlogHWP , semoga bisa membantu H.W.P Mania dalam belajar bahasa pemrograman C# :)

Written by

0 comments: