Graderpractice for programmers

254275 OOP - Mini Test 1 (Sec 1, 2 & 5) 2562/2

Awaiting submission
Read in an integer, multiply it by 2 and print out the result.
Awaiting submission
Read in a string, count how many semi-colons (";") in the string and print out the result.

If the input is "a) apples; b) pears; c) bananas" then there are 2 semi-colons.

Awaiting submission
Read in 5 int numbers, calculate the average (mean) as a float and print out the result to 1 d.p.
Awaiting submission
Read in a line of integers, put it in an array and then count how many of the integers are divisible by 3 (e.g. count the 3s, 6s, 9s, 12s, ...).

If the input is 5 9 12 4 3 15 then the numbers divisible by 3 are 9 12 3 15 so the output is 4.

Starter code:
class D {
    public static void main(String[] args) {
        // Read line of ints into an array
        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" ");
        int[] numbers = new int[line.length];
        for (int i = 0; i < line.length; i++) {
            numbers[i] = Integer.parseInt(line[i]);
        }
		
        // TODO: print out how many of numbers are divisible by 3
    }
}
Awaiting submission
A pair of shoes have a name, a gender and a size. Complete the Shoe class by writing 3 methods:
  • getName returns the name of the shoe
  • getGender returns 'W' for womens and 'M' for mens
  • getSize returns the size of the shoe

Submit the Shoe.java file ONLY!

Template:
class Shoe {
    private String name;
    private char gender;
    private int size;

    public Shoe(String name, char gender, int size) {
        this.name = name;
        this.gender = gender;
        this.size = size;
    }
}
Test code:
class TestE {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String n = sc.nextLine();
        char g = sc.nextLine().charAt(0);
        int s = Integer.parseInt(sc.nextLine());
        Shoe fav = new Shoe(n, g, s);
        System.out.println("My favorite shoe is " + fav.getName() + " " + fav.getGender() + " size " + fav.getSize());
    }
}