×
CS每周1个project有感:美国读一般的大学也不容易

这大学录取率是80%以上,Introduction to Object-Oriented Programming 学到这里才2个多月,还有一个月就结束了。最近大约1周一个project,真心不容易!看最近的一个要求

 

This problem set has two parts.  In the first part, you will be implementing part of a simple database for geocaches.  In the second part, you will be implementing a class reminiscent of Java's Scanner class.

Part 1

Geocaches

For the purposes of this assignment you do not need to know what geocaches are, but it can't hurt.  Geocaches are containers of various sizes that are hidden throughout the world.  Geocachers (such as me) are people who enjoy looking for geocaches. There is a free geocaching app available for smart phones.  There is also a website, https://www.geocaching.com/play/search, (Links to an external site.)Links to an external site. that we use to learn about geocaches in our area.  For example, there are more than 200 geocaches within two miles of MEB. 

Every geocache at geocaching.com has (among other things) a title, an owner, the GPS coordinates where it is located, a difficulty rating that describes how difficult the geocache is to find, and a terrain rating that describes how hard it is to travel to the hiding place. 

My geocaching name is "lesdubois", and I specialize in hiding "puzzle" caches.  To get the GPS coordinates of a puzzle cache, you have to first solve a puzzle.  To solve one of my puzzles, Digital Dilemma 2 (Links to an external site.)Links to an external site., the geocacher needs to write some simple computer programs.  If you're interested, the programs required are the right difficulty for CS 1410 students.

But I digress.

Getting Started

You will be completing the implementation of a program that I have started.  Your job will be to provide correct implementations and unit tests for two classes: Cache and CacheList.

Begin by running PS7Demo.jar.  Use the file chooser that pops up to navigate to and open the file caches.txt, which contains a list of geocaches.  (The list is a few years old, so some of the geocaches it contains no longer exist.)  The program will then open an application that lets you search through the contents of caches.txt.  When you have completed this assignment, your program should behave just like the demo program you have just run.

The four source files define five classes: Cache, CacheList, GeocacheBrowser, CacheTests, and  CacheListTests.  You should not modify GeocacheBrowser.  Unless you are curious, you do not need to understand it or even look at it.

GeocacheBrowser contains a main method.  Run it, and it will bring up the same application as the jar file.  Most everything will be blank, however, until you complete Cache and CacheList.

The application uses Cache objects (implemented by your Cache class) to represent individual geocaches.  It uses a CacheList object (implemented by your CacheList class) to keep track of, filter, and sort all the Cache objects.

Please read and follow the directions carefully.

Cache Class

The Cache class provides objects that represent information about a single geocache.  The class file contains complete specifications as well as a completed implementation for the toString method.  You should

  1. Read carefully through the entire class file.
     
  2. Create a complete set of unit tests for the Cache class.  I have created a test class called CacheTests that contains a sample test.  You should add your tests to this class.  The TAs and I will not help you with your Cache class implementation until you have completed this step!

    The key to testing class implementations is to realize that it is not usually possible to test each constructor and method in isolation.  For example, to test the getOwner() method of the Cache class, you must first use the constructor to create a Cache object.  

     
  3. Design a representation and then declare and document your instance variables.
     
  4. Implement the constructor.  Each line of the file caches.txt is an example of a string that the constructor should be able to take as a parameter.  (Hint:  Use the String split method.)
     
  5. Implement the methods (other than toString, which is already complete).
     
  6. Test/debug/modify your Cache and CacheTests classes until you are certain that the Cache class behaves according to its specifications.
     

CacheList Class

The CacheList class provides objects that represent collections of Caches as well as constraints on them.  The class file contains complete specifications as well as a partial implementation.  You should

  1. Read carefully through the entire class file.
     
  2. Create a complete set of unit tests for for the CacheList class.  I have created a test class called CacheListTests that contains a sample test.  You should add your tests to this class.  The TAs and I will not help you with your CacheList class implementation until you have completed this step!

    Keep in mind that it is not usually possible to test each constructor and method in isolation.  For example, to test the setTitleConstraint() method of the CacheList class, you must use the constructor to create a CacheList object, use setTitleConstraint(), and then call the select() method to see if the title constraint has the proper effect.

     
  3. Design a representation and then declare and document your instance variables.  Please note that I have already provided a key part of the representation.
     
  4. Complete the implementation of the constructor.  The file caches.txt is an example of the kind of file that the constructor should be able to process.  Please note that I have included code that shows how to sort a list of Cache objects.
     
  5. Implement the methods.  Please note that the partial implementation of getOwners I have provided shows how to sort a list of Strings.
     
  6. Test/debug/modify your CacheList and CacheListTests classes until you are certain that the CacheList class behaves according to its specifications.
     

