Question

In: Computer Science

Enumerations Create an advanced enumeration to represent months (JANUARY – DECEMBER) called enuMonths Add internal properties...

Enumerations

  1. Create an advanced enumeration to represent months (JANUARY – DECEMBER) called enuMonths
    1. Add internal properties to represent a month.
      1. friendlyName                ( e.g., January, February, etc. )
      2. shortName                   ( e.g., Jan, Feb, etc. )
      3. monthNumber              ( e.g., 1, 2, etc. )
      4. daysInMonth                ( e.g., 31, 28, etc. )
      5. isLeapYearMonth          ( e.g., false, true, etc. )
  2. Create an advanced enumeration for a deck of cards in a game of blackjack called enuCards ( AH, 2H, 3H, etc… )
    1. Add the internal properties
      1. friendlyName                ( e.g., Ace of Hearts, 2 of Diamonds, etc. )
      2. minPointValue              ( e.g., 1, 2, etc. )
      3. maxPointValue             ( e.g., 11, 2, etc. )

  1. Create an advanced enumeration of your own. You can decide the subject and the properties it stores.  You can also add public methods to the enumeration that perform a task or calculation.

Interfaces

  1. Create an interface that would apply to all vending machines called iVendingMachine.  You will need to come up with the methods on your own that will be applied to anything that interfaces with the iVendingMachine interface
  2. Create an interface for an automobile called iAutomobile. This interface should cover what any automobile would need to implement.

Solutions

Expert Solution

1.

//enuMonths.java : Java enumeration enuMonths to represent months

public enum enuMonths {

      

       JANUARY("January","Jan",1,31,false),

       FEBRUARY("February","Feb",2,28,true),

       MARCH("March","Mar",3,31,false),

       APRIL("April","Apr",4,30,false),

       MAY("May","May",5,31,false),

       JUNE("June","Jun",6,30,false),

       JULY("July","Jul",7,31,false),

       AUGUST("August","Aug",8,31,false),

       SEPTEMBER("September","Sep",9,30,false),

       OCTOBER("October","Oct",10,31,false),

       NOVEMBER("November","Nov",11,30,false),

       DECEMBER("December","Dec",12,31,false);

      

       public String friendlyName;

       public String shortName;

       public int monthNumber;

       public int daysInMonth;

       public boolean isLeapYearMonth;

      

       private EnuMonths(String friendlyName, String shortName, int monthNumber, int daysInMonth, boolean isLeapYearMonth)

       {

             this.friendlyName = friendlyName;

             this.shortName = shortName;

             this.monthNumber = monthNumber;

             this.daysInMonth = daysInMonth;

             this.isLeapYearMonth = isLeapYearMonth;

       }

}

//end of enuMonths.java

2.

//enuCards.java : Java enumeration enuCards to represent blackjack cards

public enum enuCards {

      

       A_H("Ace of Hearts",1,11),

       TWO_H("2 of Hearts",2,2),

       THREE_H("3 of Hearts",3,3),

       FOUR_H("4 of Hearts",4,4),

       FIVE_H("5 of Hearts",5,5),

       SIX_H("6 of Hearts",6,6),

       SEVEN_H("7 of Hearts",7,7),

       EIGHT_H("8 of Hearts",8,8),

       NINE_H("9 of Hearts",9,9),

       TEN_H("10 of Hearts",10,10),

       J_H("Jack of Hearts",10,10),

       Q_H("Queen of Hearts",10,10),

       K_H("King of Hearts",10,10),

      

       A_D("Ace of Diamonds",1,11),

       TWO_D("2 of Diamonds",2,2),

       THREE_D("3 of Diamonds",3,3),

       FOUR_D("4 of Diamonds",4,4),

       FIVE_D("5 of Diamonds",5,5),

       SIX_D("6 of Diamonds",6,6),

       SEVEN_D("7 of Diamonds",7,7),

       EIGHT_D("8 of Diamonds",8,8),

       NINE_D("9 of Diamonds",9,9),

       TEN_D("10 of Diamonds",10,10),

       J_D("Jack of Diamonds",10,10),

       Q_D("Queen of Diamonds",10,10),

       K_D("King of Diamonds",10,10),

      

       A_S("Ace of Spades",1,11),

       TWO_S("2 of Spades",2,2),

       THREE_S("3 of Spades",3,3),

       FOUR_S("4 of Spades",4,4),

       FIVE_S("5 of Spades",5,5),

       SIX_S("6 of Spades",6,6),

       SEVEN_S("7 of Spades",7,7),

       EIGHT_S("8 of Spades",8,8),

       NINE_S("9 of Spades",9,9),

       TEN_S("10 of Spades",10,10),

       J_S("Jack of Spades",10,10),

       Q_S("Queen of Spades",10,10),

       K_S("King of Spades",10,10),

      

       A_C("Ace of Clubs",1,11),

       TWO_C("2 of Clubs",2,2),

       THREE_C("2 of Clubs",3,3),

       FOUR_C("4 of Clubs",4,4),

       FIVE_C("5 of Clubs",5,5),

       SIX_C("6 of Clubs",6,6),

       SEVEN_C("7 of Clubs",7,7),

       EIGHT_C("8 of Clubs",8,8),

       NINE_C("9 of Clubs",9,9),

       TEN_C("10 of Clubs",10,10),

       J_C("Jack of Clubs",10,10),

       Q_C("Queen of Clubs",10,10),

       K_C("King of Clubs",10,10);

      

