Try to solve each of the following. Click the Check Me button to check each solution. You will be told if your solution is too short, has a block in the wrong order, or you are using the wrong block. Some of the problems have an extra block or two that aren’t needed in the correct solution. Try to solve these on your phone or other mobile device!
The following program should create a Person class with a constructor that takes in a String and an integer value and intilaizes its fields name and id. But, the blocks have been mixed up and may include extra blocks that are not needed in a correct solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the Check button to check your solution.
public class Person
{
private String name;
private int id;
---
public Person(String name, int id)
{
this.name = name;
this.id = id;
}
---
public Person()
{
this.name = name;
this.id = id;
} #distractor
---
public Person(String name, int id)
{
} #distractor
---
public Person()
{
} #distractor
---
} // end class
The following program should create a Person class with a default constructor. But, the blocks have been mixed up and may include extra blocks that are not needed in a correct solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the Check button to check your solution.
public class Person
{
private String name;
private int id;
---
public Person(String name, int id)
{
this.name = name;
this.id = id;
} #distractor
---
public Person(String name, int id)
{
} #distractor
---
public Person()
{
}
---
} // end class
The following program segment should create an empty Dog class that is a child of the Animal class. But, the blocks have been mixed up and may include extra blocks that are not needed in a correct solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the Check button to check your solution.
public class Dog extends Animal {
---
public Animal class Dog { #distractor
---
public class Animal extends Dog { #distractor
---
public class Dog implements Animal { #distractor
---
} // end class
The following program should overload a void method talk with no parameters. But, the blocks have been mixed up and may include extra blocks that are not needed in a correct solution. Drag the needed blocks from the left and put them in the correct order on the right. Click the Check button to check your solution.
public class GenericPerson
{
public void talk()
{
System.out.println("Hello!");
}
}
public class Person extends GenericPerson {
---
public void talk(String name) {
System.out.println("Hello" + name);
}
---
public String talk() {
return "Hello!";
} #distractor
---
public char talk() {
return 'y';
} #distractor
---
} // end class