Tugas Pemrograman Visual 2
Menggabungkan 2 Method (Mencari jumlah
nilai & rata-rata)
Nama : Wahyu Nurfian
NIM : 12.12.0306
Kelas : SI 12 A
STMIK AMIKOM PURWOKERTO
TAHUN
2012/2013
CLASS MAHASISWA
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Latihan
{
class Mahasiswa
{
string jurusan, NIM, nama;
public string Nama
{
get { return nama; }
set { nama = value; }
}
public string NIM1
{
get { return NIM; }
set { NIM = value; }
}
public string Jurusan
{
get { return jurusan;
}
set { jurusan = value;
}
}
DateTime tgl_lahir;
public DateTime
Tgl_lahir
{
get { return
tgl_lahir; }
set { tgl_lahir = value;
}
}
double ipk;
public double Ipk
{
get { return ipk; }
set { ipk = value; }
}
float nilai_algoritma, nilai_spbd, nilai_pbo;
public float
Nilai_pbo
{
get { return
nilai_pbo; }
set { nilai_pbo = value;
}
}
public float
Nilai_spbd
{
get { return
nilai_spbd; }
set { nilai_spbd = value;
}
}
float nilai_algoritmaa, nilai_spbdd, nilai_pboo;
public float
Nilai_pboo
{
get { return
nilai_pboo; }
set { nilai_pboo = value;
}
}
public float
Nilai_spbdd
{
get { return
nilai_spbdd; }
set { nilai_spbdd = value;
}
}
public float
Nilai_algoritmaa
{
get { return
nilai_algoritmaa; }
set { nilai_algoritmaa = value;
}
}
int thnLhr;
public int ThnLhr
{
get { return thnLhr;
}
set { thnLhr = value;
}
}
//construktor
public Mahasiswa()
{
}
//overloading construktor
public Mahasiswa(string
NIM, string nama, string
jurusan, DateTime tgl_lahir, double ipk, float
nilai_algoritma, float nilai_spbd, float nilai_pbo)
{
this.NIM = NIM;
this.nama = nama;
this.jurusan = jurusan;
this.tgl_lahir = tgl_lahir;
this.ipk = ipk;
this.nilai_algoritma = nilai_algoritma;
this.nilai_spbd = nilai_spbd;
this.nilai_pbo = nilai_pbo;
}
// method
public void
tampilData(Mahasiswa mhs)
{
Console.WriteLine("NIM
\t\t: "+mhs.NIM);
Console.WriteLine("Nama
\t\t: "+mhs.nama);
Console.WriteLine("Jurusan
\t: "+mhs.jurusan);
Console.WriteLine("Tanggal
Lahir : "+mhs.tgl_lahir);
Console.WriteLine("IPK
\t\t: "+mhs.ipk);
}
// overloading method
public void
tampilData()
{
Console.WriteLine("NIM
\t\t: "+NIM);
Console.WriteLine("Nama
\t\t: "+nama);
Console.WriteLine("Jurusan
\t: "+jurusan);
Console.WriteLine("Tanggal
Lahir : "+tgl_lahir);
Console.WriteLine("IPK
\t\t: "+ipk);
}
public void
isiNilaiAlgoritma(Mahasiswa nilaiAlgoritma)
{
//float nilaiA;
Console.Write("Masukan
nilai Algoritma : ");
nilai_algoritmaa = float.Parse(Console.ReadLine());
}
public void
isiNilaiSpbd(Mahasiswa nilaiSpbd)
{
//float nilaiS;
Console.Write("Masukan
Nilai SPBD : ");
nilai_spbdd = float.Parse(Console.ReadLine());
}
public void
isiNilaiPbo(Mahasiswa nilaiPbo)
{
//float nilaiP;
Console.Write("Masukan
Nilai PBO : ");
nilai_pboo = float.Parse(Console.ReadLine());
}
public void
jumlahNilai(Mahasiswa jumlah)
{
float algo, spbd, pbo, jml;
algo=nilai_algoritmaa;
spbd = nilai_spbdd;
pbo = nilai_pboo;
jml = algo + spbd + pbo;
Console.WriteLine("Jumlah
Nilai : " + jml);
}
public void rataRata(Mahasiswa rata)
{
float algo, spbd, pbo, rata2;
algo = nilai_algoritmaa;
spbd = nilai_spbdd;
pbo = nilai_pboo;
rata2 =(algo + spbd + pbo)/ 3;
Console.WriteLine("Rata
- Rata : " + rata2);
}
public void uu(Mahasiswa uuu)
{
Console.Write("ketik
kan tahun lahir : ");
thnLhr = int.Parse(Console.ReadLine());
int um = DateTime.Now.Year
- thnLhr;
Console.WriteLine("");
Console.WriteLine("umur
sekarang : " + um);
}
}}
CLASS PROGRAM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Latihan
{
class Program
{
static void Main(string[] args)
{
Mahasiswa mhs1 = new
Mahasiswa();
mhs1.Nama = "Nurvina Dwi Andari";
mhs1.NIM1 = "12.12.0306";
mhs1.Jurusan = "Sistem Informasi";
mhs1.Tgl_lahir = DateTime.Parse("1994-07-01");
mhs1.Ipk = 3.75;
mhs1.tampilData(mhs1);
Console.WriteLine("");
mhs1.isiNilaiAlgoritma(mhs1);
mhs1.isiNilaiSpbd(mhs1);
mhs1.isiNilaiPbo(mhs1);
Console.WriteLine("");
mhs1.jumlahNilai(mhs1);
Console.WriteLine("");
mhs1.rataRata(mhs1);
Console.WriteLine("");
mhs1.uu(mhs1);
Console.Read();
}
}
}
Tidak ada komentar:
Posting Komentar