Langsung ke konten utama

Postingan

Menampilkan postingan dari Maret, 2017
// Fig. 8.13: EmployeeTest.java //static member demonstration.   public   class  EmployeeTest {      public   static   void  main (   String [ ]  args  )      {          //show that count is 0 before creating Employees          System . out . printf (   "Empployees before instantiation: %d \n " ,             Employee. getCount ( )   ) ;                  //create two Employees; count should be 2         Employee e1  =   new  Employee (   "Susan" ,  "Baker"   ) ;         Employee e2  =   new  Employee (   "Bob" ,  "Blue"   ) ;                  //show that coount is 2 after creating two Employees          System . out . println (   " \n Employees after instantiation: " ) ;          System . out . printf (   "via e1.getCount(): %d \n " , e1. getCount ( )   ) ;          System . out . printf (   "via e2.getCount(): %d \n " , e2. getCount ( )   ) ;      
Composition & Enumerations A. COMPOSITION     Composition adalah dimana hubungan suatu object bergantung dengan objek lainnya.    Berikut ini program class Date, class Employee dan class EmployeeTest. Source Code : Class Date // Fig. 8.7: Date.java // Date class declaration. public class Date { private int month; private int day; private int year; private static final int[] daysPerMonth = //days in each month {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //contruktor : call checkMonth to confirm proper value for month; //call checkDay to confirm proper value for day public Date (int theMonth, int theDay, int theYear) { month = checkMonth(theMonth); year = theYear; day = checkDay(theDay); System.out.printf ("Date object constructor for date %s\n", this); } //utility method to confirm proper month value private int checkMonth(int test
Studi Kasus : Mesin Tiket  Ticket Machine Case Study (Studi Kasus Mesin Tiket) Ticket Machine adalah sebuah mesin seperti ATM, yang berfungsi melayani penjualan tiket kereta api dari satu tujuan ke tujuan yang lain. Di dalam Ticket Machine ada sebuah program atau perangkat lunak yang mengatur harga tiket di tiap tujuan, mengatur kembalian uang, dan juga mencetak receipt sebagai bukti pembelian tiket. Berikut ini program TicketMachine dan program pengaplikasiannya (IntMain) : Source code : Program TicketMachine public class TicketMachine { // The price of a ticket from this machine private int price; // The amount of money entered by a customer so far. private int balance; // The total amount of money collected by this machine. private int total; public TicketMachine(int ticketCost) { price = ticketCost; balance = 0; total = 0; } public int getPrice() { return price; } public int getBalance() { r