GeocacheBrowser

If you have correctly implemented Cache and CacheList, your GeocacheBrowser should behave identically to the example implementation.  If it doesn't, the problem is with either Cache or CacheList.

 

Part 2

MyScanner

In this part of the problem set, you are to design, implement, document, and test a class that provides objects that have a subset of the capabilities of Scanners.  Your class must:

  • Be called MyScanner and be in a package called scan
  • Provide a constructor that takes a String as a parameter
  • Provide four methods:
    1. hasNext(), which takes no parameters and returns a boolean
    2. next(), which takes no parameters and returns a String
    3. hasNextInt(), which takes no parameters and returns a boolean
    4. nextInt(), which takes no parameters and returns an int
  • Not use Scanner in its implementation!

A MyScanner should behave just like a Scanner would if you only used the Scanner's String constructor and its hasNext(), next(), hasNextInt(), and nextInt() methods.  Be sure that you understand exactly how Scanners behave, including the circumstances in which exceptions are thrown.  Don't simply assume you know how those methods interact.  For example, hasNextInt() doesn't report whether there is an integer token somewhere in the Scanner; it reports whether the next token can be parsed as an int by Integer.parseInt().  You should read the relevant parts of the Scanner documentation (Links to an external site.)Links to an external site. and (probably more importantly)  experiment with Scanners.

Since there is no close() method, none of the MyScanner methods should ever throw an IllegalStateException.  However, in the right circumstances some of the MyScanner methods should throw a java.util.NoSuchElement exception and/or a java.util.InputMismatchException.

Be sure to test your MyScanner class thoroughly.  Put your unit tests in a class MyScannerTests in the scan package.  If I were you, I would write thorough test cases for the Scanner class.  Then, when I was sure that my tests cases were correct and complete, I would do a global replace of "MyScanner" for "Scanner".  But that's just me.

Hint:  Here is a bit of code that decomposes a string into an array of tokens:

String[] tokens = s.trim().split("\\s+");

Here's how it works.  It first "trims" the string, which removes all leading and trailing white space.  It then splits the string into tokens.  The parameter that is passed to split says that tokens will be separated by one or more white space characters.

Submitting

Keep in mind that the CPM validator does not test or grade your program.  It only checks that you have named everything as specified.  Don't ignore validation errors, as they will make it difficult to grade your program.

Don't forget to submit your solution.  You can submit a solution as many times as you like, but we will only grade your most recent submission.

 

Rubric

P7 Rrubric
P7 Rrubric
Criteria Ratings Pts
Passes 20 tests in CacheGrader
 
 
 
20.0 pts
Full Marks
 
 
0.0 pts
No Marks
 
20.0 pts
Passes 20 tests in CacheListGrader
 
 
 
20.0 pts
Full Marks
 
 
0.0 pts
No Marks
 
20.0 pts
Passes 20 tests in MyScannerGrader
 
 
 
20.0 pts
Full marks
 
 
0.0 pts
No marks
 
20.0 pts
Instance variables are private
 
 
 
2.0 pts
All
 
 
1.0 pts
Some
 
 
0.0 pts
None
 
2.0 pts
Instance variables are non-static
 
 
 
2.0 pts
All
 
 
1.0 pts
Some
 
 
0.0 pts
None
 
2.0 pts
Instance variables are commented
 
 
 
2.0 pts
All
 
 
1.0 pts
Some
 
 
0.0 pts
None
 
2.0 pts
Comprehensive tests provided in CacheTests
 
 
 
4.0 pts
Yes
 
 
2.0 pts
Partially
 
 
0.0 pts
No tests
 
4.0 pts
Comprehensive tests provided in CacheListTests
 
 
 
10.0 pts
Yes
 
 
5.0 pts
Partially
 
 
0.0 pts
No tests
 
10.0 pts
Comprehensive tests provided in MyScannerTests
 
 
 
10.0 pts
Yes
 
 
5.0 pts
Partially
 
 
0.0 pts
No tests
 
10.0 pts
Student made an effort
 
 
 
10.0 pts
Yes
 
 
0.0 pts
No
 
10.0 pts
Total Points: 100.0

