Final Project

package bioskop; import java.util.Scanner; class Data{ int nomor,harga; String nama,genre,judul; Data left,right,up,next,prev; public void FillData(){ Scanner q =new Scanner(System.in); System.out.print("Masukan Nomor Kursi : "); this.nomor =Integer.parseInt(q.nextLine()); System.out.print("Masukan Nama Penonton : "); this.nama =q.nextLine(); System.out.print("Masukan Genre Film : "); this.genre =q.nextLine(); System.out.print("Masukan Judul Film : "); this.judul =q.nextLine(); System.out.print("Masukan Harga Tiket : Rp."); this.harga =Integer.parseInt(q.nextLine()); System.out.println(); } public void ItemView(){ System.out.println("------------------------"); System.out.println("Nomor Kursi : "+this.nomor); System.out.println("Nama Penonton : "+this.nama); System.out.println("Genre Film : "+this.genre); System.out.println("Judul Film : "+this.judul); System.out.println("Harga Tiket : Rp."+this.harga); System.out.println("-------------------------"); } } public class Bioskop { static Data root; Data tail; private int nomor,harga; private String nama,genre,judul; private void LinkedList(Data item){ if(tail==null){ tail=item; }else{ tail.next=item; item.prev=tail; tail=item; } } private Data Search(){ Data item=tail; if(root!=null){ Scanner q =new Scanner(System.in); System.out.println("Pilih Nomor Kursi Yang Diinginkan : "); int cari =q.nextInt(); while(item!=null){ if(item.nomor==cari){ return item; } item=item.prev; } System.out.println("Nomor Tidak Ditemukan !"); return null; }else{ System.out.println("Data Kosong !"); return null; } } private void DelSearch(Data data){ if(data!=null){ DelSearch(data.left); DelSearch(data.right); if(data.left==tail){ data.left=null; } if(data.right==tail){ data.right=null; } } } private void Input(){ Data item=new Data(); item.FillData(); if(root==null){ LinkedList(item); root=item; return; } Data current = root; Data parent =null; while(true){ parent=current; if(item.nomor<current.nomor){ current=current.left; if(current==null){ LinkedList(item); parent.left=item; item.up=parent; break; } }else if(item.nomor>current.nomor){ current=current.right; if(current==null){ LinkedList(item); parent.right=item; item.up=parent; break; } }else{ System.out.println("Maaf Nomor Kursi "+item.nomor+" Telah Terisi !!"); break; } } } private void View(Data data){ if(root!=null){ if(data!=null){ View(data.left); data.ItemView(); View(data.right); } }else{ System.out.println("Data Kososng !"); } } private void Found(){ Data item=Search(); if(item!=null){ if(item.up!=null){ System.out.println("--------Parent---------"); item.up.ItemView(); }else{ System.out.println("Data Ini Tidak Mempunyai Parent !"); } System.out.println("--------Data Yang Dicari---------"); item.ItemView(); if(item.left!=null){ System.out.println("--------Child Kiri---------"); item.left.ItemView(); }else{ System.out.println("Data Ini Tidak Mempunyai Child Kiri !"); } if(item.right!=null){ System.out.println("--------Child Kanan---------"); item.right.ItemView(); }else{ System.out.println("Data Ini Tidak Mempunyai Child Kanan !"); } } } private void Update(){ Data item=Search(); if(item!=null){ item.FillData(); } } private void Delete(){ if(root!=null){ if(tail==root){ root=null; tail=null; System.out.println("Data Terakhir Telah Dihapus !"); }else{ DelSearch(root); tail=tail.prev; tail.next=null; System.out.println("Data Terakhir Telah Dihapus !"); } }else{ System.out.println("Data Kosong !"); } } public static void main(String[] args) { int pilih; Bioskop x=new Bioskop(); Scanner q =new Scanner(System.in); do{ System.out.println("Masukan Menu Pilihan\n1.Input 4.Update\n2.View 5.Delete\n3.Search 6.Exit"); pilih =q.nextInt(); switch(pilih){ case 1: x.Input(); break; case 2: x.View(root); break; case 3: x.Found(); break; case 4: x.Update(); break; case 5: x.Delete(); break; case 6: System.out.println("Anda telah Keluar !"); break; default: System.out.println("Menu Pilihan Tidak Tersedia"); break; } }while(pilih!=6); } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.