Lab Test 1
In your week 3 lab, you will take one of the five tests below.
Lab Test 1, Version A
No Materials permitted. Questions:- This Question has four parts:
- Using Eclipse, create a new mercurial repository called labtest1 in your home directory.
- Create a new Eclipse project called Lab Test 1 that is within the mercurial repository you just created.
- Within the project created above, create a class Hello that has a main method that prints: "Hello World!".
- Put your class under version control (by "Add"ing it), and commit your changes.
- Write a program 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. (3 Marks)
- Write a program that reads an integer (n) from the console and then prints all the even numbers between 1 and n. (2 Marks)
- Write a program that reads an integer (n) from the console and then prints all the prime numbers between 1 and n. (2 Marks)
Lab Test 1, Version B
No Materials permitted. Questions:- This Question has four parts:
- Using Eclipse, create a new mercurial repository called labtest1 in your home directory.
- Create a new Eclipse project called Lab Test 1 that is within the mercurial repository you just created.
- Within the project created above, create a class Hello that has a main method that prints: "Hello World!".
- Put your class under version control (by "Add"ing it), and commit your changes.
- Write a program 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. (3 Marks)
- Write a program 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). (2 Marks)
- Write a program that reads in two strings from the console then determines whether the characters of one string are some permutation of the character 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). (2 Marks)
Lab Test 1, Version C
No Materials permitted. Questions:- This Question has four parts:
- Using Eclipse, create a new mercurial repository called labtest1 in your home directory.
- Create a new Eclipse project called Lab Test 1 that is within the mercurial repository you just created.
- Within the project created above, create a class Hello that has a main method that prints: "Hello World!".
- Put your class under version control (by "Add"ing it), and commit your changes.
- Write a program 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!. (3 Marks)
- Write a program 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'. (2 Marks)
- Write a program in Java 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. (2 Marks)
Lab Test 1, Version D
No Materials permitted. Questions:- This Question has four parts:
- Using Eclipse, create a new mercurial repository called labtest1 in your home directory.
- Create a new Eclipse project called Lab Test 1 that is within the mercurial repository you just created.
- Within the project created above, create a class Hello that has a main method that prints: "Hello World!".
- Put your class under version control (by "Add"ing it), and commit your changes.
- Write a program 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. (3 Marks)
- Write a program 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). (2 Marks)
- Write a program 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. (2 Marks)
Lab Test 1, Version E
No Materials permitted. Questions:- This Question has four parts:
- Using Eclipse, create a new mercurial repository called labtest1 in your home directory.
- Create a new Eclipse project called Lab Test 1 that is within the mercurial repository you just created.
- Within the project created above, create a class Hello that has a main method that prints: "Hello World!".
- Put your class under version control (by "Add"ing it), and commit your changes.
- Create an array of Strings that has the names of the songs you like. Print the elements of the array on separate lines (you do not need to use a loop for this, just use fixed indices into the array). (3 Marks)
- Using a while loop, write a program that prints (on separate lines) the numbers between and including 10 and 30 in reverse order. i.e. the program should print on separate lines: 30 29 28 ... 10. (2 Marks)
- Write a program that draws circles using ASCII characters and
standard output. The program should read in from the console an
integer, dia, which represents the diameter (in characters) of the
circle. Use the * character as the edge of the circle. For
simplicity you may assume that the terminal outputs characters which
are the same size and have equal height and width.
For example, for an input of 6, the output might look like this:
**** * * * * * * * * ****
(2 Marks)
