Giter VIP home page Giter VIP logo

uwjavatest's Introduction

Greetings!

This exercise is designed to test your ability to compile Java programs, modifying Java source code as necessary to make that happen.

Your task is simple: Make the code compile, and make all the unit tests pass. You may not change the tests that already exist in the files in the "src/test" subdirectories; you will also be asked to add a few tests, as well.

To do that...

... you must first obtain a copy of the source. Do that by cloning this repository:

git clone https://bitbucket.org/TedNeward/uwjavatest uwjavatest

This will create a local copy of the project. However, in order to store your changes to your own GitHub account, you need to create a new repository on GitHub (call it uwjavatest again), and then change the project's settings to point to that new repository as the remote origin.

git remote set-url origin https://github.com/[your-ID]/uwjavatest.git

This will work regardless of whether you got the syntax of the URL correct or not, so do a quick push to make sure it all worked correctly:

git push

Git will ask you for your username and password, then (if everything was done correctly), it will upload the code to the new repository, and this is your new "home" for this project going forward. Verify the files are there by viewing your GitHub project through the browser.

NOTE: Your grade for this assignment (and all future assignments) will be based on what we see in the GitHub repository, and nothing else. If it isn't in GitHub, it doesn't exist.

Now, you can begin to work on the homework code.

To do that...

... you must make the code compile. To do that, we will use a build system that is popular in the Java world, called "Gradle". It will likely require you to install some stuff on your machine.

To install Gradle...

... visit the Gradle website. The Downloads page has some details on how to install on to your machine of choice.

Note that if you have a Mac, this is much easier; install Homebrew, and once that's done, issue "brew install gradle" at the command-line. You will need to have Java installed on your Mac already, which may require a download from Oracle to do so. (Or, you can use Homebrew again, if you feel comfortable doing so: brew update && brew cask install java.)

The reason we are using Gradle is because this is the build system used internally inside Android Studio (at least for now). Understanding a little of how it works will be helpful when working with your own Android projects later.

To build the code once Gradle is installed...

... you will need to open a Terminal window to the directory in which you cloned this code (if you haven't already). Then, issue "gradle build" to compile the code, or "gradle test" to build the code and run the tests.

If you prefer GUIs, run "gradle --gui" and a nice little window will pop up.

Check the test results

When Gradle is done with the build, if you asked it to run the tests, it will do so and dump the results in a nicely-formatted HTML file in "build/reports/tests". Open the "index.html" file in that directory with your browser of choice (or, if you're on a Mac, from the command-line do "open build/reports/tests/index.html"; on Windows, "start build/reports/tests/index.html" and either will open the HTML file in the currently-selected default browser).

It will show you the summary of the test run, with breakdowns either by "Packages" or "Classes".

Your tasks

In no particular order, you will need to:

  • Create "getters" and "setters" on Person

  • Ensure that Person.setAge() throws an IllegalArgumentException when passed a value less than zero

  • Ensure that Person.setName() throws an IllegalArgumentException when passed a null String

  • Write a Person.count() that returns the total number of Person instances created

  • Ensure that Person.equals() returns true if two Person instances have the same name and age (salary doesn't factor into equality comparison). Make sure no exceptions are thrown from this method--anything "weird" should just return false.

  • Create an AgeComparator class that compares two Persons and arranges them by age (age 15 is less than age 25). This Comparator MUST BE a nested class inside of Person; Person's fields must remain private.

  • Make Person be Comparable, such that when I compare two Persons, they arrange themselves by salary in reverse order (salary 150000 is less than salary 10000). (Rich people to the front!)

  • Create a static method "getNewardFamily" that returns an ArrayList consisting of four Person objects: Ted, age 41, salary 250000; Charlotte, age 43, salary 150000; Michael, age 22, salary 10000; and Matthew, age 15, salary 0.

  • Lastly, you will need to implement a final test, marked in comments in the TestPerson class, which will register a "PropertyChangeListener" instance. This PropertyChangeListener will need to call the three "assertEquals" calls (as described in the comments) in order to test that the property did change. You shouldn't change anything above or below the comment lines beyond that.

... most of which will/should be obvious from looking at the tests. The test classes are in src/test/java/com/tedneward/example, and the source files that you will need to modify will be in src/main/java/com/tedneward/example.

Note: No Android Studio for this

This isn't just because I want you to get a little command-line exercise in; this is also because the Android Studio does not support plain ol' command-line Java application development.

If you really can't live without an IDE, JetBrains' IDEA would work, but you really need to be comfortable with writing code without the bells and whistles of an IDE, because the IDE won't always be there. (After this one, I promise, we're all IDE, all the way.)

Grading

This is pretty simple stuff; accordingly, this is kind of a pass/fail scenario. Get the tests to pass, full marks; don't get all the tests to pass, nada.

Questions

Fire away, to either me or the TA.

uwjavatest's People

Contributors

tedneward avatar

Watchers

James Cloos avatar Cooper Cain avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.