java代写 java代码代写 java程序代写 java作业代写

java编程代写, java代做, java编程作业代写, java程序作业代写

CS 125 Java intro assignment 

● BasicUser.java containing all methods for Task 1 

● VIP.java containing all methods for Task 1 

● ServerQueue.java containing all methods for Task 1 

● EasterEgg.java containing all methods for Task 2 

Task 1 

For Task 1, you will be working with a virtual server queue(s) that allows Basic Users and VIP 

Users to join and exit the queue. 

You will be using abstract and concrete classes, static and non-static methods, and ArrayLists. 

Furthermore, you do not need to worry about deep copies. 

The source folder has those files: BasicUser.javaServerQueue.java

ServerQueueTester.javaUser.javaVIP.javaYou will be implementing several 

methods within BasicUser.javaServerQueue.java, and VIP.java, and you will be 

testing those methods in ServerQueueTester.javaFor Task 1, you need to submit 

BasicUser.javaServerQueue.java, and VIP.java

ServerQueueTester.java 

Within ServerQueueTester.java are a few test cases for the ServerQueue class. As you 

are implementing BasicUser.javaServerQueue.java, and VIP.java, you should test 

thoroughly to make sure that your program is functioning as expected. We will not be 

collecting ServerQueueTester.java

User.java 

The User class is an ABSTRACT class that maintains simple user information. This file is 

already completed for you, so you must NOT make any changes to this file. Within the 

User class, there is one private member variable - nameWe also provide a getter and setter 

method for the name, and we provide an abstract method that you will have to implement in the 

subclasses BasicUser and VIP. Be sure that you understand everything that is given within 

this file! 

BasicUser.java 

The BasicUser class is a CONCRETE class that maintains information about a basic user and 

that EXTENDS the User class. This file contains NO extra member variables. 

We provide you with one getter function that simply returns false. Please read the method 

carefully and understand its purpose.You must implement the following 2 methods: 

1. public BasicUser(String name) 

This constructor should simply set this.name to the parameter name. However, it is 

not that simple because inside the User class, this.name is private. Figure out how to 

set this.name to be the parameter nameHINT: It should only take one line of code. 

2. public String getInformation() 

This method should return the concatenation of "BASIC USER: " and this.name

For example, if this.name was "Henry Doe", then this method should return 

"BASIC USER: Henry Doe". Keep in mind that there is a space between BASIC 

and USER, and that there is a space after the colon (:). 

VIP.java 

The VIP class is a CONCRETE class that maintains information about a VIP user and that 

EXTENDS the User class. This file contains 1 extra private member variable - 

hasPriorityhasPriority is used to determine if the VIP user has priority within the 

queue. We also provide you with hasPriority's respective getter method. 

You must implement the following 2 methods: 

1. public VIP(String name, boolean hasPriority) 

This constructor should simply set this.name to the parameter name, and this 

constructor should also simply set this.hasPriority to the parameter 

hasPriority. Learning from what you did in the BasicUser class, figure out how to set 

this.name as well as this.hasPriority

2. public String getInformation() 

This method should return the concatenation of "VIP: "this.name, and either 

PRIORITY_STR or NO_PRIORITY_STR depending on the priority status of the VIP 

user. For example, if this.name was "Claire Doe" and this.hasPriority was 

false, then this method should return "VIP: Claire Doe - NO PRIORITY"

Keep in mind that there is a space after the colon (:). 

ServerQueue.java 

Within ServerQueue.java, there are 2 private member variables given to you: 

● 

private String name - the name of the server 

● 

private ArrayList queue - the queue for the server 

NOTE: The User objects in queue will always be valid User objects (no null Users or invalid 

Users).Take note of the declared types of name and queue. Do NOT change their types. 

We also provide you with two getter methods. Please carefully read and understand the 

methods. 

You must implement the 5 following methods: 

1. public ServerQueue(String name) 

This constructor should set this.name to be the parameter name, and this constructor 

should also set this.queue to be a new, empty ArrayList. 

2. public void clearQueue() 

This method should either set this.queue to be a new, empty ArrayList, or call the 

.clear() method on this.queue. In other words, this method should simply clear 

the queue (without setting the queue to null). 

3. public void appendToQueue(User user) 

This method should append (or add) the parameter user to the end of this.queue

For example, consider the following queue (which is NOT quite a memory model 

diagram) where the left is the front of the queue: 

Appending a VIP user named "Mary" with hasPriority as true would result in the 

following queue: 

4. public User removeFromQueue() 

This method should first check if there is a VIP user in the queue that has priority (i.e. 

VIP user with hasPriority == true). If there is such a VIP user, then you should 

remove and return the first instance of that VIP user. If there is NOT such a VIP user, 

then you should remove and return the first user (either VIP or BasicUser - does not 

matter) at the front of the queue (which is at index 0). 

In other words, remove and return the first priority VIP user if possible. Otherwise, 

remove and return the user at the front of the queue. 

NOTE: You can assume that there will always be at least one User in the queue when 

calling this method.For example, consider the following queue where the left is the front of the queue. 

Calling removeFromQueue() on that queue would result in the following queue: 

where the VIP user "Mary" would be returned. 

5. public static void mergeQueue(ServerQueue q1, ServerQueue q2) 

This method should append (or add) all the Users from q2's queue to the end of q1's 

queue while maintaining their same order. Furthermore, this method should clear q2's 

queue

For example, if q1's queue looked like the following: 

and if q2's queue looked like the following: 

Then, after calling mergeQueueq1's queue should look like: 

and q2's queue should be completely empty.Task 2 

An Easter Egg race is afoot and you're eyeing the first prize! Unlike a regular hunt, you know 

exactly where the eggs are, but for you to be able to reach the finish line in time, you decide 

NOT to collect two consecutive eggs in a row. Each egg is worth ten times the position that 

the egg is located at. For example, the first egg is worth 10 points, the second egg is worth 20 

points, the third egg is worth 30 points, and so on. If you're lucky enough, you can find golden 

eggs which are worth double that of a regular chocolate egg. 

An example ArrayList would be ['Chocolate', 'Chocolate', 'Golden', 

'Chocolate', 'Golden', 'Chocolate', 'Chocolate'] and their potential scores 

would be [10, 20, 60, 40, 100, 60, 70]. As you can see, the 1st golden egg (at index 

2) has a point of 2 * 30 = 60. 

In order to win, you would have to maximize the score you could possibly get. Keeping in mind 

that you CANNOT pick two consecutive eggs in a row, you would choose the eggs that give you 

the scores - 10 + 60 + 100 + 70 = 240 (which are the first, third, fifth, and seventh indices 

respectively). 

Please download the starter code from here. Ensure that there are 2 files: 

EasterEgg.java and EasterEggTester.java

EasterEggTester.java 

Within EasterEggTester.java are a few test cases for the EasterEgg class. As you are 

implementing EasterEgg.java, you should test thoroughly to make sure that your 

program is functioning as expected. We will not be collecting EasterEggTester.java

EasterEgg.java 

Within EasterEgg.java, you will be required to implement the 2 following methods: 

1. public int[] calculateScores(ArrayList eggs) throws Exception 

Read BOTH (a) and (b) before implementing this method! 

(a) This method will be used to generate and return the scores for each egg as an 

array, when the input given is an ArrayList of Strings that can could either be 

'Chocolate' (to denote regular chocolate eggs) or 'Golden' (to denote 

golden eggs worth double the regular score). 

An example ArrayList that would be passed to the method would be: 

['Chocolate', 'Chocolate', 'Golden', 'Chocolate', 

'Golden', 'Chocolate', 'Chocolate'] 

and the scores array to be returned would be: [10, 20, 60, 40, 100, 

60, 70].NOTE 1: Keep in mind - for a chocolate egg at index i, its score would be 

(i+1) * 10, and for a golden egg at index i, its score would be worth (i+1) 

* 20

(b) Exception Handling: Consider the following edge case - while you are iterating 

through the ArrayList parameter eggs, if eggs contained a string that was NOT 

"Chocolate" or "Golden", then you should handle this edge case via an 

Exception

While reading in the inputs from the ArrayList, make sure to throw new 

Exception with the message "Invalid Easter Egg" if such an erroneous 

string is encountered. Likewise, in EasterEggTester.java, you would then 

need to implement try and catch statements in order to print out the 

appropriate message. We already provide you with a try-catch block for 

obj1, so if you write additional tests that call calculateScores, then you 

would need to surround them in a try-catch block. 

NOTE 1: Make sure that the error message inside the new Exception is the 

same, exact error message as above. 

2. public int maxScore(int scores[], int idx) 

This method should RECURSIVELY calculate the highest score possible when the 

condition of skipping two eggs in a row is followed. In other words, if an egg at index 

is chosen, then egg i+1 cannot be chosen. The scores array generated in the 

previous step should be passed as a parameter. To help with recursion, the second 

parameter you pass in MUST initially be the first index, (refer to the tester file to see 

the value of idx being passed in to the maxScore call). This is important because our 

tests will pass in idx as 0

For the example scores array above, you would return 240 as the highest score 

because you would choose 10 + 60 + 100 + 70

Here's another example - consider the scores array [10, 20, 60, 40, 50, 120]

You would return 190 as the highest score because you would choose 120 + 60 + 

10

HINT: Think about your base case (i.e. when do you stop recursion), and what 

respective recursive calls should you make? Knowing that you cannot choose two eggs 

in a row (i.e. you cannot choose and i+1), what indices should you check instead?

京ICP备2025144562号-1
微信
程序代写,编程代写
使用微信扫一扫关注
在线客服
欢迎在线资讯
联系时间: 全天