计算机代写编程代写java代写CS116 MIDTERM EXAM-Fall 2018

0 Comments

CS116 MIDTERM EXAM-Fall 2018

SIGNATURE:

SIGN AND RETURN THE EXAM ON COMPLETION.

· Duration: 120 minutes

· This test is CLOSED book CLOSED notes. It is worth 20 points towards your final grade.

· You can use the station computer or laptop to access Notepad++. No other types of files or opening a Browser are permitted.

· At the end zip the source code and compiled files and submit the zipped file on Blackboard under Submissions => Exams => Midterm. DO NOT USE RAR!

· For Part B, submit your answers in a txt file.

· No flash drives, no smart phones allowed (put your phone in your packet).

· Partial credit will be given as appropriate

Part A: Programming [15 pts] You are working on a project to automate the standings of sports teams. Your project consists of a service class in Team.java and a client class in TeamClient.java.Team.java The specifications of Team.java are: · Every Team has a unique String name, an integer number of wins and an integer number of losses (wins plus losses equals total games).· We need default and non-default constructors, and standard set* and get* methods.· A “winningPercentage“ method to calculate and return the real number winning percentage (divide the wins by total games and return the real number result). If zero games have been played, return a zero winning percentage.

· A “toString” method, which returns a formatted String containing all the data ,the winning percentage members (no special formatting needed), and below phrase depending on the winning percentage:

· “Over 500 Team” if winning percentage is greater than .5

· “Under 500 Team” if winning percentage is less than .5

· “500 Team” if winning percentage equals .5

· Place the Team.java in a package called Midterm.Service

TeamClient.java

· The purpose of the client is to read the information about the team from the text file and add it to a data structure. The client will then sort the team information and print it out.

· Download the file “TeamClient.java” and text file called “TeamTxt.txt” from the Blackboard, which has the code to read the information on the wins and losses of the teams from a text file called “TeamTxt.txt”. The format of the text file is:

TEAM-NAME:NO-OF-WINS:NO-OF-LOSSES

· The client is placed in the package Midterm.Client

· You will modify the client file in the following way:

o As the client reads in each line from the text file, an object of Class Team is created with the information on the team (name, wins and losses)

o Import relevant user defined and pre-defined classes.

o The client has a data structure to store the objects. You have the choice to implement this data structure as an array or Vector or ArrayList.

o After reading the file, and creating and populating the data structure, the client will implement selection sort to sort the data structure in decreasing order of the teams’ “winningPercentage”. The first index in your data structure should have the team with the highest winningPercentage, the second index should have the team with second highest winningPercentage, and so on.

o Finally, the client should print out all the entries in the data structure in order.

Extra-credit[5 pts]

· The text file can have duplicate entries for a team. Two entries are said to be duplicate if the team names match. When the client encounters a duplicate entry, it should add the wins and losses from the duplicate entry to the wins and losses information of the team already in the data structure.

· You should implement code that will check for and remove duplication before sorting and print out the entries.

Note, maintain the package structure, as declared in the java files. Make sure your code compiles and generates the correct results.

You can refer to the attachment “Sample-output.txt”, which has the output when the duplicates have been removed.

Part B: Theory [5 pts]Submit your answers for Part B as a text file called “PartB.txt” Multiple Choice Questions:1. Which of the following is FALSE about arrays in Java A. Java array is always an objectB. Length of array can be changed after creationC. Array’s length attribute provides the size of the arrayD. Array can store objects Answer:2. Conider the following code snippet. What is the result of compiling and executing this class? public class MainClass{public static void main(String[] args){int[] a = new int[10]; int[] b = new int[100];a = b;}}A. Compilation errorB. Execution errorC. Compiles but gives an execution errorD. Compiles and executes successfully Answer: 3. In the following array, what is the value of fees.length? double[][] fees = {{3.00, 3.50, 4.00, 5.00},{6.35, 7.35, 8.35, 9.00}};a. 2b. 4c. 8d. none of the above Answer: 4. Which search algorithm would be best to use with ordered data? a) Binary searchb) Sequential searchc) Binary and sequential search have the same performanced) Cannot use either binary or sequential search

Answer:

5. What is the output of the following code? enum Barcode{

one, two, three, four, five;

}

public class HashTest{

public static void main(String[] str){ Barcode bar = Barcode.two; System.out.println(bar);

}

}

a) two

b) Compilation error

c) execution error

d) None of the above

Answer:

Comments