Skip navigation
The Australian National University

Lab Test 1

In your week 3 lab, you will take one of the four tests below, selected at random by your tutor.

You must use mercurial. Since you will start with an empty environment and will not have a network connection, you must first create a mercurial repository and then throughout the rest of the lab test you will commit your work to that repository, within an Eclipse project called Lab Test 1. I have created a video that shows you how to do this.

Lab Test 1, Version A

No Materials permitted.

Questions:
  1. This Question has four parts:
    • Using Eclipse, create a new mercurial repository called labtest1 locally (in your home directory).
    • Create a new Eclipse project called Lab Test 1, whose location is the labtest1 repository you just created (not 'default location').
    • Within the Lab Test 1 project created above, create a class Hello that has a main method that prints: "Hello World!".
    • Place your new class under version control (by "Add"ing it), and commit your changes.
    Use the project Lab Test 1 created in this question for the remaining questions. (3 Marks)
  2. Within the Lab Test 1 project, create a class ShoeSize, that will estimate your shoe size by reading in your height (in meters) from the console, multiplying by 5.0 and rounding it to the nearest integer. Add, commit, and push your work. (3 Marks)
  3. Within the Lab Test 1 project, create a class Even that reads an integer (n) from the console and then prints all the even numbers between 1 and n. Add, commit, and push your work. (2 Marks)
  4. Within the Lab Test 1 project, create a class Prime that reads an integer (n) from the console and then prints all the prime numbers between 1 and n. Add, commit, and push your work. (2 Marks)

Lab Test 1, Version B

No Materials permitted.

Questions:
  1. This Question has four parts:
    • Using Eclipse, create a new mercurial repository called labtest1 locally (in your home directory).
    • Create a new Eclipse project called Lab Test 1, whose location is the labtest1 repository you just created (not 'default location').
    • Within the Lab Test 1 project created above, create a class Hello that has a main method that prints: "Hello World!".
    • Place your new class under version control (by "Add"ing it), and commit your changes.
    Use the project Lab Test 1 created in this question for the remaining questions. (3 Marks)
  2. Within the Lab Test 1 project, create a class Square that declares and initializes an integer variable side. The variable side holds the length of the side of a square. Use this variable to calculate and print the area of the square. Add, commit, and push your work. (3 Marks)
  3. Within the Lab Test 1 project, create a class Movie that reads in the name of a movie (stored in a String called name), and its length in minutes (stored in an int called length) from the console. The program must print the name of the film and its length in hours and minutes. e.g. if the inputs are Finding Nemo and 104, then the program would output Finding Nemo runs for 1 hour and 44 minutes. (Hint - use the % operator). Add, commit, and push your work. (2 Marks)
  4. Within the Lab Test 1 project, create a class Permute that reads in two strings from the console then determines whether the characters of one string are some permutation of the characters of another string (a permutation is a strict reordering, no additions, no deletions). So for example cats is a permutation of acst, whereas, neither cats nor catt are permutations of cate. (Hint - use .length to find the length of a String and the charAt() method to get the character at a given position in a String). Add, commit, and push your work. (2 Marks)

Lab Test 1, Version C

No Materials permitted.

Questions:
  1. This Question has four parts:
    • Using Eclipse, create a new mercurial repository called labtest1 locally (in your home directory).
    • Create a new Eclipse project called Lab Test 1, whose location is the labtest1 repository you just created (not 'default location').
    • Within the Lab Test 1 project created above, create a class Hello that has a main method that prints: "Hello World!".
    • Place your new class under version control (by "Add"ing it), and commit your changes.
    Use the project Lab Test 1 created in this question for the remaining questions. (3 Marks)
  2. Within the Lab Test 1 project, create a class Greet that reads in from the console a string, name and then outputs a greeting which includes the name. e.g. If the input is Hugh then your output could be Hi Hugh!. Add and push your work. (3 Marks)
  3. Within the Lab Test 1 project, create a class Mark that reads a mark for a subject from the console, stores the mark as a variable called mark, and then prints the final grade based on this mark. Assume final grades are calculated using the following: marks between and including 0 and 49 will given a grade of 'N', 50 and 59 will give 'P', 60 and 69 will give 'C', 70 and 79 will give 'D', and finally 80 and 100 will give 'HD'. Add and push your work. (2 Marks)
  4. Within the Lab Test 1 project, create a class Ones that reads from the console an integer, called value and determines the number of '1's in the underlining bit pattern representation. This program should work with negative numbers. e.g. The integer 5 has 2 '1's its binary representation. Add and push your work. (2 Marks)

Lab Test 1, Version D

No Materials permitted.

Questions:
  1. This Question has four parts:
    • Using Eclipse, create a new mercurial repository called labtest1 locally (in your home directory).
    • Create a new Eclipse project called Lab Test 1, whose location is the labtest1 repository you just created (not 'default location').
    • Within the Lab Test 1 project created above, create a class Hello that has a main method that prints: "Hello World!".
    • Place your new class under version control (by "Add"ing it), and commit your changes.
    Use the project Lab Test 1 created in this question for the remaining questions. (3 Marks)
  2. Within the Lab Test 1 project, create a class Name that reads in your name from the console to a String variable called name. Print out your name in upper case using the toUpperCase() method of String. Also print out the number of characters in your name. e.g. if your name is Bill the program should print out BILL on one line and 4 on the next. Add, commit, and push your work. (3 Marks)
  3. Within the Lab Test 1 project, create a class Even that reads an integer from the console into a variable called value, and then determines whether value is even. The program will either print X is even or X is not even. This program must use a method with the signature public static boolean isEven(int i). Add and push your work. (2 Marks)
  4. Within the Lab Test 1 project, create a class Bases that is able to convert numbers between different bases (for simplicity we restrict the possible bases to 2, 3, 4, ... , 10). The program should read in three variables from the console; an integer sourceBase, the source base, an integer destbase, the destination base, and a String, value. The program should interpret the value as a number in source base and output it as a number in destination base (using the source and destination base number system). e.g. Say your source base was 3 and the destination base was 5. Then if 21 was entered, then 12 should be printed. You do not need to handle negative numbers. Add and push your work. (2 Marks)

Updated:  26 July 2013 / Responsible Officer:   JavaScript must be enabled to display this email address. / Page Contact:   JavaScript must be enabled to display this email address.