       public String friendlyName;

       public int minPointValue;

       public int maxPointValue;

       private EnuCards(String friendlyName, int minPointValue, int maxPointValue)

       {

             this.friendlyName = friendlyName;

             this.minPointValue = minPointValue;

             this.maxPointValue = maxPointValue;

       }

      

}

//end of enuCards.java

3.

//enuDays.java : Java enumeration enuDays to represent days

public enum enuDays {

       SUNDAY("Sunday","Sun",1),

       MONDAY("Monday","Mon",2),

       TUESDAY("Tuesday","Tue",3),

       WEDNESDAY("Wednesday","Wed",4),

       THURSDAY("Thursday","Thu",5),

       FRIDAY("Friday","Fri",6),

       SATURDAY("Saturday","Sat",7);

      

       public String friendlyName;

       public String shortName;

       public int dayNumber;

      

       private EnuDays(String friendlyName, String shortName, int dayNumber)

       {

             this.friendlyName = friendlyName;

             this.shortName = shortName;

             this.dayNumber = dayNumber;

       }     

}

//end of enuDays.java

4.

//iVendingMachine.java : Vending Machine Interface

public interface iVendingMachine {

      

       // method to select the index of the item

       public void selectItem(int i);

       // method to insert the money to buy the selected item

       public void insertMoney(int i, double money);

       // method to return the change corresponding to the money inserted and item selected

       public double returnBalance(int i, double moneyInserted);

}

//end of iVendingMachine.java

//iAutomobile.java : iAutomobile interface

public interface iAutomobile {

       // method to start the automobile

       public void start();

       // method to accelerate the automobile's speed

       public void acceleterate();

       // method to apply brakes

       public void brake();

       // method to stop the automobile

       public void stop();

}

//end of iAutomobile.java


Related Solutions

Define a table with the following properties that represent an election. Create a unique id for...
Define a table with the following properties that represent an election. Create a unique id for the table. Create a field or fields representing an election's description. Create a field or fields representing an election's date. Create a field or fields representing an election's status (active or inactive)
Create a project called rise. Add a class called GCD. Complete a program that reads in...
Create a project called rise. Add a class called GCD. Complete a program that reads in a numerator (as an int) and a denominator (again, as an int), computes and outputs the GCD, and then outputs the fraction in lowest terms. Write your program so that your output looks as close to the following sample output as possible. In this sample, the user entered 42 and 56, shown in green. Enter the numerator: 42 Enter the denominator: 56 The GCD...
with PHP Create a class called Invoice that a hardware store might use to represent an...
with PHP Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables — a part number (type String), a part description (type String), a quantity of the item being purchased (type int) and a price per item (double). Your class should have a constructor that initializes the four instance variables. Provide a set and a get method...
----------------------------------------------------------------------------------------------- Create a class called MathOperations that a teacher might use to represent the basic type...
----------------------------------------------------------------------------------------------- Create a class called MathOperations that a teacher might use to represent the basic type of mathematical operations that may be performed. The class should include the following: Three double private variables as instance variables, number1, number2, and result. Your class should have a default constructor that initializes the three instance variables to zero. Your class should also have a constructor that initializes the two instance variables (number1 and number2) to the value entered by the user from keyboard....
With PHP Create a class called Account that a bank might use to represent customers' bank...
With PHP Create a class called Account that a bank might use to represent customers' bank accounts. Your class should include one data member of type int to represent the account balance. Your class should provide a constructor that receives an initial balance and uses it to initialize the data member. The constructor should validate the initial balance to ensure that it is greater than or equal to 0. If not, the balance should be set to 0 and the...
Invoice Class - Create a class called Invoice that a hardware store might use to represent...
Invoice Class - Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables—a part number (type String), a part description (type String), a quantity of the item being purchased (type int) and a price per item (double). Your class should have a constructor that initializes the four instance variables. If the quantity passed to the constructor is...
Invoice Class - Create a class called Invoice that a hardware store might use to represent...
Invoice Class - Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables—a part number (type String), a part description (type String), a quantity of the item being purchased (type int) and a price per item (double). Your class should have a constructor that initializes the four instance variables. If the quantity passed to the constructor is...
Create a c++ class called Fraction in which the objects will represent fractions. Remember:   do not...
Create a c++ class called Fraction in which the objects will represent fractions. Remember:   do not reduce fractions, do not use "const," do not provide any constructors, do not use three separate files. You will not receive credit for the assignment if you do any of these things. In your single file, the class declaration will come first, followed by the definitions of the class member functions, followed by the client program. It is required that you provide these member...
. Create a class called Book to represent a book. A Book should include four pieces...
. Create a class called Book to represent a book. A Book should include four pieces of information as instance variables‐a book name, an ISBN number, an author name and a publisher. Your class should have a constructor that initializes the four instance variables. Provide a mutator method and accessor method (query method) for each instance variable. Inaddition, provide a method named getBookInfo that returns the description of the book as a String (the description should include all the information...
1. Create a class named Mobile 2. Add IEMICode, processor, make, model and color properties to...
1. Create a class named Mobile 2. Add IEMICode, processor, make, model and color properties to the Mobile class 3. Create a methods connectBlueTooth, sendMessage, changeColor, displayInfo in the class Mobile. 4. Write a python script that creates two instances of the class Mobile, changes their colors to Black and Pink and prints a message to the console to display the object attributes using the displayInfo method 5. Run the program and observe the message in Console
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT