CS 3667 Lecture 5: CreatingOrdinalTypesProgram

85 views3 pages

Document Summary

1. write a class that shows how to declare and use an ordinal type in java. 2. provide mechanism (i. e. , comparator) that demonstrates how to use the ordinal type in. // instance variables - replace the example below with your own private int x; private rainbowcolors[] s1; * @param colors private rainbowcolors(int colors) { this. colors = colors; * @return colors public int getrainbowcolors() { return colors; * public constructor for class. public ordinal() s1 = new rainbowcolors[7]; s1[0] = rainbowcolors. yellow; s1[1] = rainbowcolors. red; s1[2] = rainbowcolors. green; s1[3] = rainbowcolors. violet; s1[4] = rainbowcolors. blue; s1[5] = rainbowcolors. orange; s1[6] = rainbowcolors. indigo; * @param o1 a sample parameter for a method. * @param o2 a sample parameter for a method. * @return returns whether the first colors object. * is greater than, less than, or equal to the other colors object. 9/10/2016 public int compare(rainbowcolors o1, rainbowcolors o2) { return o1. getrainbowcolors() - o2. getrainbowcolors(); class rainbowcolorscomparator implements comparator {

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents