CSE205 Assignment #8 Solved

50.00 $

Category: Tags: , ,
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

5/5 - (1 vote)

Minimal Submitted Files

 You are required, but not limited, to turn in the following source file:

Assignment8.java

(https://asu.instructure.com/courses/42647/files/12993480/download? wrap=1)_

(https://asu.instructure.com/courses/42647/files/12993480/download? wrap=1)_(More code need to be added)

Club.java

(https://asu.instructure.com/courses/42647/files/12993482/download? wrap=1)_

(https://asu.instructure.com/courses/42647/files/12993482/download? wrap=1)_(given by the instructor, it needs to be modified for this assignment)

President.java

(https://asu.instructure.com/courses/42647/files/12993494/download? wrap=1)_

(https://asu.instructure.com/courses/42647/files/12993494/download? wrap=1)_(given by the instructor, it needs to be modified for this assignment)

ClubNameComparator.java

MemberNumberComparator.java

CurrentPresidentComparator.java

Sorts.java

ClubManagement.java

Requirements to get full credits in Documentation

  1. The assignment number, your name, StudentlD, Lecture day/time, and a class description need to be included at the top of each file/class.
  2. A description of each method is also needed.
  3. Some additional comments inside of methods (especially for a “main” method) to explain code that are hard to follow should be

https://asuinstructure.com/courses/42647/pages/assignment8-due-wednesday-march-25th-7-00pm?module_item_id=2689624                                  2/19

 

 

written.

New Skills to be Applied

In addition to what has been covered in previous assignments, the use of the following items, discussed in class, will probably be needed:

Sorting

Searching

Aggregate Objects Interfaces

Serialization

File read/write

Program Description

Class Diagram:

 

(https://asu.instructure.com/courses/42647/files/12993483/download? wrap=1)

President

The President class implements the “Serializable” interface so that its object can be stored. (The Serializable interface is defined in the “java.io” package.) It needs to define the following method:

public void copy(President other)

It needs to copy every member variable value from “other” parameter to their corresponding variable of the object itself using “this” reference. For instance, if we have two objects of President, presidentl and president2, then, executing the following statement:

presidentl .copy(president2)

should resulting to have the object presidentl to have the same firstName, lastName, and academicLevel value as the ones for president2, but presidentl and president2 should not become aliases.

 

Club

The Club class implements the “Serializable” interface so that its object can be stored. (The Serializable interface is defined in the “java.io” package.) It needs to define the following method:

public void copy(Club other)

It needs to copy every member variable value from “other” parameter to their corresponding variable of the object itself using “this” reference.

ClubNameComparator

The ClubNameComparator class implements the “Comparator” interlace (The Comparator interface is in “java.util” package.). It needs to define the following method that was an inherited abstract method from Comparator interface:

public int compare(Object first, Object second)

(Note that you can also define:

public int compare(Club first, Club second)

instead by making the class implements Comparator<Club>.

If the first argument object has its club name less than that of the second argument, an int less than zero is returned. If the first argument object has its club name larger than that of the second argument, an int greater than zero is returned. If their club names are same, then 0 should be returned. Note that it should use String comparisons, such as using the compareTo method of the String class.

MemberNumberComparator

 

                                                                                                                                                                                                                              

The MemberNumberComparator class implements the “Comparator” interface (The Comparator interface is in “java.util” package.). It needs to define the following method that was an inherited abstract method from Comparator interface:

public int compare(Object first, Object second)

(Note that you can also define:

public int compare(Club first, Club second)

instead by making the class implements Comparator<Club>.

If the first argument object has its number of members less than that of the second argument, an int less than zero is returned. If the first argument object has its number of members larger than that of the second argument, an int greater than zero is returned. If their numbers of members are same, then 0 should be returned.

CurrentPresidentComparator

The CurrentPresidentComparator class implements the “Comparator” interface (The Comparator interface is in “java.util” package.). It needs to define the following method that was an inherited abstract method from Comparator interface:

public int compare(Object first, Object second)

(Note that you can also define:

public int compare(Club first, Club second)

instead by making the class implements Comparator<Club>.

If the first argument object has its last name less than that of the second argument, an int less than zero is returned. If the first argument object has its last name larger than that of the second argument, an int greater than zero is returned. If their last names are same, then their first names should be compared. (if the first argument object has its first name smaller (in alphabetical

 

                                                                                                                                                                                                                              

order — compareTo method of the String class), then it should return a negative integer. If the first argument object has its first name larger, then it should return a positive integer. If their last names and first names are same, then 0 should be returned.

Sorts

The Sorts class is a utility class that will be used to sort a list of Club objects. Sorting algorithms are described in the algorithm note posted under Notes section of the course web site. These algorithms sort numbers stored in an array. It is your job to modify it to sort an array of objects.

The Sorts class object will never be instantiated. It must have the following methods:

public static void sort(Club[] clubList, int size, Comparator<Club>)

Your sort method utilizes the compare method of the parameter Comparator object to sort. You can use one of Selection sort, Insertion Sort, MergeSort, or QuickSort. The parameter size specifies how many first elements should be sorted. Note that not all elements in the array should be sorted, since some of them will be null pointers.

ClubManagement

The ClubManagement class has a list of Club objects that can be organized at the club management system. The club management system will be a fully encapsulated object. The ClubManagement class implements the Serializable interface.

It has the following attributes:

clubList                                an array of Club objects A list of Club objects in the c

management system

https://asuinstructure.com/courses/42647/pages/assignment8-due-wednesday-march-25th-7-00pm?module_item_id=2689624                            7/19

 

 

the maximum number of Clu that can be stored in the clul array. It is also the size of thi array.

 

The following public methods should be provided to interact with the club management system:

 

Method
Description

 

A Constructor of the ClubManageml parameter value, it should initialize t maxSize. Then it should instantiate objects using the maxSize, and inith array to null for every index. It shoul member variable numberOfClubs to

 

 

 

Search for a Club object by clubNan and return the index of the object if I not found. The parameters are the c university of a Club object.

 

 

 

int currentPresidentExists(String firstName, String lastName, String academicLevel)

Search for a Club object in the club same president’s first name, last na level as the parameter values and ri such object if found. Return -1 if not

 

 

 

boolean addClub(String clubName, int numberOfMembers, String university, String firstName, String lastName, String academicLevel)

Add a Club object to the club list an object was added successfully at the index (numberOfClubs should be in Return false if an object with the sar university already exists or number( same as maxSize, i.e., the array is f not added).

 

Remove a Club object of the paraml the university from the club list. Rett. was removed successfully. Return fi the given club name and university object is removed, all of the (non-nu array after the removed one need to index before, and numberOfClubs s decremented by 1.

Sort the list of Club objects by club r calls the sort method defined in the the clubList, and its numberOfClubs ClubNameComparator class.

 

 

 

Sort the list of Club objects by their I members. This method calls the sor the Sorts class, using the clubList, a

numberOfClubs, an object of MemberNumberComparator class.

Sort the list of Club objects by their I information including its last names This method calls the sort method d class, using the clubList, and its nun object of CurrentPresidentComparal

List all Club objects in the club list. 1 the concatenation of each Club obje list for the number of numberOfClub size of the array here) Hint: you can toString method to help you complex add “In” at the beginning and “In” at string. If there is no object in the list, return the string containing “\nno clu

 

 

 

Closes the club management syster clubList empty. This can be done by of the clubList array to null, and alsc numberOfClubs to be 0.

 

No input/output should occur in the club management system. User interaction should be handled only by the driver class (Assignment8 class).

 

You may add other methods to the class in order to make your life easier.

Assignment8

All input and output should be handled in Assignment8 class. The main method should start by displaying this updated menu in this exact format:

ChoiceltItActionln

—– Int—- In

AItItAdd ClubIn

CltltCreate ClubManagementln

DltltSearch by ClubIn

EltItSearch by Current Presidentln

LltltList Clubsln

NltltSort by Club Namesln

OltltSort by Club Member Numbersln

PltltSort by Current Presidentsln

QltltQuitln

RltltRemove by ClubIn TItItClose ClubManagementln

UltItWrite Text to FileIn VltltRead Text from FileIn

WltltSerialize ClubManagement to FileIn

XINDeserialize ClubManagement from FileIn

?MtDisplay HelpInIn

Next, the following prompt should be displayed:

What action would you like to perform?In

Read in the user input and execute the appropriate command. After the execution of each command, redisplay the prompt. Commands should be accepted in both lowercase and uppercase. The following commands are modified or new.

 

 

Add Club

This part is already implemented in Assignment8.java file. Please see the case A in the main of Assignment8.java.

Create ClubManagement

This part is already implemented in Assignment8.java file. Please see the case C in the main of Assignment8.java.

Search by Club

This part is already implemented in Assignment8.java file. Please see the case D in the main of Assignment8.java.

Search by Current President

This part is already implemented in Assignment8.java file. Please see the case E in the main of Assignment8.java.

Sort by Club Names

This part is already implemented in Assignment8.java file. Please see the case N in the main of Assignment8.java.

Sort by Club Member Numbers

This part is already implemented in Assignment8.java file. Please see the case 0 in the main of Assignment8.java.

 

Sort by Current Presidents

 

 

This part is already implemented in Assignment8.java file. Please see the case P in the main of Assignment8.java.

Remove by Club

This part is already implemented in Assignment8.java file. Please see the case R in the main of Assignment8.java.

List Clubs

Each Club object information in the club list should be displayed using the toString method provided in the Club class. (and use listClubs( ) method in the ClubManagement class.)

This part is already implemented in Assignment8.java file.

Please see the case L in the main of Assignment8.java.

Close ClubManagement

Delete all Club objects. Then, display the following:

club management system closedln

This part is already implemented in Assignment8.java file. Please see the case R in the main of Assignment8.java

Write Text to File

Your program should display the following prompt:

Please enter a file name to write:In

https://asuinstructure.com/courses/42647/pages/assignment8-due-wednesday-march-25th-7-00pm?module_item_id=2689624                          12/19

 

                                                                                                                                                                                                                              

Read in the filename and create an appropriate object to get ready to read from the file. Then it should display the following prompts:

Please enter a string to write in the file:ln

Read in the string that a user types, say “input”, then attach “\n” at the end of the string, and write it to the file. (i.e. input+”\n” string will be written in the file.)

If the operation is successful, display the following:

FILENAME was writtenln

Replace FILENAME with the actual name of the file.

Use try and catch statements to catch I0Exception. The file should be closed in a finally statement.

Read Text from File

Your program should display the following prompt:

Please enter a file name to read: In

Read in the file name create appropriate objects to get ready to read from the file. If the operation is successful, display the following (replace FILENAME with the actual name of the file):

FILENAME was readln

Then read only the first line in the file, and display:

 

The first line of the file is:In

CONTENTIn

where CONTENT should be replaced by the actual first line in the file.

Your program should catch the exceptions if there are. (Use try and catch
statement to catch, FileNotFoundException, and the rest of I0Exception.)

If the file name cannot be found, display

FILENAME was not foundln

where FILENAME is replaced by the actual file name.

Serialize ClubManagement to File

Your program should display the following prompt:

Please enter a file name to write:In

Read in the filename and write the serialized ClubManagement object (the variable clubManagel) out to it. Note that any objects to be stored must implement Serializable interface. The Serializable interface is defined in java.io.* package. If the operation is successful, display the following:

FILENAME was writtenln

Replace FILENAME with the actual name of the file.

 

 

Use try and catch statements to catch NotSerializableExeption and I0Exception.

Deserialize ClubManagement from File

Your program should display the following prompt:

Please enter a file name to read:In

Read in the file name and attempt to load the ClubManagement object from that file. Note that there is only one ClubManagement object (the variable clubManagel) in the Assignment8 class, and the first object read from the file should be assigned to the ClubManagement object. If the operation is successful, display the following (replace FILENAME with the actual name of the file):

FILENAME was readln

Your program should catch the exceptions if there are.

(Use try and catch statement to catch ClassNotFoundException, FileNotFoundException, and the rest of I0Exception.)

See the output files for exception handling.

Test Cases

Download the following input files, inputi .bct, input2.txt, input3.txt, and input4.txt, and the following output files, outputl.txt, output2.txt, output3.txt, and output4, and save them in the same directory as Assignment5.java is located.

inputl .bct  (https://asu.instructure.com/courses/42647/files/12993484/download? wrap=1)_

(https://asu.instructure.com/courses/42647/files/12993484/download? wrap=1)

input2.txt  (https://asu.instructure.com/courses/42647/files/12993485/download? wrap=1)_

(https://asu.instructure.com/courses/42647/files/12993485/download? wrap=1)

input3.txt  (https://asu.instructure.com/courses/42647/files/12993486/download? wrap=1)_

(https://asu.instructure.com/courses/42647/files/12993486/download? wrap=1)

input4.txt  (https://asu.instructure.com/courses/42647/files/12993487/download? wrap=1)_

(https://asu.instructure.com/courses/42647/files/12993487/download? wrap=1)

outputl .bct  (https://asu.instructure.com/courses/42647/files/12993489/download? wrap=1)_

(https://asu.instructure.com/courses/42647/files/12993489/download? wrap=1)

(https://asu.instructure.com/courses/42647/files/12993491/download? wrap=1)

 

 

fhttps://asu.instructure.com/courses/42647/files/12993491/download?  wrap=1),

(https://asu.instructure.com/courses/42647/files/12993492/download? wrap=1)

output3.txt

(https://asu.instructure.com/courses/42647/files/12993492/download? wrap=1)_

(https://asu.instructure.com/courses/42647/files/12993492/download? wrap=1)

output4.txt

(https://asu.instructure.com/courses/42647/files/12993493/download? wrap=1)_

(https://asu.instructure.com/courses/42647/files/12993493/download? wrap=1)

Error Handling

Your program should be robust enough to handle all test cases above.

 

 

 

What to turn in:

 

 

-Submit your Assignment8.java, Club.java, President.java, ClubManagement.java, ClubNameComparator.java, MemberNumberComparator.java, CurrentPresidentComparator.java, Sorts.java files

using Gradescope-> Assignment8 on canvas.asu.edu. Make sure that your files are compiling and passing all test cases. You can submit multiple times until the assignment deadline.

Grading Criteria:

____ / 5 Documentation (Each class file needs to have a header with

your name, your information, and program description, each method needs its description and comments within your code)

/ 1       Indentation and spacing (easy to read)

/ 6 Required classes/methods and functionalities implemented

____ / 8 Produces correct results (test cases — auto graded)

Total points: 20

Copyright © 2020,

Arizona State University

All rights reserved.

ASU disclaimer lhttp://www.asu.edu/asuweb/disclaimern

 

                                                                                                                                                                                                                               

Copying any content of this page and posting on the Internet will be a violation of the copy right.

  • Assignment8-pfip7h.zip