联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Java编程Java编程

日期:2018-09-16 02:16

CSCI-UA作业代写代做java编程作业、代写 javaTestFileRead代做、Java作业代写、帮做ava作业

CSCI-UA 102, Fall 2018

Project 1

1

Project 1: Game of Thrones Battle Archive

Due date: September 24, 11:55PM EST.

You may discuss any of the assignments with your classmates and tutors (or anyone else) but all work for all assignments must

be entirely your own . Any sharing or copying of assignments will be considered cheating (this includes posting of partial or

complete solutions on Piazza or any public forum). If you get significant help from anyone, you should acknowledge it in your

submission (and your grade will be proportional to the part that you completed on your own). You are responsible for every line

in your program: you need to know what it does and why. You should not use any data structures and features of Java that have

not been covered in class (or the prerequisite class). If you have doubts whether or not you are allowed to use certain structures,

just ask your instructor.

In this project you will provide a tool for looking up the major battles in Game of Thrones, by the name of the characters who participated

in them. Your program will use the data provided with this assignment that contains a list of characters and their allegiances, and a

second file with details about each battle, including the attacking king and defending king who participated.

Objectives

The goal of this programming project is for you to master (or at least get practice on) the following tasks:

• working with multi-file programs

• reading data from inputfiles

• working with data sets

• using the ArrayList class

• writing classes

• working with existing code

• extending existing classes (inheritance)

Most, if not all, of the skills that you need to complete this project are based on the material covered in cs101. But there might be certain

topics for which you did not have to write a program or that you forgot. Make sure to ask questions during recitations, in class and on

Piazza.

Start early! This project may not seem like much coding but debugging always takes time.

Dataset

In this project you will be working with data provided with the assignment. For the purposes of this project, you must only utilize

the data provided specifically for this assignment.

There are two files you will use:

• characters.csv: contains characters with allegiances

• battles.csv: contains information for each major battle, as well as the character names of the attacking and defending kings

CSCI-UA 102, Fall 2018

Project 1

2

Program’s Data

For this program, the data files are considered to be part of the

application(notthe input providedbytheuseratruntime). You

should store all ofthe data filesin their own directory calleddata

inside the project directoryinEclipse (thisis atthe same directory

assrc directory thatstoresthe actual code, possibly in packages).

This way you can open the filesfrom within your program using

the relative path, for example, "data/battles.csv".

Within Eclipse the project/folder/package hierarchy should look

something like the image on the right.

Youcan test yoursetup using theTestFileRead classincluded

at the end of this specification.

If you setup your program and data differently, the graders may not

be able to run the code successfully.

User Interface

Your program has to be a console based program (no graphical interface).

Program Usage

The program is started from the command line (or run within an IDE). It does not use any command line arguments (if any are provided,

the program should simply ignore them).

Input and Output

The program should run in a loop that allows the user to see the battles associated with any character name, or all characters. On each

iteration, the user should be prompted to enter either a name (for which the program lists the results), or ‘all’ to see all characters and

any battles they participated in (grouped by character), or ‘exit’ to indicate the termination of the program.

The user should not be prompted for any other response.

If the name entered by the user cannot be found in the list of names stored in the dataset (i.e., it does not occur in ANY of the files), the

program should print a message

Character not found!

and continue into the next iteration.

If the name entered by the user matches a character name, the program should print the character name and allegiance, and then print

the battles for which the character was either the attacking king or the defending king. Once the results are displayed, the program

should continue into the next iteration.

Any error messages generated by your code should be written to the System.err stream (not the System.out stream).

Robyn Peterson

robyn@cs.nyu.edu

CSCI-UA 102, Fall 2018

Project 1

3

Input:

Your program should prompt the user for input:

Enter a character name (or type "all" for all characters, or "exit" to exit):

Output:

If the name entered by the user is found, the name of the character should be displayed with his/her allegiance, and then a list of the

battles the character participated in, listed in alphabetical order. like this:

Enter a character name (or type "all" for all characters, or "exit" to exit):

stannis baratheon

Stannis Baratheon with allegiance to Baratheon

- Battle of Castle Black, when Stannis Baratheon attacked Mance Rayder, resulting in a loss, through a siege, at

Castle Black, in the region of Beyond the Wall

- Battle of the Blackwater, when Stannis Baratheon attacked Joffrey Baratheon, resulting in a loss, through a

pitched battle, at King's Landing, in the region of The Crownlands

