CS计算机代考程序代写 Java Review:

Review:
1. OOP principle 1: Abstraction and Encapsulation
2. Relationship of objects: a. Association
b. Aggregation c. Composition
3. Java wrapper classes
4. String class and its commonly used methods
5. Basic UML
Write programs:
1. Design a class named MyInteger. Below is the UML of class MyInteger.
Constructor
Constructor, create instance from a string Return ¡°value¡±
Check if value is even
Check if value is odd
CSE148 Object Oriented Programming Homework Set 04
SCCC CSE148, Spring 2021
MyInteger
-value: int
+MyInteger(value:int) +MyInteger(strVal: String) +getValue(): int
+isEven() : boolean +isOdd () : boolean
1

Check if value is a prime number
Check if input argument is even
Check if input argument is odd
Check if input argument is a prime number Check if the input argument equals to value Check if the input argument equals this instance
2. Design a class named Stock. Below is the UML of class Stock.
Stock symbol
Stock name
Current price of this stock Previous close price of this stock
Constructor, create Stock instance with name and symbol Return current price
Set current price
Set previous closing price
Get previous closing price Get price change percent Get price change amount
SCCC CSE148, Spring 2021
+isPrime() : boolean
+isEven(value: int) : boolean
+isOdd (value: int) : boolean +isPrime(value: int) : boolean +equals(value: int) : boolean +equals(myInt: MyInteger) : boolean
Stock
-symbol: String -name: String -currentPrice: double -previousPrice: double
+Stock (symbol: String, name: String) +getCurrentPrice (): double
+setCurrentPrice (currPrice: double) : void +setPreviousClosingPrice(prevPrice: double) : void +getPreviousClosingPrice (): double +getPriceChangePercent (): double +getPriceChangeAmount (): double
2

3. Design a class named StockBag which serves as a container of a group of Stock objects. Below is the UML of this class:
Stock symbol Stock name
Constructor, create StockBag instance, set stocks to default size (16) Constructor, create StockBag instance, set stocks size to ¡®size¡¯
Add a stock into bag. Return true if operation succeed.
Remove a stock from bag. Return true if operation succeed.
Remove a stock by ¡°symbol¡± from bag. Return true if operation succeed. Search stock in stocks by stock symbol, return a stock if found, otherwise null. Get list of stock currently in this StockBag
Return number of stocks currently in StockBag
Check if is StockBag empty
** For method ¡°addStock()¡±, choose to implement one of the following logic to add a stock into the bag if ¡°stocks¡± is full: (1) Expand the size of ¡°stock¡±, this means user can always add new stock into the bag. Or,
(2) Implement circular array of ¡°stock¡± so the ¡°oldest¡± stock will be removed, and new stock can be stored.
SCCC CSE148, Spring 2021
StockBag
-stocks: Stock[] -name: String
+StockBag ()
+StockBag(size: int)
+addStock (stock: Stock): boolean +removeStock(stock: Stock) : boolean +removeStock(stockSymbol: String) : boolean +searchForStock(stockSymbol: String) : Stock +getStocks (): Stock[]
+getStockCount(): int
+isEmpty(): boolean
3

4.
5.
Give a string of words. Write a method to check if this string is a palindrome in word level. For example, the following string is a palindrome: ¡°I am a student a am I¡±. The method signature is:
boolean isPalindrome(String str, boolean ignoreCase);
ignore case of words if input param ignoreCase is true. Otherwise, do case sensitive comparison.
Write a method to check if the digits stored in a string are ascendingly or descending ordered. For example, for the following string: ¡°He2llo J4av5a 6 W8orld¡±. Digits in this string are: 2, 4, 5, 6, 8. They are ascendingly ordered. The signature of the method is:
boolean isDigitsSortedInString(String str, boolean ascend);
if input param ascend is true, check digits in string ¡°str¡± are ascendingly ordered, otherwise, check if ¡°str¡± is descending ordered.
SCCC CSE148, Spring 2021
4