Starting from:

$29.99

COMP90041 Lab 4 Solution


In this tutorial, you will be introduced to the basics of Git and on how to host your projects online on GitHub. This knowledge will be crucial for your assignments and final project so please follow this guide closely What is Git?
Git is a version control software, which means it lets you create snapshots of your work. Think about a Word document, for example. Every time you save, it overwrites the previously saved, complete file. With version control, you only save the changes between two versions, thus making it easier for you to go back to a previous version. This is extremely useful on any software development project. When working as a team, Git “keeps track of every modification to the code in a special kind of database. If a mistake is made, developers can turn back the clock and compare earlier versions of the code to help fix the mistake while minimizing disruption to all team members” . While all of this is great, teams now need to collaborate by sharing the code, and this is where GitHub shines.
GitHub is a service that lets developers use version control online, enabling us to have an online space (repository) that holds all our code. Every time you save your code you must create a new commit (adding the changes to the files). After committing you can push changes to your online repository and share it with your team. Even if you work alone it can be used as an online backup of your project.
For this workshop, you will create a new repository, commit, and push code from GitHub. Excited? Then follow these steps:
• First, you must go and create an account on https://github.com/ using your unimelb email. If you already have an account you can add your unimelb email by following the steps outlined here: http://go.unimelb.edu.au/o37j.

https://classroom.github.com/a/e-8-q50-



● Accept the assignment and your repository is ready!


● Click on your repository URL and you will be in your own online space to store your code. ● Note that your repository is pre-filled with the following files:
○ .gitignore > lists files and file types that should not be committed
○ README.md > task description
○ Temperatures.java > skeleton code. Here is where you write your program.
○ oputput.txt > test output for you to locally test
○ temperatures.txt > test input for you to locally test



● Click on the Temperatures.java file

● Try to edit the output string and commit your changes:

● Now your Temperatures.java is updated and has been committed.
● You can check your history of commits.

● Next, we are going to connect this repository to a local folder on your computer (This process is called Clone a Repository). For this, we are using GitHub Desktop (But you can any tool you prefer, including command-line tools).
● You will need to download and install the following software on your computer: GitHub Desktop (https://desktop.github.com/) ● Sign in with your GitHub credentials.



● After cloning you can go to the local path in your computer and find the files from your repo.
● Open this folder in your favourite text editor and add a new comment: // This line is added on my local computer!



• You can also use your IDE, say Eclipse, to create a project from your local repository by choosing File Open Projects from File System and following all the instructions. After that, you can modify the code like what you normally do for your previously created projects.







● Save the file and go back to GitHub Desktop, you should be able to see the new changes in the Readme file highlighted in green.

● Do not forget to add a message and click on Commit to master. This records the changes in version control on your local machine. To make this change available online in your repository click on Push origin.
● You can now go to your repository in GitHub.com and check that your Temperatures.java file is updated with the extra line.

Congratulations! Welcome to the wonderful world of version control! Now let’s code…

Exercise 1a: Histogram of temperatures


Histogram of Temperatures
--------------------------


Exercise 1b: Testing locally: Input and Output Redirection
You will be given a sample test input file temperatures.txt and the corresponding sample output file output.txt. When you run your program by the following command in a terminal (or Windows command line):

java Temperatures < temperatures.txt > my-output.txt

your program should produce a file name my-output.txt, which should be exactly the same as output.txt. In this command, “< temperatures.txt” and “> my-output.txt” are called “input redirection” and “output redirection.” They use the content in temperatures.txt as the command line input, and print the program output into my-output.txt.

To do input redirection and output redirection on your IDE, say Eclipse, you just need to update the configurations Common. Specifically, you need to select the input file path (for input redirection) and output file path (for output redirection) as shown in the figure below.




To check your output (my-output.txt) and the provided one (output.txt) are exactly the same, you can use some diffing tools (e.g., “diff” command for Mac or Linux). Fortunately, Eclipse has a built-in feature for that. You just need to select two files you want to compare, and right click then select Compare With Each Other. As shown in the figure below, Eclipse will open two panels side by side and highlight the differences between the two files. You can look at the differences and make changes to your code accordingly to get correct output.


Exercise 1c: Submission
Once your program produces the correct output on your local machine, go ahead and submit your projects via GitHub.

You should always test your code locally on your machine before pushing it into your repository. Once you are confident that your program compiles correctly you can commit your changes and push your code to your repository.

Note this exercise is for practice purpose only. It will NOT be marked.



Exercise 2: Traffic Infringements

Condition Message(s)


65 to <= 70 $5 fine for each km/hr over 60 km/hr

65 to <= 70 and drunk $7 fine for each km/hr over 60 km/hr + Take a shower

> 70 $10 fine for each km/hr over 60 km/hr

> 70 and drunk $15 fine for each km/hr over 60 km/hr
Spend the day/night in cell until you sober up


The program should ask the traffic officer to type in the km/hr speed of the offending driver. It should then ask whether driver is drunk or not. (The officer answers with a ‘y’ or ‘n’ and the appropriate message is then given.) The program should then display the appropriate message and where any fine is applicable, the program should compute and display the fine.

NOTE: You are not required to submit Exercise 2 via GitHub.

Sample Run 1
Please enter speed: 64
Is the driver drunk? ('Y' for drunk, 'N' otherwise): N

****************************************************

---------------------------------------------------- You have a fine of $0.0
****************************************************

Sample Run 2

Please enter speed: 64
Is the driver drunk? ('Y' for drunk, 'N' otherwise): Y

****************************************************

---------------------------------------------------- You have a fine of $0.0
****************************************************

Sample Run 3
Please enter speed: 85
Is the driver drunk? ('Y' for drunk, 'N' otherwise): Y

****************************************************
$15.0 fine for each km/hr over 60 km/hr

Spend the day/night in cell until become sober.

---------------------------------------------------- You have a fine of $375.0
****************************************************

More products