0
0
Javaprogramming~15 mins

Use cases in Java - Interactive Code Practice

Choose your learning style8 modes available
ads_clickPractice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a simple class named User.

Java
public class [1] {
    // class body
}
🎯 Drag options to blanks, or click blank then click option
Auser
BUser
CMain
DAccount
Attempts:
3 left
2fill in blank
medium

Complete the code to create a method named greet that returns a String.

Java
public class Greeter {
    public [1] greet() {
        return "Hello!";
    }
}
🎯 Drag options to blanks, or click blank then click option
AString
Bint
Cvoid
Dboolean
Attempts:
3 left
3fill in blank
hard

Fix the error in the code to correctly instantiate an object of class Car.

Java
public class Car {
    String model;

    public Car(String model) {
        this.model = model;
    }
}

Car myCar = new [1]("Tesla");
🎯 Drag options to blanks, or click blank then click option
ACar
Bcar()
Ccar
DVehicle
Attempts:
3 left
4fill in blank
hard

Fill both blanks to create a method that checks if a user is adult based on age.

Java
public class User {
    int age;

    public boolean isAdult() {
        return age [1] [2];
    }
}
🎯 Drag options to blanks, or click blank then click option
A>=
B18
C<
D21
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to create a method that returns a map of user names and their ages if age is above 20.

Java
import java.util.Map;
import java.util.HashMap;

public class UserData {
    Map<String, Integer> users = new HashMap<>();

    public Map<String, Integer> getAdults() {
        Map<String, Integer> adults = new HashMap<>();
        for (String [1] : users.keySet()) {
            int [2] = users.get([1]);
            if ([2] [3] 20) {
                adults.put([1], [2]);
            }
        }
        return adults;
    }
}
🎯 Drag options to blanks, or click blank then click option
Aname
Bage
C>
D<
Attempts:
3 left