这大学录取率是80%以上,Introduction to Object-Oriented Programming 学到这里才2个多月,还有一个月就结束了。最近大约1周一个project,真心不容易!看最近的一个要求

 

This problem set has two parts.  In the first part, you will be implementing part of a simple database for geocaches.  In the second part, you will be implementing a class reminiscent of Java's Scanner class.

Part 1

Geocaches

For the purposes of this assignment you do not need to know what geocaches are, but it can't hurt.  Geocaches are containers of various sizes that are hidden throughout the world.  Geocachers (such as me) are people who enjoy looking for geocaches. There is a free geocaching app available for smart phones.  There is also a website, https://www.geocaching.com/play/search, (Links to an external site.)Links to an external site. that we use to learn about geocaches in our area.  For example, there are more than 200 geocaches within two miles of MEB. 

Every geocache at geocaching.com has (among other things) a title, an owner, the GPS coordinates where it is located, a difficulty rating that describes how difficult the geocache is to find, and a terrain rating that describes how hard it is to travel to the hiding place. 

My geocaching name is "lesdubois", and I specialize in hiding "puzzle" caches.  To get the GPS coordinates of a puzzle cache, you have to first solve a puzzle.  To solve one of my puzzles, Digital Dilemma 2 (Links to an external site.)Links to an external site., the geocacher needs to write some simple computer programs.  If you're interested, the programs required are the right difficulty for CS 1410 students.

But I digress.

Getting Started

You will be completing the implementation of a program that I have started.  Your job will be to provide correct implementations and unit tests for two classes: Cache and CacheList.

Begin by running PS7Demo.jar.  Use the file chooser that pops up to navigate to and open the file caches.txt, which contains a list of geocaches.  (The list is a few years old, so some of the geocaches it contains no longer exist.)  The program will then open an application that lets you search through the contents of caches.txt.  When you have completed this assignment, your program should behave just like the demo program you have just run.

The four source files define five classes: Cache, CacheList, GeocacheBrowser, CacheTests, and  CacheListTests.  You should not modify GeocacheBrowser.  Unless you are curious, you do not need to understand it or even look at it.

GeocacheBrowser contains a main method.  Run it, and it will bring up the same application as the jar file.  Most everything will be blank, however, until you complete Cache and CacheList.

The application uses Cache objects (implemented by your Cache class) to represent individual geocaches.  It uses a CacheList object (implemented by your CacheList class) to keep track of, filter, and sort all the Cache objects.

Please read and follow the directions carefully.

Cache Class

The Cache class provides objects that represent information about a single geocache.  The class file contains complete specifications as well as a completed implementation for the toString method.  You should

  1. Read carefully through the entire class file.
     
  2. Create a complete set of unit tests for the Cache class.  I have created a test class called CacheTests that contains a sample test.  You should add your tests to this class.  The TAs and I will not help you with your Cache class implementation until you have completed this step!

    The key to testing class implementations is to realize that it is not usually possible to test each constructor and method in isolation.  For example, to test the getOwner() method of the Cache class, you must first use the constructor to create a Cache object.  

     
  3. Design a representation and then declare and document your instance variables.
     
  4. Implement the constructor.  Each line of the file caches.txt is an example of a string that the constructor should be able to take as a parameter.  (Hint:  Use the String split method.)
     
  5. Implement the methods (other than toString, which is already complete).
     
  6. Test/debug/modify your Cache and CacheTests classes until you are certain that the Cache class behaves according to its specifications.
     

CacheList Class

The CacheList class provides objects that represent collections of Caches as well as constraints on them.  The class file contains complete specifications as well as a partial implementation.  You should

  1. Read carefully through the entire class file.
     
  2. Create a complete set of unit tests for for the CacheList class.  I have created a test class called CacheListTests that contains a sample test.  You should add your tests to this class.  The TAs and I will not help you with your CacheList class implementation until you have completed this step!

    Keep in mind that it is not usually possible to test each constructor and method in isolation.  For example, to test the setTitleConstraint() method of the CacheList class, you must use the constructor to create a CacheList object, use setTitleConstraint(), and then call the select() method to see if the title constraint has the proper effect.

     
  3. Design a representation and then declare and document your instance variables.  Please note that I have already provided a key part of the representation.
     
  4. Complete the implementation of the constructor.  The file caches.txt is an example of the kind of file that the constructor should be able to process.  Please note that I have included code that shows how to sort a list of Cache objects.
     
  5. Implement the methods.  Please note that the partial implementation of getOwners I have provided shows how to sort a list of Strings.
     
  6. Test/debug/modify your CacheList and CacheListTests classes until you are certain that the CacheList class behaves according to its specifications.
     

