Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Package lab2.cscd211methods Class CSCD211Lab2Methods java.lang.Object lab2.cscd211methods.CSCD211Lab2Methods public class CSCD211Lab2Methods extends java.lang.Object The methods class for the Lab Constructor Summary Constructors Constructor Description CSCD211Lab2Methods() Method Summary

Package lab2.cscd211methods

Class CSCD211Lab2Methods

  • java.lang.Object
    • lab2.cscd211methods.CSCD211Lab2Methods
  • public class CSCD211Lab2Methods extends java.lang.Object

    The methods class for the Lab

    • Constructor Summary

      Constructors
      Constructor Description
      CSCD211Lab2Methods()
    • Method Summary

      All MethodsStatic MethodsConcrete Methods
      Modifier and Type Method Description
      static Color convertColor(java.lang.String color)

      The convertColor method converts a string to a color.

      static void displayAll(Color toFind, Person[] myPeeps)

      The displayAll method displays all Person objects that contain a specific color.

      static Person[] fillArray(java.util.Scanner fin, int total)

      The fillArray method creates an array of type person.

      static int menu(java.util.Scanner kb)

      The menu method.

      static void printArray(Person[] myPeeps)

      The print array method prints the individual person to the screen and then a carriage return between people.

      static Color readColor(java.util.Scanner kb)

      The readColor method reads a string from the keyboard and then converts it to a color by calling the private method convertColor

      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CSCD211Lab2Methods

        public CSCD211Lab2Methods()
    • Method Detail

      • convertColor

        public static Color convertColor(java.lang.String color)

        The convertColor method converts a string to a color. This method is called from various other methods.

        Parameters:

        color - String representing the color

        Returns:

        Color - The color object obtained from the String. If no color matches then and RuntimeException is thrown. This method must convert the color generically

        Throws:

        java.lang.IllegalArgumentException - if the String is null

      • displayAll

        public static void displayAll(Color toFind, Person[] myPeeps)

        The displayAll method displays all Person objects that contain a specific color.

        Parameters:

        toFind - Representing the color to find

        myPeeps - Representing the Person array

        Throws:

        java.lang.IllegalArgumentException - if the array is null

      • fillArray

        public static Person[] fillArray(java.util.Scanner fin, int total)

        The fillArray method creates an array of type person. Reads the information from the file, creates a person and places the person object into the array. The array is returned.

        Parameters:

        fin - Representing the Scanner object to the file

        total - Representing the total items that will be in the array

        Returns:

        Person [] - An filled array of containing Person objects

        Throws:

        java.lang.IllegalArgumentException - if the Scanner object is null

        java.lang.IllegalArgumentException - if total is less than or equal to 0

      • menu

        public static int menu(java.util.Scanner kb)

        The menu method. Valid menu choices are: 1. Print the Array to the screen 2. Display all people that contain a certain color 3. Sort the array by Color 4. Sort the array by the 'natural order' 5. Quit You must ensure the value entered is within range You must ensure the input buffer is left empty

        Parameters:

        kb - Representing the Scanner object to the keyboard

        Returns:

        int - Representing the menu choice

        Throws:

        java.lang.IllegalArgumentException - if the Scanner object is null

      • printArray

        public static void printArray(Person[] myPeeps)

        The print array method prints the individual person to the screen and then a carriage return between people.

        Parameters:

        myPeeps - Representing the filled array of type Person

        Throws:

        java.lang.IllegalArgumentException - if the array is null

      • readColor

        public static Color readColor(java.util.Scanner kb)

        The readColor method reads a string from the keyboard and then converts it to a color by calling the private method convertColor

        Parameters:

        kb - Representing the Scanner object

        Returns:

        Color - Representing the Color enumerated type

        Throws:

        java.lang.IllegalArgumentException - if the Scanner object is null

Package lab2.cscd211enums

