PEMOGRAMAN BERORIENTASI OBJEK - OBJECT ORIENTED PROGRAMMING
Soal 1
Untuk codingan assignment 1 :
Main Class (Objek)
//Kristian Yunando
//19316009
import java.util.Scanner;
public class main_mahasiswa {
public static void main(String[] args) {
//membuat objek
Mahasiswa masis = new Mahasiswa();
Scanner input = new Scanner (System.in);
//mengisi atribut untuk objek masis
System.out.print("Inputkan NPM : ");
masis.setNPM(input.nextLine());
System.out.print("Inputkan NAMA : ");
masis.setNAMA(input.nextLine());
//membuat method
System.out.println("NPM : "+masis.getNPM());
System.out.println("NAMA : "+masis.getNAMA());
}
}
Java Class
//Kristian Yunando
//19316009
public class Mahasiswa {
//membuat atribut class
private String NPM;
private String NAMA;
public String getNPM(){
return NPM;
}
public void setNPM(String NPM){
this.NPM = NPM;
}
public String getNAMA(){
return NAMA;
}
public void setNAMA(String NAMA){
this.NAMA = NAMA;
}
}
Soal 2
Untuk codingan assignment 2:
Main class (objek)
//Kristian Yunando
//19316009
import java.util.Scanner;
public class main_mahasiswa {
public static void main(String[] args) {
//membuat objek
Mahasiswa masis = new Mahasiswa();
Scanner input = new Scanner (System.in);
//mengisi atribut untuk objek mha
System.out.print("Inputkan NPM : ");
masis.setNPM(input.nextLine());
System.out.print("Inputkan NAMA : ");
masis.setNAMA(input.nextLine());
System.out.print("Inputkan Alamat : ");
masis.setAlamat(input.nextLine());
System.out.print("Inputkan NoHP : ");
masis.setNoHP(input.nextLine());
System.out.print("Inputkan Email : ");
masis.setEmail(input.nextLine());
System.out.print("Inputkan Instagram : ");
masis.setInstagram(input.nextLine());
//membuat method
System.out.println("NPM : "+masis.getNPM());
System.out.println("NAMA : "+masis.getNAMA());
System.out.println("Alamat : "+masis.getAlamat());
System.out.println("NoHP : "+masis.getNoHP());
System.out.println("Email : "+masis.getEmail());
System.out.println("Instagram : "+masis.getInstagram());
}
}
Java Class :
//Kristian Yunando
//19316009
public class Mahasiswa {
//membuat atribut class
private String NPM;
private String NAMA;
private String Alamat;
private String NoHP;
private String Email;
private String Instagram;
public String getNPM(){
return NPM;
}
public void setNPM(String NPM){
this.NPM = NPM;
}
public String getNAMA(){
return NAMA;
}
public void setNAMA(String NAMA){
this.NAMA = NAMA;
}
public String getAlamat(){
return Alamat;
}
public void setAlamat(String Alamat){
this.Alamat = Alamat;
}
public String getNoHP(){
return NoHP;
}
public void setNoHP(String NoHP){
this.NoHP = NoHP;
}
public String getEmail(){
return Email;
}
public void setEmail(String Email){
this.Email = Email;
}
public String getInstagram(){
return Instagram;
}
public void setInstagram(String Instagram){
this.Instagram = Instagram;
}
}
Komentar
Posting Komentar