PBOooo
1.Class NumberDisplay
2.Class ClockDisplay
3.Class TestClockDisplay
Bentuk Hubungan antar Class
Output
Program Siswa
Class student
class siswa
- public class NumberDisplay
- {
- private int limit;
- private int value;
- public NumberDisplay(int rollOverLimit)
- {
- limit = rollOverLimit;
- value = 0;
- }
- public int getValue()
- {
- return value;
- }
- public String getDisplayValue()
- {
- if(value < 10)
- {
- return "0" + value;
- }
- else
- {
- return "" + value;
- }
- }
- public void setValue(int replacementValue)
- {
- if((replacementValue >= 0) && (replacementValue < limit))
- {
- value = replacementValue;
- }
- }
- public void increment()
- {
- value = (value + 1) % limit;
- }
- }
- public class ClockDisplay {
- private NumberDisplay hours;
- private NumberDisplay minutes;
- private String displayString;
- public ClockDisplay()
- {
- hours = new NumberDisplay(24);
- minutes = new NumberDisplay(60);
- updateDisplay();
- }
- public ClockDisplay(int hour, int minute)
- {
- hours = new NumberDisplay(24);
- minutes = new NumberDisplay(60);
- setTime(hour, minute);
- }
- public void timeTick()
- {
- minutes.increment();
- if(minutes.getValue() == 0)
- {
- hours.increment();
- }
- updateDisplay();
- }
- public void setTime(int hour, int minute)
- {
- hours.setValue(hour);
- minutes.setValue(minute);
- updateDisplay();
- }
- public String getTime()
- {
- return displayString;
- }
- private void updateDisplay()
- {
- displayString = hours.getDisplayValue() + ":" + minutes.getDisplayValue();
- }
- }
- public class TestClockDisplay
- {
- public TestClockDisplay()
- {
- }
- public void test()
- {
- ClockDisplay clock = new ClockDisplay();
- clock.setTime(21,59);
- System.out.println(clock.getTime());
- clock.setTime(12,39);
- System.out.println(clock.getTime());
- clock.setTime(14,89);
- System.out.println(clock.getTime());
- }
- }
- public class Student
- {
- // instance variables - replace the example below with your own
- private String nama = "Aguel";
- private double grade = 4;
- public String getName(){
- return nama;
- }
- public void printGrade(){
- System.out.println(grade);
- }
- }
- public class Siswa {
- public static void main() {
- Student b = new Student();
- String nama;
- nama = b.getName();
- System.out.println(nama);
- b.printGrade();
- }
- }
- Dapatkan link
- X
- Aplikasi Lainnya
Komentar
Posting Komentar