Enum Color

  • java.lang.Object
    • java.lang.Enum
      • lab2.cscd211enums.Color
  • All Implemented Interfaces:

    java.io.Serializable, java.lang.Comparable

    public enum Color extends java.lang.Enum

    The enumerated type Color.

    • Enum Constant Summary

      Enum Constants
      Enum Constant Description
      BLUE
      GREEN
      PURPLE
      RED
    • Constructor Summary

      Constructors
      Modifier Constructor Description
      private Color()
    • Method Summary

      All MethodsStatic MethodsConcrete Methods
      Modifier and Type Method Description
      static Color valueOf(java.lang.String name)

      Returns the enum constant of this type with the specified name.

      static Color[] values()

      Returns an array containing the constants of this enum type, in the order they are declared.

      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • RED

        public static final Color RED
      • GREEN

        public static final Color GREEN
      • BLUE

        public static final Color BLUE
      • PURPLE

        public static final Color PURPLE
    • Constructor Detail

      • Color

        private Color()
    • Method Detail

      • values

        public static Color[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (Color c : Color.values()) System.out.println(c); 

        Returns:

        an array containing the constants of this enum type, in the order they are declared

      • valueOf

        public static Color valueOf(java.lang.String name)

        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

        Parameters:

        name - the name of the enum constant to be returned.

        Returns:

        the enum constant with the specified name

        Throws:

        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name

        java.lang.NullPointerException - if the argument is null

Package lab2.cscd211comparators

Class ColorComparator

  • java.lang.Object
    • lab2.cscd211comparators.ColorComparator
  • All Implemented Interfaces:

    java.util.Comparator

    public class ColorComparator extends java.lang.Object implements java.util.Comparator

    The ColorComparator lab implements a Comparator and ensures the parameterized type Person is used for the Comparator.

    • Constructor Summary

      Constructors
      Constructor Description
      ColorComparator()
    • Method Summary

      All MethodsInstance MethodsConcrete Methods
      Modifier and Type Method Description
      int compare(Person p1, Person p2)

      The compare method that compares two persons by the Color reference contents.

      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Comparator

        equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Constructor Detail

      • ColorComparator

        public ColorComparator()
    • Method Detail

      • compare

        public int compare(Person p1, Person p2)

        The compare method that compares two persons by the Color reference contents.

        Specified by:

        compare in interface java.util.Comparator

        Parameters:

        p1 - The first Person to be compared

        p2 - The second Person to be compared

        Returns:

        int - A negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second

        Throws:

        java.lang.IllegalArgumentException - if either Person 1 or Person are null

Package lab2.cscd211classes

Class Person

  • java.lang.Object
    • lab2.cscd211classes.Person
  • All Implemented Interfaces:

    java.lang.Comparable

    public class Person extends java.lang.Object implements java.lang.Comparable

    The person class. A person contains a first name, last name both Strings, and a Color reference to the enumerated type Color.

    • Field Summary

      Fields
      Modifier and Type Field Description
      private Color color

      The persons favorite color

      private java.lang.String fn

      The persons first name

      private java.lang.String ln

      The persons last name

    • Constructor Summary

      Constructors
      Constructor Description
      Person(java.lang.String fn, java.lang.String ln, Color color)

      Explicit Value Constructor for Person

    • Method Summary

      All MethodsInstance MethodsConcrete Methods
      Modifier and Type Method Description
      int compareTo(Person another)

      compares by last name, if the last names are the same then by first name.

      Color getColor()

      The getColor method

      java.lang.String toString()

      Prints the first name space last name, color

      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • fn

        private java.lang.String fn

        The persons first name

      • ln

        private java.lang.String ln

        The persons last name

      • color

        private Color color

        The persons favorite color

    • Constructor Detail

      • Person

        public Person(java.lang.String fn, java.lang.String ln, Color color)

        Explicit Value Constructor for Person

        Parameters:

        fn - The first name

        ln - The last name

        color - The color reference

        Throws:

        java.lang.IllegalArgumentException - if any of the parameters are null

    • Method Detail

      • compareTo

        public int compareTo(Person another)

        compares by last name, if the last names are the same then by first name. If the first names are then same then by color

        Specified by:

        compareTo in interface java.lang.Comparable

        Throws:

        java.lang.IllegalArgumentException - if another is null

      • getColor

        public Color getColor()

        The getColor method

        Returns:

        Color - Returns the reference to the enumerated type Color.

      • toString

        public java.lang.String toString()

        Prints the first name space last name, color

        Overrides:

        toString in class java.lang.Object

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems X Special Issue On Database And Expert Systems Applications Lncs 8220

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2013th Edition

3642412203, 978-3642412202

More Books

Students also viewed these Databases questions

Question

6. Does your speech have a clear and logical structure?

Answered: 1 week ago