Starting from:

$30

CS1632-Exercise 0 Solved

The purpose of this exercise is to assess your Java programming skills coming

Another purpose of this exercise is to familiarize you with the workflow for
this course.  We are going to use GitHub for collaboration and source code
Please follow the below instructions.

## Install JDK 8

The official Java version for this class is Java 8 (1.8.0.231).  Please install the Java package for your OS at: 

https://drive.google.com/drive/folders/1E76H7y2nMsrdiBwJi0nwlzczAgTKKhv7

After installation, make sure you have the correct Java and Javac versions by doing "java
-version" and "javac -version".  You should get something like the following:

```
$ java -version
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)
```

Alternatively, you can use these versions of OpenJDK 8 that have been verified to work with our tool chain:
* https://chocolatey.org/packages/openjdk8
* https://chocolatey.org/packages/zulu8

After installing, they should show their respective versions on "java -version".  For example, for zulu8:
```
$ java -version
openjdk version "1.8.0_265"
OpenJDK Runtime Environment (Zulu 8.48.0.53-CA-win64) (build 1.8.0_265-b11)
OpenJDK 64-Bit Server VM (Zulu 8.48.0.53-CA-win64) (build 25.265-b11, mixed mode)
```

If you don't see the correct version (either for JDK 8, OpenJDK 8, or Zulu 8), please follow the below instructions to
set up the Path OS environment variable.

### Setting up JDK 8 for Windows

1. Search "environment" in the Windows 10 search box.
2. Open "Edit the system environment variables" control panel.
3. Click on the "Environment Variables" box.
4. Search the "Path" environment variable in user variables and system variables.
5. Add the bin directory of the Java installation, probably "C:\Program Files\Java\jdk1.8.0_231\bin" to the top of the "Path"
6. For good measure, you may want to remove other Java installations from the "Path"
7. After this, try doing "java -version" again and it should have changed.

If you use [Chocolatey](https://chocolatey.org/) as your package manager, and you opted to install OpenJDK 8, you will have to replace the above Java bin path with the path where Chocolatey installs the package.

### Setting up JDK 8 for MacOS

1. Open ~/.bash_profile with your favorite editor (if you don't have one, just do "pico ~/.bash_profile")
2. Add the following 2 lines at the bottom
export PATH=/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/bin:$PATH
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/
3. Save the file and exit from the terminal
4. Relaunch the terminal and try doing "which java".  It should say /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/bin/java.
5. Now you are good to go!  Otherwise, try doing "echo $PATH" and see if your path is not updated properly, or if there is some other Java installation before you.

Alternatively, you can use [jEnv](https://www.jenv.be/) that allows you to switch Java versions easily on a Mac.  You will also need [Mac brew](https://brew.sh/) if you don't already have it.  These are just one liners to install so it should be pretty painless.

It's a brew installation so it should be pretty painless.

## Create GitHub Repository

For every source code submission in this class, you are asked to create a new
GitHub repository.  If you don't already have a GitHub account, please create
one.  

1. If you are new to git source versioning or GitHub, I recommend that you
start by using the Desktop GUI version.  You can download it from:


2. Once you've installed GitHub Desktop, let's first clone the course repository to your computer:

    

    You will need to go to the root of the course repository to get the clone link:

    
    This way, you will have always have up=to-date course materials on your
computer.  Whenever there are updates to the course materials, the "Pull"
request button will be activated for the repository on GitHub Desktop.  Clicking
that button will bring your local folder in sync with the updated materials.

3. Next, create a new repository just for this exercise:

    

    You can name it whatever you want (but preferably something easy to remember, right?).

    Once you've created the repository, copy over the contents of just the exercise
folder in the course repository to the new repository folder.  Once you've
copied over the files, you need to "Commit" and "Push" the files to upload
those files to GitHub.  If you are successful, you should be able to see your
new repository with the new files at github.com.

4. Whenever you make improvements to your source code, frequently "Commit" and
   "Push" those changes to GitHub so that your new changes are versioned.

## Compilation

Go to the new repository folder you created for this exercise and make sure that the Java file compiles:

```
$ mkdir bin
$ javac -d bin src/*.java 

```

You should see no errors at this point

## Running

Try running the compiled class file:

```
$ java -cp bin SortedCollection
Usage: java SortedCollection [num1] [num2] [num3] ...
```

The SortedCollection main method just prints usage information when no
commandline arguments are passed.  With commandline arguments, it should print
out the commandline arguments in sorted order, from smallest to largest:

```
$ java -cp bin SortedCollection 3 2 1
sorted: 1 2 3
```

But at the current state, SortedCollection is incomplete and prints out:

```
$ java -cp bin SortedCollection 3 2 1
sorted: 0 0 0
```

Your job is to complete SortedCollection so that it works properly.

## Completing SortedCollection.java

The places in source code where you are asked to insert or modify code are
marked by // TODO comments.  Feel free to use any data structure from java.util
or one of your own.  It doesn't matter how you implement it as long as it works
as specified.  Pay attention to the Javadoc comments on top of each method.

More products