Identifying Boundary Cases

Help Questions

AP Computer Science A › Identifying Boundary Cases

Questions 1 - 3
1

Identify a user error that could occur in this program

UserInput ui = new UserInput(); // input from the user

int s = (Integer)ui;

System.out.println(s);

The user input could not be an integer

There is nothing wrong

The parseInt statement is incorrect

The user can never do anything wrong

Explanation

The user could input a string and the cast to an (Integer) would cause a runtime exception. If there is a runtime exception, the program will stop and open up vulnerabilities to hackers. Once a hacker knows how to halt a program, they can start input bad data to see a database schema to collect data. One way to fix this would be using a utility method such as parseInt(ui).

2

Identify a user error that could occur in this program

UserInput ui = new UserInput(); // input from the user

int s = (Integer)ui;

System.out.println(s);

The user input could not be an integer

There is nothing wrong

The parseInt statement is incorrect

The user can never do anything wrong

Explanation

The user could input a string and the cast to an (Integer) would cause a runtime exception. If there is a runtime exception, the program will stop and open up vulnerabilities to hackers. Once a hacker knows how to halt a program, they can start input bad data to see a database schema to collect data. One way to fix this would be using a utility method such as parseInt(ui).

3

Identify a user error that could occur in this program

UserInput ui = new UserInput(); // input from the user

int s = (Integer)ui;

System.out.println(s);

The user input could not be an integer

There is nothing wrong

The parseInt statement is incorrect

The user can never do anything wrong

Explanation

The user could input a string and the cast to an (Integer) would cause a runtime exception. If there is a runtime exception, the program will stop and open up vulnerabilities to hackers. Once a hacker knows how to halt a program, they can start input bad data to see a database schema to collect data. One way to fix this would be using a utility method such as parseInt(ui).

Return to subject