Advertisement
IndoproGMR

Tugas Modul 6

Apr 22nd, 2021
1,052
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.54 KB | None | 0 0
  1. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Class User +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2.  
  3. package pewarisan;
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class user {
  8.  
  9.     public static void main(String[] args) {
  10.         Televisi tv = new Televisi("TV Jaman Dulu,69 inc", 10);
  11.         String[] allCenel = {"RCTI", "SCTV", "Indosiar", "TV one",
  12.             "Metro TV", "Trans TV", "TPI", "TV 0",
  13.             "TVRI", "TVG", "ANTV"};
  14.         String[] cenelpaporit = {"RCTI", "SCTV", "Indosiar", "TV one"};
  15.  
  16.         //===================================================
  17.        
  18.         System.out.println("Kevin membeli Televisi : " + tv.getDiski());
  19.  
  20.         //===================================================
  21.        
  22.         //===================================================
  23.        
  24.         tv.getCN();
  25.         tv.setCN(allCenel);
  26.         tv.setCN(cenelpaporit);
  27.        
  28.         //===================================================
  29.  
  30.         //===================================================
  31.        
  32.         Scanner input = new Scanner(System.in);
  33.         System.out.println("mau mengganti apa ?");
  34.         System.out.println("1: voulume \n2: Channel");
  35.         int stg = input.nextInt();
  36.         switch (stg) {
  37.            
  38.             case 1:
  39.                 System.out.println("Silakan masukan volume yang ada inginkan 0~100");
  40.                 int NV = input.nextInt();
  41.                 tv.setVLM(NV);
  42.                 break;
  43.  
  44.             case 2:
  45.                 int c = cenelpaporit.length - 1;
  46.                 System.out.println("Silakan pilih channel dari 0 ~ " + c);
  47.                 int NC = input.nextInt();
  48.                 tv.setCNA(NC);
  49.                 break;
  50.                
  51.             default:
  52.                 System.out.println("eror");
  53.         }
  54.        
  55.         //===================================================
  56.  
  57.         //tv.setCNA(3);
  58.         //tv.setVLM(NV);
  59.         //tv.setCNA(4);
  60.         //tv.setCNA(5);
  61.        
  62.         //===================================================
  63.     }
  64. }
  65.  
  66.  
  67.  
  68. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  69.  
  70.  
  71.  
  72.  
  73.  
  74. //++++++++++++++++++++++++++++++++++++++++++++++++ Class Televisi +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  75.  
  76. package pewarisan;
  77.  
  78. public class Televisi {
  79.  
  80.     private int JCN;
  81.     public String[] CN = null;
  82.     private int CNA;
  83.     private int VLM;
  84.     private String Diski;
  85.  
  86.     public Televisi(String Diski, int JCN) {
  87.         this.Diski = Diski;
  88.         this.JCN = JCN;
  89.     }
  90.  
  91.     // ================================
  92.     public int getJCN() {
  93.         return JCN;
  94.     }
  95.  
  96.     public void setJCN(int JCN) {
  97.         this.JCN = JCN;
  98.     }
  99.  
  100.     // ================================
  101.     public String[] getCN() {
  102.         if (CN == null) {
  103.             System.out.println("Belum ada channel yang diset!");
  104.         }
  105.         return CN;
  106.     }
  107.  
  108.     public void setCN(String[] CN) {
  109.         this.CN = CN;
  110.         if (CN.length > JCN) {
  111.             System.out.println("maaf Televisi ini hanya dapat menyimpan : " + JCN + " Channel");
  112.         } else {
  113.             this.CN = CN;
  114.             System.out.println("Channel Telah di Update!");
  115.         }
  116.     }
  117.  
  118.     // ================================
  119.     public int getCNA() {
  120.         return CNA;
  121.     }
  122.  
  123.     public void setCNA(int CNA) {
  124.         if (CNA > CN.length) {
  125.             System.out.println("Channel yang Anda Pilih belum diset/Kosong!");
  126.             return;
  127.         }
  128.         this.CNA = CNA;
  129.         System.out.println("Pindah Ke Channel : " + CN[CNA]);
  130.     }
  131.  
  132.     // ================================
  133.     public int getVLM() {
  134.         return VLM;
  135.     }
  136.  
  137.     public void setVLM(int VLM) {
  138.         this.VLM = VLM;
  139.         if (VLM > 100) {
  140.             System.out.println("Tolong kecilkan Volume Anda!\nVolume yang terlalu keras dapat merusak speaker dan telinga anda");
  141.         }if (VLM<0){
  142.         System.out.println("Anda taukan kalo volume "+VLM+" itu tidak nyata ??");
  143.         }
  144.         else {
  145.             System.out.println("Volume diSet : " + VLM);
  146.         }
  147.     }
  148.  
  149.     // ================================
  150.     public String getDiski() {
  151.         return Diski;
  152.     }
  153.  
  154.     public void setDiski(String Diski) {
  155.         this.Diski = Diski;
  156.     }
  157.     // ================================
  158. }
  159.  
  160. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement