Advertisement
wewgu

Profil

Feb 23rd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.65 KB | None | 0 0
  1. package profil;
  2.  
  3. //Profil.java
  4. public class Profil
  5. {
  6.     String nama;
  7.     int umur;
  8.     double gaji;
  9.     String alamat;
  10.    
  11.     public Profil(String nama, int umur, double gaji, String alamat)
  12.     {
  13.         this.nama = nama;
  14.         this.umur = umur;
  15.         this.gaji = gaji;
  16.         this.alamat = alamat;
  17.     }
  18.    
  19.     public String getNama()
  20.     {
  21.         return nama;
  22.     }
  23.    
  24.     public int getUmur()
  25.     {
  26.         return umur;
  27.     }
  28.    
  29.     public double getGaji()
  30.     {
  31.         return gaji;
  32.     }
  33.    
  34.     public String getAlamat()
  35.     {
  36.         return alamat;
  37.     }
  38.    
  39.     public void setNama(String nama)
  40.     {
  41.         this.nama = nama;
  42.     }
  43.    
  44.     public void setUmur(int umur)
  45.     {
  46.         this.umur = umur;
  47.     }
  48.    
  49.     public void setGaji(double gaji)
  50.     {
  51.         this.gaji = gaji;
  52.     }
  53.    
  54.     public void setAlamat(String alamat)
  55.     {
  56.         this.alamat = alamat;
  57.     }
  58. }
  59.  
  60. //ProfilBaru.java
  61. package profil;
  62.  
  63. public class ProfilBaru extends Profil
  64. {
  65.     public ProfilBaru(String nama, int umur, double gaji, String alamat)
  66.     {
  67.         super(nama, umur, gaji, alamat);
  68.     }
  69.    
  70.     @Override
  71.     public String getNama()
  72.     {
  73.         return nama;
  74.     }
  75.    
  76.     @Override
  77.     public int getUmur()
  78.     {
  79.         return umur;
  80.     }
  81.    
  82.     @Override
  83.     public double getGaji()
  84.     {
  85.         return gaji;
  86.     }
  87.    
  88.     @Override
  89.     public String getAlamat()
  90.     {
  91.         return alamat;
  92.     }
  93. }
  94.  
  95. //ProfilImplentasi.java
  96. package profil;
  97.  
  98. import java.io.*;
  99.  
  100. public class ProfilImplementasi
  101. {
  102.     static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  103.     static String nama;
  104.     static int umur;
  105.     static double gaji;
  106.     static String alamat;
  107.            
  108.     public static void main(String[]args) throws IOException
  109.     {
  110.         buatProfil();
  111.         Profil profil = new Profil(nama, umur, gaji, alamat);
  112.         System.out.println("\n" + profil.getNama() + "\n" + profil.getUmur() + "\n" + profil.getGaji() + "\n" + profil.getAlamat());
  113.        
  114.         System.out.println("--- Buat Profil Baru ---");
  115.        
  116.         buatProfil();
  117.         ProfilBaru profilBaru = new ProfilBaru(nama, umur, gaji, alamat);
  118.         System.out.println("\n" + profilBaru.getNama() + "\n" + profilBaru.getUmur() + "\n" + profilBaru.getGaji() + "\n" + profilBaru.getAlamat());
  119.     }
  120.    
  121.     public static void buatProfil() throws IOException
  122.     {
  123.         nama = reader.readLine();
  124.         umur = Integer.parseInt(reader.readLine());
  125.         gaji = Double.parseDouble(reader.readLine());
  126.         alamat = reader.readLine();
  127.     }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement