FAQ |
Calendar |
![]() |
|
Programming Share, tanya jawab, saling bantu antar programmer dengan berbagai macam bahasa pemrograman. |
![]() |
|
Thread Tools |
#1
|
|||
|
|||
![]()
Tanya gan, berkaitan dengan exception handling... Jadi codenya begini di kelas main : Code: public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); Mobil mob = new Mobil(); BufferedReader b = new BufferedReader(new InputStreamReader(System.in)); int x=0,panjang = 0,lebar = 0; String merek = "", platNo = "", bahanBakar = "", warna = ""; LinkedList listKomponen = new LinkedList(); do{ try{ System.out.println("=====MENU=====\n"+ "1. Masukkan Mobil Baru\n"+ "2. Tampil Semua Data Mobil\n"+ "3. Keluar \n Pilihan anda : "); x = input.nextInt(); switch(x){ case 1 : try{ System.out.println("merk : "); merek = b.readLine(); System.out.println("Plat No ; "); platNo = b.readLine(); System.out.println("Warna : "); warna = b.readLine(); System.out.println("Bahan bakar : "); bahanBakar = b.readLine(); System.out.println("Panjang : "); panjang = input.nextInt(); System.out.println("Lebar : "); lebar = input.nextInt(); checkMerk(merek, listKomponen); checkBB(bahanBakar, listKomponen); checkLebar(lebar); checkPanjang(panjang); checkPlat(platNo, listKomponen); } catch(merkException me){ System.out.println(me.getMessage()); } catch(bbException bbe){ System.out.println(bbe.getMessage()); } catch(rangeException re){ System.out.println(re.getMessage()); } catch(platNoException pne){ System.out.println(pne.getMessage()); } catch(Exception E){} mob = new Mobil(merek, warna, platNo, bahanBakar, panjang, lebar); listKomponen.add(mob); break; case 2 : printListKomponen(listKomponen); break; } } catch(Exception E){} } while(x!=3); } public static void printListKomponen(LinkedList Terkait:
|
![]() |
|
|