GeocacheBrowser

If you have correctly implemented Cache and CacheList, your GeocacheBrowser should behave identically to the example implementation.  If it doesn't, the problem is with either Cache or CacheList.

 

Part 2

MyScanner

In this part of the problem set, you are to design, implement, document, and test a class that provides objects that have a subset of the capabilities of Scanners.  Your class must:

  • Be called MyScanner and be in a package called scan
  • Provide a constructor that takes a String as a parameter
  • Provide four methods:
    1. hasNext(), which takes no parameters and returns a boolean
    2. next(), which takes no parameters and returns a String
    3. hasNextInt(), which takes no parameters and returns a boolean
    4. nextInt(), which takes no parameters and returns an int
  • Not use Scanner in its implementation!

A MyScanner should behave just like a Scanner would if you only used the Scanner's String constructor and its hasNext(), next(), hasNextInt(), and nextInt() methods.  Be sure that you understand exactly how Scanners behave, including the circumstances in which exceptions are thrown.  Don't simply assume you know how those methods interact.  For example, hasNextInt() doesn't report whether there is an integer token somewhere in the Scanner; it reports whether the next token can be parsed as an int by Integer.parseInt().  You should read the relevant parts of the Scanner documentation (Links to an external site.)Links to an external site. and (probably more importantly)  experiment with Scanners.

Since there is no close() method, none of the MyScanner methods should ever throw an IllegalStateException.  However, in the right circumstances some of the MyScanner methods should throw a java.util.NoSuchElement exception and/or a java.util.InputMismatchException.

Be sure to test your MyScanner class thoroughly.  Put your unit tests in a class MyScannerTests in the scan package.  If I were you, I would write thorough test cases for the Scanner class.  Then, when I was sure that my tests cases were correct and complete, I would do a global replace of "MyScanner" for "Scanner".  But that's just me.

Hint:  Here is a bit of code that decomposes a string into an array of tokens:

String[] tokens = s.trim().split("\\s+");

Here's how it works.  It first "trims" the string, which removes all leading and trailing white space.  It then splits the string into tokens.  The parameter that is passed to split says that tokens will be separated by one or more white space characters.

Submitting

Keep in mind that the CPM validator does not test or grade your program.  It only checks that you have named everything as specified.  Don't ignore validation errors, as they will make it difficult to grade your program.

Don't forget to submit your solution.  You can submit a solution as many times as you like, but we will only grade your most recent submission.

 

Rubric

P7 Rrubric
P7 Rrubric
Criteria Ratings Pts
Passes 20 tests in CacheGrader
 
 
 
20.0 pts
Full Marks
 
 
0.0 pts
No Marks
 
20.0 pts
Passes 20 tests in CacheListGrader
 
 
 
20.0 pts
Full Marks
 
 
0.0 pts
No Marks
 
20.0 pts
Passes 20 tests in MyScannerGrader
 
 
 
20.0 pts
Full marks
 
 
0.0 pts
No marks
 
20.0 pts
Instance variables are private
 
 
 
2.0 pts
All
 
 
1.0 pts
Some
 
 
0.0 pts
None
 
2.0 pts
Instance variables are non-static
 
 
 
2.0 pts
All
 
 
1.0 pts
Some
 
 
0.0 pts
None
 
2.0 pts
Instance variables are commented
 
 
 
2.0 pts
All
 
 
1.0 pts
Some
 
 
0.0 pts
None
 
2.0 pts
Comprehensive tests provided in CacheTests
 
 
 
4.0 pts
Yes
 
 
2.0 pts
Partially
 
 
0.0 pts
No tests
 
4.0 pts
Comprehensive tests provided in CacheListTests
 
 
 
10.0 pts
Yes
 
 
5.0 pts
Partially
 
 
0.0 pts
No tests
 
10.0 pts
Comprehensive tests provided in MyScannerTests
 
 
 
10.0 pts
Yes
 
 
5.0 pts
Partially
 
 
0.0 pts
No tests
 
10.0 pts
Student made an effort
 
 
 
10.0 pts
Yes
 
 
0.0 pts
No
 
10.0 pts
Total Points: 100.0
Sign-up now to access all contents for free without interruption.

Also included is a 15-day free-trial of JumpStart Package™ with unlimited access college application tools and resources. No credit card necessary.