CMSC 280 -- Lab 1

Lab 1

Getting Started

Log into the computer science server and use wget and tar to download your starter code.
  1. Use wget to download the file at http://cs.longwood.edu/courses/cmsc280/f18/files/lab1.tgz
  2. Uncompress the lab1.tgz file by using tar -xvzf lab1.tgz

The Problem

Several students at Poedunk University have consumed too much root beer and are wandering the streets of Nowheresburgh city. A student travels exactly one city block (in a random direction) every minute. The streets of Nowheresburgh are in a perfect grid. We are going to write a program to track the students’ travels.

You will need to write the following classes:

Coord -- a Coord stores two integers x and y
  1. public static Coord random()
    • input: none
    • output: one of the following Coords (-1,0) (0,-1) (1,0) (0,1)
  2. void add(Coord c)
    • input: a Coord object
    • output: none -- adds c to the object that called this funtion
  3. void inLimits(Coord c)
    • input: a Coord object
    • output: none -- caps the object that called this function to the bounds in given in c
  4. String toString()
    • input: none
    • output: a String representation of a Coord
Student -- a Student stores a Coord and the number of encounters with other students
  1. void step(Coord bounds)
    • input: a Coord storing the bounds of the city
    • output: none -- simulates the student taking one step
  2. String toString()
    • input: none
    • output: a String representation of a student
WanderingStudents -- the main class
  1. void simulate(int steps)
    • input: the number of steps to simulate
    • output: none
  2. toString
    • input: none
    • output: a String representation of the map and all students
  3. public static void main(String[] args)

Your program will read in three integers: the number of blocks, the number of steps, and the number of students.

The blocks variable will be used to determine the number of city blocks in Nowheresburgh. Our students will start in the middle of the city.

The steps variable describes how many minutes your program should simulate.

You will need to keep track of where the students are currently in the city and how many times they have visited each spot in the city. A student can’t leave the city limits, any direction which leaves the bounds will be ignored. The students will need to keep track of how many times they encounter a fellow student.

Remember, you will be graded on style, syntax, functionality, and correctness. Since our lab uses random numbers you will not need test cases.

You must use a Makefile. Please remember to submit a README.txt

This is not your friend’s work. This is not the internet’s work. This is your work...

Examples

 .  .  .  .  .  2  8  5  2  1  5  4  1  .  .  . 
 .  .  .  .  .  1  5  4  2  4  1  .  .  .  .  . 
 .  .  .  .  1  1  4  5  6  8  1  1  .  .  .  . 
 .  .  .  .  1  1  5 12  9  8  4  4  3  .  .  . 
 1  3  4  .  .  1  3  9  5  3  5  5  3  .  .  . 
 .  3  6  .  .  1  8 14  8  7  9  6  3  .  .  . 
 .  2  4  3  2  7 11 17 12 12 14 15  8  3  1  . 
 .  1  4  7  4  7  9 12 14 16 14 17 16 12  5  5 
 .  1  2  4  4  7 10 13 17 21 15 14 13  6  7  9 
 .  1  3  6  3  7  6 11 17 13 13 15 11  8 12  9 
 .  .  1  3  3  6  6 18 12  6  7  9 11 12 17 16 
 .  .  .  .  3  5  5 12  6  9  6  7 13 12 27 31 
 .  .  .  .  1  3  4  5  2  7 10 10 10  3 13 15 
 .  .  .  .  .  1  1  2  6  4 12  9  5  4 11  9 
 .  .  1  2  1  .  2  1  5  4  7  3  2  4  5  8 
 .  .  2  1  1  1  5  3  4  .  .  .  1  5  4 10 

{12,3}	7
{8,2}	4
{11,0}	6
{1,6}	10
{3,14}	11
 3  5  7 10 11  3  1  3  5  5 10 11  5  2  4  5 
 .  1  2  2  2  .  1  3  5  4 11  6  7  4  2  2 
 .  .  1  4  4  .  1  5  7  9 15 12 10  4  .  1 
 .  .  2  1  3  2  1  6  7  9  8  7  8  3  1  1 
 .  .  1  .  1  4  3  4  4  7  9  9 13  7  .  . 
 .  .  1  1  .  7  7  6  2  6  7  4  6  6  2  . 
 .  .  .  1  1  3  4  5  .  5  5  5  4  3  1  . 
 1  1  .  3  3  1  7  8  6 10  8  7  4  2  2  . 
 6  5  5  6  7  5 11  7  5  6  2  2  3  4  7  4 
 8  5  4  5  7  4  4  3 12  8  8  4  5  6 11 11 
 6  8  5  5  5  3  2  2 10  9 10  3  3  4  7  6 
 8  5  1  3  7  8  4  6  8  3  3  4  5  9  8  4 
 3  1  .  1  7  8  2  4  3  2  8  8  9 11  9  7 
 .  .  .  2  6  9  7  3  3  3  8  9 11 15 14 11 
 .  .  .  .  .  1  7  7  2  3 10 15 20 17 13 19 
 .  .  .  .  .  2  7 12  6  2  5  9 23 19  7  5 

{12,11}	11
{13,4}	10
{10,1}	6
{2,0}	7
{14,0}	16
11  8  4 11 14  8  7 13 11 10  7  1  .  .  .  . 
 5  6 10 15  8  2  4  8 10  8 15  6  1  .  .  . 
10  6  6 12 10  3  4  7 12  8 11  3  3  1  .  . 
 8  4  5 10  8 12 13 10 13  8  8  5  2  2  1  1 
 7  5  6  5  3  7  9 12 12  9  7  6  5  2  .  . 
 7  5 10 10  8  7  8  6  3  3  7  3  3  2  3  2 
 9  2  8 11 12  5  5  4  5  2  7  6  3  1  2  . 
 6  .  5  7  8  6  3  4 10  5  2  4  3  4  7  7 
 5  6  7  3  5  9  4  5 12  5  2  3  3  6  2  2 
 3  5  4  3  5  9  6  5 10  4  7  7 12  7  3  2 
 .  1  .  2  4 10 10  6  6  2  8 12 11  4  3  3 
 .  .  .  4  9 12 11  3  4  3  4  7  5  5  3  1 
 .  .  .  .  3  6  7  6  4  1  3  8  9  4  1  1 
 .  .  .  .  2  2  3  3  3  2  4  7 10  6  4  2 
 .  .  .  .  .  .  1  2  7  6 10 10  7  2  3  . 
 .  .  .  .  .  .  .  1  6  2  8  3  1  1  1  . 

{3,10}	18
{15,3}	20
{0,5}	17
{3,11}	12
{8,15}	1


Handin

When you are done you may hand in your lab by using make handin.

The lab is due at 11:59pm Sept. 21st 2018.