Java代写:CS114 Object Oriented Concepts

作业分为五个部分,分别对应Object Oriented Concepts中的五个知识点进行编程考察。

PART1: CLASS DESIGN

Create a USMoney class with two integer instance variables dollars and cents. Add a constructor with two parameters for initializing a USMoney object. The constructor should check that the cents value is between 0 and 99 and, if not, transfer some of the cents to the dollars variable to make it between 0 and 99. Add a plus() method to the class that takes a USMoney object as its parameter. It creates and returns a new USMoney object representing the sum of the object whose plus() method is being invoked and the parameter. It does not modify the values of the two existing objects. It should also ensure that the value of the cents instance variable of the new object is between 0 and 99. For example, if x is a USMoney object with 5 dollars and 80 cents, and if y is a USMoney object with 1 dollar and 90 cents, then x.plus(y) will return a new USMoney object with 7 dollars and 70 cents. Also, create a USMoneyDemo class that tests the USMoney class. Document your code appropriately and include description on how to demonstrate the uses of the classes.

PART2: INHERITANCE

Create a Person class with private instance variables for the person’s name and birth date. Add appropriate accessor methods for these variables. Then create a subclass CollegeGraduate with private instance variables for the student’s GPA and year of graduation and appropriate accessors for these variables. Don’t forget to include appropriate constructors for your classes. Then create a class with a main() method that demonstrates your classes. Document your code appropriately and include description on how to demonstrate the uses of the classes.

PART3: IMPLEMENTING AN INTERFACE

Create a new class Constants that implements the Series interface provided below. Its getNext() method repeatedly returns the last value passed in as an argument to the setStart() method. Until setStart() is called, it returns 0. Then create a class with a main() method that demonstrates the use the interface. Document your code appropriately and include description on how to demonstrate the uses of the classes.

1
2
3
4
5
public interface Series {
int getNext();
void reset();
void setStart(int x);
}

PART4: GENERIC FUNCTION

Implement a generic method containsNull() that takes an array of type T as its parameter and returns true if any of the values in the array are null. Then create a class with a main() method that demonstrates the correct behavior of this generic method. Document your code appropriately and include description on how to demonstrate the correct behavior.

PART5: USING COLLECTIONS INTERFACES

Write a program that converts an ArrayList to a HashSet to a PriorityQueue to an ArrayDeque to a TreeSet using the version of their constructors that takes a Collection as its argument. Start by creating a small ArrayList of strings and displaying the list using its toString() method. Then similarly construct and display the other Collections, using each of them as the argument to the constructor for the next one. Even though the Collections all contain the same strings, you are likely to see those strings displayed in different orders for some of the Collections. Then create a class with a main() method that demonstrates the correct behavior of the program. Document your code appropriately and include description on how to demonstrate the correct behavior.