Design and development of significantly sized software using top-down design and bottom-up implementation. Dynamically allocated data, object-oriented programming, architecture of memory, basics of language translation, and basics of algorithm analysis. Development of simple graphical user interfaces. Prerequisite: CS 110 (grade of C or better).

Lab 1 - Getting started with Java and SVN - (50 points)



Due date: 2/5/2016 at 11:59pm

Objectives



  • Familiarize yourself with the Java syntax
  • Learn about version control through SVN
  • Familiarize yourself with basic command line operations

Calculator program (20 points)



  • Write a Java program (Calculator.java) that contains the Calculator class. In this program, you will take command line input from the user and print the result of the operation specified at the command line. The input for your program at the command line will look as follows:
    • Addition: java Calculator + 10 5
    • Subtraction: java Calculator - 10 5
    • Multiplication: java Calculator x 10 5 - Note that the multiplication symbol (*) should not be used and instead a 'x' should be used.
    • Division : java Calculator / 10 5
  • In the Calculator class, you must check whether args[0] is a +, -, x, / and perform the operation accordingly. To compare the input argument with a +,-,x,/ symbol you could use the contains() method in the String class as follows :

    args[0].contains((CharSequence) "+")

    The contains() method returns a boolean (true/false) and can be used as the condition for an if statement.
  • The input command line arguments are all strings and int number = Integer.valueOf(inputString); can be used to convert an input String into an integer.
  • Using the input numbers from args[1] and args[2], perform the appropriate operation (addition/subtraction/mutliplication/division) as specified by the user and display the result on the screen. For example, the output for addition would look like this The result of 10 + 5 = 15

Car class and driver (20 points)



  • Create a Car class that contains the name/make of a car, the year it was manufactured, the manufacturer, and the current number of miles on the car
    • Make sure to define the right data attributes
    • Create the getters and setters for EVERY data attribute
    • Create the toString() method for the class
  • Create a CarDriver class that contains at least three Car objects
  • Make sure that for each object, you call at least two methods from the Car class (any of the getters/setters/toString are fine).
  • When you run the CarDriver program, it should print the information for each Car object.

SVN Repository



For lab and project submissions, we will use the SVN tool. You can refer to the SVN commands. Create a cs112 directory in your SVN repository, using the terminal and type

svn mkdir https://www.cs.usfca.edu/svn/< your username>/cs112 -m "create cs112"

Submitting the lab using SVN (10 points)



  1. In addition to the java files, we would like to create a text file named README. This file should contain your name, your student id, and a few comments about the lab. In the README, you should write the names of the students you worked with, any other resources you used, any challenges, you faced, and anything interesting you would like to share with the TA and me.
  2. Open the terminal and go to the directory (use cd) that contains your Calculator.java, Car.java, CarDriver.java, README file.
  3. At the terminal, type svn co https://www.cs.usfca.edu/svn/yourusername.You will be asked your password and will see some output on your screen.
  4. Type cd yourusername and go to that directory. In that directory you will find another directory "cs112". Go into that directory by typing "cd cs112".
  5. Create a new directory there called lab1. Copy your Calculator.java, Car.java, CarDriver.java, and README files from your original directory to the lab1 directory (Use the cp command).
  6. Now, navigate out of the lab1 directory by typing cd .. and type svn add lab1. You will be asked some questions to which you can say 'yes' and should see some output as follows.
  7. apjoshi@hrn23501:lab1$ svn add lab1
    A         lab1
    A         lab1/Calculator.java
    A         lab1/Car.java
    A         lab1/CarDriver.java
    A         lab1/README
    					
  8. After adding the files, do NOT forget to commit the files by typing svn commit * -m "Committing files for Lab 1" or some such message. The output should look as follows:
  9. Adding         lab1
    Adding         lab1/Calculator.java
    Adding         lab1/Car.java
    Adding         lab1/CarDriver.java
    Adding         lab1/README
    Transmitting file data ....
    Committed revision 26.
    					
    Note: Your revision number may vary.

  10. Remember that you have to ADD ONCE (step 5), but COMMIT FREQUENTLY (step 6). Subsequent commits create a new version of your lab, and we will only grade the one that is closest to to 11:59pm on the due date.
  11. Make sure to verify that your files are submitted by opening a web browser and pasting the URL - https://www.cs.usfca.edu/svn/username/cs112/lab1. You should see all the files that you 'committed' for lab 1.