- Retaking of Deepwood Motte, when Stannis Baratheon attacked Balon Greyjoy, resulting in a win, through a

pitched battle, at Deepwood Motte, in the region of The North

- Second Seige of Storm's End, when Joffrey Baratheon attacked Stannis Baratheon, resulting in a win, through a

siege, at Storm's End, in the region of The Stormlands

- Siege of Dragonstone, when Joffrey Baratheon attacked Stannis Baratheon, resulting in a win, through a siege,

at Dragonstone, in the region of The Stormlands

- Siege of Storm's End, when Stannis Baratheon attacked Renly Baratheon, resulting in a win, through a siege, at

Storm's End, in the region of The Stormlands

- Siege of Winterfell, when Stannis Baratheon attacked Joffrey Baratheon, resulting in a loss, through a siege,

at Winterfell, in the region of The North


In the case where the user types in ‘all’ the program should display each character and their battles, where the characters, and the battles

for each, are ordered alphabetically.

Something to consider:

The program should be case in-sensitive with respect to the user input. The name in the data file is always capitalized properly,

for example ‘stannis baratheon’ should be considered the same input as ‘Stannis Baratheon’. Your program should produce exactly

the same results regardless.

The program should not terminate until the user types ‘exit’. Otherwise, it should just keep looping on the user input.

Data Storage and Organization

Your need to provide an implementation of several classes that store the data and compute the results when the program is executed.

In particular, your program must implement and use the following classes. You may implement additional classes as well, if you wish.

Robyn Peterson

robyn@cs.nyu.edu

CSCI-UA 102, Fall 2018

Project 1

4

MyArrayList Class

The MyArrayList class is a container class just like the ArrayList<E> class that is part of JavaAPI. In fact, your own implementation

must inherit from ArrayList<E> class. The main difference is that your class will be used for working with generic elements whose

type implements Comparable<E> interface. Your class will be using a bounded generic type. To achieve this, your classheader should

look as follows:

public class MyArrayList<E extends Comparable<E>> extends ArrayList<E>

Your own implementation ...

... must overload the sort method of the ArrayList class. Your own sort method should take no parameters and should not

return anything. It should operate on the object on which it is called and sort the elements according to their natural order (the one

defined by the compareTo method). This method should make use of Collections.sort() to perform its task.

[Optional: You may try to implement your own sort method (one of the ones you learned about in cs101) to see how the performance

of Collections.sort() compares to your own implementation. Do not submit that version of the program.]

... must implement isSorted() method that returns true or false if the elements stored in the collection are sorted or not sorted,

respectively. The method should use the natural ordering of the elements, i.e. the compareTo method defined on the elements.

... must override the contains method implemented in the ArrayList class. The method should determine if the elements stored

in the container are sorted, and if so, apply a binary search algorithm. If the elements are not in a sorted order, the method should

call the contains implemented in the ArrayList class (this method performs a linear search).

You may implement additional methods, if you wish.

Note, that MyArrayList is a generic class, i.e., it can store elements of any type (as long as the type is consistent within the container).

Battle Class

The Battle class holds all the information for a given battle. This class should provide a seven-parameter constructor:

public Battle (String name, String attackerKing, String defenderKing, String attackerOutcome, String battleType,

String location, String region)

There should be no default constructor.

This class should implement Comparable<Battle> interface. The comparison should be done with the name as primary key (using

alphabetical order). In other words, thisclassshouldoverride thecompareTomethod, by using the String compareTo method to

compare name.

The class should override the toString method so that it returns a String object that is a meaningful representation of the object on

which it is called:

String construction:

