Last change
on this file since fcbb532 was
1725989,
checked in by Peter A. Buhr <pabuhr@…>, 5 months ago
|
add enumeration test programs for different programming languages
|
-
Property mode set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[1725989] | 1 | import java.io.*; |
---|
| 2 | import java.util.Random; |
---|
| 3 | |
---|
| 4 | public class testP3 { |
---|
| 5 | static Random rand = new Random(); |
---|
| 6 | enum Weekday { |
---|
| 7 | Mon(rand.nextInt()), Tue(rand.nextInt()), Wed(rand.nextInt()), Thu(rand.nextInt()), Fri(rand.nextInt()), |
---|
| 8 | Sat(rand.nextInt()), Sun(rand.nextInt()); // must appear first |
---|
| 9 | private int day; |
---|
| 10 | private Weekday( int d ) { day = d; } |
---|
| 11 | |
---|
| 12 | public boolean isWeekday() { |
---|
| 13 | return day <= Fri.day; |
---|
| 14 | } |
---|
| 15 | public boolean isWeekend() { |
---|
| 16 | return Fri.day < (int)day; |
---|
| 17 | } |
---|
| 18 | } |
---|
| 19 | |
---|
| 20 | public static void main( String[] args ) { |
---|
| 21 | Weekday day = Weekday.Sat; |
---|
| 22 | System.out.println( day.ordinal() + " " + day.day + " " + day.name() ); |
---|
| 23 | for ( Weekday iday : day.values() ) { |
---|
| 24 | System.out.print( iday.ordinal() + " " + iday.day + " " + iday.name() + ", " ); |
---|
| 25 | } |
---|
| 26 | System.out.println(); |
---|
| 27 | System.out.println( day.isWeekday() ); // false |
---|
| 28 | System.out.println( day.isWeekend() ); // true |
---|
| 29 | |
---|
| 30 | Weekday day2 = Weekday.Sat; |
---|
| 31 | System.out.println( day2.ordinal() + " " + day2.day + " " + day2.name() ); |
---|
| 32 | for ( Weekday iday : day2.values() ) { |
---|
| 33 | System.out.print( iday.ordinal() + " " + iday.day + " " + iday.name() + ", " ); |
---|
| 34 | } |
---|
| 35 | System.out.println(); |
---|
| 36 | System.out.println( day2.isWeekday() ); // false |
---|
| 37 | System.out.println( day2.isWeekend() ); // true |
---|
| 38 | } |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | // java test |
---|
Note: See
TracBrowser
for help on using the repository browser.