Question
A binary odometer whose wheels each show either 0 or 1 A desktop date display with three wheels, one each for year, month, and day
A binary odometer whose wheels each show either 0 or 1 A desktop date display with three wheels, one each for year, month, and day
Question 1 Define generic type Java Interface (assesses the ET1 CEAB indicator)
In this project file create a new package named Question1. In this package, create a Java interface named Rollable to be used for creating any class that represents a wheel. Use the UML class diagram shown in Figure 1 to write your Interface.
Figure 1
-
This interface describe two methods; rollUp() to roll the wheel one step up, and rollDown() to roll the wheel one step down.
-
The interface Rollable needs to be implemented by any class that represents a wheel.
-
In the same package, create another Java interface named CounterDisplay as shown in Figure 2. This interface will be implemented by any class representing a wheel-based counter.
Figure 2
-
This interface defines four methods; reset() to reset the counter to the minimum value, shuffle() to randomize the positions of the wheels of the counter, increase() to increment the counter, and decrease() to decrement the counter.
-
Do not forget to write inline comments and descriptive comments at the top of each method.
2.2 Question 2 Implement Java Interface (assesses the ET2 CEAB indicator)
-
In the same project file, create a new package and named Question2.
-
In this package, create a new generic type abstract class as shown in Figure 3.
-
This class maintain the value of the wheel stored in the field value. You need to implement the body of the methods setValue() and getValue, and define the method reset() and isRolledOver() as abstract methods.
-
The purpose of rest() method is to set the value field to the minimum value of the wheel, and the purpose of isRolledOver() method is to return whether the last wheel step caused a rollover.
Figure 3
-
In the same Question2 package, create a new class and name it IntegerWheel as shown in Figure 4. This class should provide body implementation for the rest() and isRolledOver() methods in addition to a full implementation to the interface Rollable.
-
The constructor with one argument will initialize the minValue by 0, and the maxValue by max, and set the wheel value to max. The constructor with two arguments will initialize the minValue by min and the maxValue by max, and set the wheel value to min.
-
This class records a non-negative count value that is between a minimum and a maximum value. Rolling up the wheel beyond its maximum will roll it over to the minimum value. Rolling down the wheel below its minimum will roll it over to the maximum value.
-
Write a new class named IntegerWheelCounter that implements the CounterDisplay interface and references the IntegerWheel class, see Figure 5 above. This class maintains a collection of three wheels of type IntegerWheel.
-
Implement the toString() method to return a string that represent the IntegerWheelCounter object as shown in the given video ClockDemo.mp4.
ClockDemo.java file:
package Question2; import java.util.Timer; import java.util.TimerTask; public class ClockDemo extends TimerTask { static IntegerWheel seconds = new IntegerWheel(0, 59); static IntegerWheel minutes = new IntegerWheel(0, 59); static IntegerWheel hours = new IntegerWheel(0, 23); static IntegerWheelCounter theClock = new IntegerWheelCounter(hours, minutes, seconds); public void run() { System.out.print(" " + theClock); theClock.increase(); } public static void main(String[] args) { System.out.println("Wheels based clock"); System.out.println("=================="); System.out.println("HH:MM:SS"); // Starts at any random time theClock.shuffle(); Timer timer = new Timer(); timer.schedule(new ClockDemo(), 0, 1000); } }
TimerDemo.java file:
package Question2; import java.util.Timer; import java.util.TimerTask; public class TimerDemo extends TimerTask { static IntegerWheel seconds = new IntegerWheel(20); static IntegerWheel minutes = new IntegerWheel(0); static IntegerWheel hours = new IntegerWheel(0); static IntegerWheelCounter theTimer = new IntegerWheelCounter(hours, minutes, seconds); static Timer timer = new Timer(); public void run() { System.out.print(" " + theTimer); if (theTimer.toString().equals("00:00:00") ) { { timer.cancel(); timer.purge(); return; } } theTimer.decrease(); } public static void main(String[] args) { System.out.println("Wheels based timer"); System.out.println("=================="); timer.schedule(new TimerDemo(), 0, 1000); } }
In this question you will develop a desktop date display program with four wheels, one for the day of the week, one for the month, one for the day, and one for the year.
You will use the abstract class Wheel and the interface Rollable to create four new classes: YearWheel, MonthYear, DayYear, and WeekDaysWheel. In addition, you will use the interface CounterDisplay to create one more class called CalendarCounter. These five new class should follow the UML class diagram shown in Figure 6.
In the same project, create a new package and name it Question3. In this package you will write these five classes.
The class diagram shown in Figure 6, will help you to construct your program quickly, however, the numbers and the names of the fields and the methods of the four wheels are not given. So, you will implementation these four wheels on your own, but again it should follow this UML diagram.
-
Note that, the YearWheel class should be able to tell whether it is a leap year, while a MonthWheel class can report the months length, i.e., 28, 29, 30, or 31. The DayWheel class needs to know the last day of a month so it can rollover correctly. The WeekDaysWheel class uses Zeller's congruence (see Wikipedia) to determine the day on which a given date falls.
-
The constructor of CalendarCounter class takes the values of the month, year and day as parameters and initializes the four objects yearWheel, monthWheel, dayWheel, and weekDaysWheel.
-
The toString() method of the CalendarCounter class should return a string that represent the date format as shown in Figure 7 below.
-
The reset() method of the CalendarCounter class should reset the four wheels to their initial values.
-
To test your program, DesktopCalendar.java to your project, then compile and
run you should have an output like the one shown below in Figure 7.
-
Note that, it is not allowed to change, delete, or add any code of the DesktopCalendar.java file.
DesktopCalender.java file:
package Question3; public class DesktopCalendar { public static void main(String[] args) { // Rolling up and prints from Feb 28 to Mar 3 2016 CalendarCounter aDay = new CalendarCounter(2, 28, 2016); for (int i = 0; i > Rollable +rollUp():void +rollDown():void Figure 1 > CounterDisplay +reset():void +shuffle():void +increase():void +decrease():void Figure 2 > Wheel-value: T +setValue(value: T):void +getValue(): T +reset():void +isRolledOver():Boolean Figure 3 > Wheel - value: T > Rollable > Counter Display +reset():void +shuffle():void +increase():void +decrease():void +setValue(value: T):void +getValue(): T +reset():void +isRolledOver():Boolean +rollUp():void +rollDown():void IntegerWheelCounter - integerWheel: IntegerWheels[] - noOfWheels: int Integer Wheel - minValue:int - maxValue: int + IntegerWheelCounter Integer Wheel wheelThree, Integer Wheel wheelTwo, Integer Wheel wheelOne) + IntegerWheel(max: int) + IntegerWheel(min: int, max: int) + getMin(); int + getMax(): int + toString(): String Figure 4 Figure 5 Now, add the given Java class Clock Demo.java to your project, then compile and run. Without any changes in this class, you should have an output like the one shown in the given video Clock Demo.mp4. Then add the given Java class Timer Demo.java to your project, compile and run. Again, without any changes in this class, you should have an output like the one shown in the given video Timer Demo.mp4. > Wheel - value: T > Rollable > Counter Display +reset():void +shuffle():void +increase():void +decrease():void +setValue(value: T):void +getValue(): T +reset():void +isRolledOver():Boolean +rollUp():void +rollDown():void Calendar Counter Year Wheel year Wheel: Year Wheel month Wheel: Month Wheel - dayWheel: DayWheel weekDaysWheel: WeekDays Wheel Month Wheel + Calendar Counter(initialMonth: int, initialDay:int, initial Year: int) DayWheel + toString(): String WeekDaysWheel Figure 6 add the given Java class Sun 28 Feb, 2016 Mon 29 Feb, 2016 Tue 1 Mar, 2016 Wed 2 Mar, 2016 Thu 3 Mar, 2016 Reset: Sun 28 Feb, 2016 Thu 3 Mar, 2016 Wed 2 Mar, 2016 Tue 1 Mar, 2016 Mon 29 Feb, 2016 Sun 28 Feb, 2016 Reset: Thu 3 Mar, 2016 Sat 27 Feb, 2021 Sun 28 Feb, 2021 Mon 1 Mar, 2021 Tue 2 Mar, 2021 Wed 3 Mar, 2021 Reset: Sat 27 Feb, 2021 Wed 3 Mar, 2021 Tue 2 Mar, 2021 Mon 1 Mar, 2021 Sun 28 Feb, 2021 Sat 27 Feb, 2021 Reset: Wed 3 Mar, 2021 Figure 7 > Rollable +rollUp():void +rollDown():void Figure 1 > CounterDisplay +reset():void +shuffle():void +increase():void +decrease():void Figure 2 > Wheel -value: T +setValue(value: T):void +getValue(): T +reset():void +isRolledOver():Boolean Figure 3 > Wheel - value: T > Rollable > Counter Display +reset():void +shuffle():void +increase():void +decrease():void +setValue(value: T):void +getValue(): T +reset():void +isRolledOver():Boolean +rollUp():void +rollDown():void IntegerWheelCounter - integerWheel: IntegerWheels[] - noOfWheels: int Integer Wheel - minValue:int - maxValue: int + IntegerWheelCounter Integer Wheel wheelThree, Integer Wheel wheelTwo, Integer Wheel wheelOne) + IntegerWheel(max: int) + IntegerWheel(min: int, max: int) + getMin(); int + getMax(): int + toString(): String Figure 4 Figure 5 Now, add the given Java class Clock Demo.java to your project, then compile and run. Without any changes in this class, you should have an output like the one shown in the given video Clock Demo.mp4. Then add the given Java class Timer Demo.java to your project, compile and run. Again, without any changes in this class, you should have an output like the one shown in the given video Timer Demo.mp4. > Wheel - value: T > Rollable > Counter Display +reset():void +shuffle():void +increase():void +decrease():void +setValue(value: T):void +getValue(): T +reset():void +isRolledOver():Boolean +rollUp():void +rollDown():void Calendar Counter Year Wheel year Wheel: Year Wheel month Wheel: Month Wheel - dayWheel: DayWheel weekDaysWheel: WeekDays Wheel Month Wheel + Calendar Counter(initialMonth: int, initialDay:int, initial Year: int) DayWheel + toString(): String WeekDaysWheel Figure 6 add the given Java class Sun 28 Feb, 2016 Mon 29 Feb, 2016 Tue 1 Mar, 2016 Wed 2 Mar, 2016 Thu 3 Mar, 2016 Reset: Sun 28 Feb, 2016 Thu 3 Mar, 2016 Wed 2 Mar, 2016 Tue 1 Mar, 2016 Mon 29 Feb, 2016 Sun 28 Feb, 2016 Reset: Thu 3 Mar, 2016 Sat 27 Feb, 2021 Sun 28 Feb, 2021 Mon 1 Mar, 2021 Tue 2 Mar, 2021 Wed 3 Mar, 2021 Reset: Sat 27 Feb, 2021 Wed 3 Mar, 2021 Tue 2 Mar, 2021 Mon 1 Mar, 2021 Sun 28 Feb, 2021 Sat 27 Feb, 2021 Reset: Wed 3 Mar, 2021 Figure 7
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started