(" - "+name+", when "+ attackerKing+" attacked "+ defenderKing+", resulting in a "+ attackerOutcome+", through a

"+ battleType+", at "+ location+", in the region of "+ region)

Output:

- Siege of Winterfell, when Stannis Baratheon attacked Joffrey Baratheon, resulting in a loss, through a siege,

at Winterfell, in the region of The North

You will need to instantiate one Battle object for each battle in the data set.

Character Class

The Character class holds all the information for a given character. This class should provide a three-parameter constructor:

public Character (String name, String allegiances, MyArrayList<Battle> battles)

Robyn Peterson

robyn@cs.nyu.edu

CSCI-UA 102, Fall 2018

Project 1

5

Note that the class should contain a data field for name, the allegiance of the character, and a collection that stores all of the Battle

objects in which the character participated. You should use your own MyArrayList class for that purpose.

Thisclassshouldoverride the compareTomethod, by using the String compareTo method to compare on name.

The class should override the toString method so that it returns a String object that is a meaningful representation of the object on

which it is called, and it should invoke the toString method of the Battles MyArrayList:

Renly Baratheon with allegiance to House Baratheon

- Siege of Storm's End, when Stannis Baratheon, attacked Renly Baratheon, resulting in a win, through a siege,

at Storm's End, in the region of The Stormlands

You may implement other methods, if you wish.

You will need to instantiate one Character object for each character in the data set.

GameOfThrones Class

The GameOfThrones class is the actual program. This is the class that should contain the main method. It is responsible for opening

and reading the data files, instantiating the Character and Battle objects, obtaining user input, and printing out responses.

You may (and probably should) implement other methods in this class to modularize the design.

Programming Rules

The data files should be read only once! Your program needs to store the data in memory resident data structures.

You may not use any of the classes that were not covered in cs101 (for this assignment, do not use LinkedList, Stack, Queue.

TreeSet, PriorityQueue. or any classes implementing Map interface).

Working on This Assignment

You should start right away! And, if you’re unsure of code style, etc, please review the Google Java Style Guide:

https://google.github.io/styleguide/javaguide.html

You should modularize your design so that you can test it regularly. Make sure that at all times you have a working program. You can

implement methods that perform one task at a time. This way, if you run out of time, at least parts of your program will be functioning

properly.

Robyn Peterson

robyn@cs.nyu.edu

CSCI-UA 102, Fall 2018

Project 1

6

You should make sure that your program’s results are consistent with what is described in this specification by running the program on

carefully designed test inputs and examining the outputs produced to make sure they are correct. The goal in doing this is to try to find

the mistakes you have most likely made in your code.

You should back up your code after each time you spend some time working on it. Save it to a flash drive, email it to yourself,

upload it to your Google drive, do anything that gives you a second (or maybe third copy). Computers tend to break just a few

days or even a few hours before the due dates - make sure that you have working code if that happens.

Grading

If your program does not compile or if it crashes (almost) every time it is run, you will get a zero on the assignment.

If the program does not adhere to the specification, the grade will be low and will depend on how easy it isto figure out what the program

is doing.

25 points program correctness (the correct values and format of output) - note that if your program does not produce correct results,

you will most likely lose points for the implementation part since the implementation itself is most likely incorrect.

60 points design and implementation of the four required classes and any additional classes

• MyArrayList class (15 points)

• Battle class (15 points)

• Character class (15 points)

• GameOfThrones class (15 points)

5 points efficient design

10 points program style, documentation, and format of submission

How and What to Submit

Your should submit all your source code files (the ones with .java extensions only) in a single zip file to NYU Classes.

You can produce a zip file directly from Eclipse:

right click on the name of the package (inside the src folder) and select Export...

under General pick Archive File and click Next

in the window that opens select appropriate files and settings:

– in the right pane pick ONLY the files that are actually part of the project, but make sure that you select all files that are

needed

– in the left pane, make sure that no other directories are selected

– click Browse and navigate to a location that you can easily find on your system (Desktop or folder with the our course

materials or ...)

– in Options select ”Save in zip format”, ”Compress the contents of the file” and ”Create only selected directories”

• click Finish

Do not submit the data files in your zip file!

Robyn Peterson

robyn@cs.nyu.edu

CSCI-UA 102, Fall 2018

Project 1

7

1 package project1;

2

3 import java.io.File;

4 import java.io.FileNotFoundException;

5 import java.util.Scanner;

6

7 /* *

8 * P rogram for testing if the da ta files can be opened .

9 * This program simply prints the content of the file to

10 * the console one line at a time .

11 *

12 *

13 */

14 public class TestFileRead {

15

16 public static void main(String[] args) {

17

18 String fileName = "data/characters.csv";

19 File f = new File(fileName);

20

21 if (!f.canRead()) {

22 System.err.printf("Error: cannot read "

23 + "data from file %s" ,fileName);

24 System.exit(1);

25 }

26

27 Scanner inputFile = null;

28 try {

29 inputFile = new Scanner(f);

30 } catch (FileNotFoundException e) {

31

32 System.err.printf("Error: cannot read "

33 + "data from file %s" ,fileName);

34 System.exit(1);

35 }

36

37 while (inputFile.hasNextLine()) {

38 System.out.println( inputFile.nextLine() );

39 }

40 inputFile.close();

41 }

42

43 }

44


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp