1. Consider the following declarations and initialization of the JavaFX Circle and Retangle shapes:

Circle cOne = new Circle(200, 200, 0);
Rectangle rOne = new Rectangle(300, 300, 0, 0);

These statements create a circle located at coordinate (200, 200) and a rectangle at coordinate (300, 300). Both shapes have size zero. What do the following statements do?

rOne.heightProperty().bind(rOne.widthProperty()); rOne.widthProperty().bind(cOne.radiusProperty());

For example, what happens to the two shapes if the program contains the following statement? cOne.setRadius(100);

2. Consider the following try/catch block:

try {
int d = Integer.parseInt(tfDiameter.getText());
int f = Integer.parseInt(tfWidth.getText());
System.out.println(d+" "+f);
int ratio = d / f;
} catch (Exception ex) {
System.err.println("Unknown exception "+ex);
} catch (ArithmeticException ae) {
System.err.println("Arithmetic error");
System.err.println(ae);
ae.printStackTrace();
} catch (NumberFormatException nfe) {
System.err.println("Field didn't contain a number");
tfDiameter.clear();
nfe.printStackTrace();
}

This code has a problem in the catch handlers. The code and format for each catch handler is correct and each catch block will work properly,. What is the problem with the way the catch blocks are used?

3. Consider the following class definitions: See image.

And suppose that the following code that uses the classes above:

i. A a = new B();
ii. B b = new B();
iii. A c = new A();
iv. a.aaa(1, 2);
v. a.aaa(1, 2.0);
vi. b.aaa(1, 2);
vii. b.aaa(1, 2.0);
viii. c.aaa(1, 2);
ix. c.aaa(1, 2.0);

a. Identify any statements (using i., ii., etc) which do not compile.

b. Of the statements which do compile, show the output for each statement.

Now suppose that method 1 in class B is commented out and the class definitions recompiled.

c. Identify any statements (using i., ii., etc) which do not compile.

d. Of the statements which do compile, show the output for each statement.

4. Which of the following class definition headers is incorrect and why? (Assume all names, except the name of the class being defined, mentioned in the class definitions below are defined appropriately elsewhere.)

a. class MyClass extends Employee implements Comparable

b. class MyClass implements Comparable, Runnable

c. class MyClass extends Employee, Supervisor

5. Consider the following code:

int x = in.nextInt();
double z = in.nextDouble();

if(x != 0 && z++ / x > 1) System.out.println(z);
if(x != 0 & z++ / x > 1) System.out.println(z);

Suppose that the value read for x is 2 and the value read for z is 10. What values are display by this code. Why?

6. Consider the following array declaration: double [][] table; Write the code which will initialize the storage for this array as follows:

i) the first index will have 8 elements

ii) the second index will have storage allocated as follows I if the first index is even, the second index will have (2 * (the first index + 1) elements II) if the first index is odd, the second index willl have (3 * (the first index + 1) ) elements where index zero counts as even. The figure below shows the storage allocation, where each square is a double element: See image.

See Packacges: See image.

7. In the class framework above, answer the following questions regarding the visibility of the named items in Column 1 from other classes:

a. What items from Column 1 are visible in Class B?

b. What items from Column 1 are visible in class C?

c. What items from Column 1 are visible in class AC?

8. You are to define a set of classes tp track of the first name, last name, and an ID number of people. In addition, the people have professions:

* tinkers: have guild levels: apprentice, journeyman, master; and specialty: pots, pans, dishes

* tailors: have guild levels: apprentice, journeyman, master; and number killed in one blow (Im not suddenly turning violent, just referring to the A Brave Little Tailor fairy tale.)

* soldiers: have ranks: private, sergeant. lieutenant, captain, major, colonel, general; and have a country

* spies: have a country; and type: single-agent, double-agent, triple-agent

Use inheritance and design a class hierarchy to represent the information above. Super classes should be used to define common attributes for subclasses. You will be graded on the completeness of your hierarchy. Attribute values that are names may be represented as Java Strings.

9. Consider the following code:

String t = getTargetString();
boolean found = false;
while (not found) {
String s = getNextString();
if(s == t)
found = true;
}

Assuming that getTargetString() and getNextString() methods are defined elsewhere, what do you think this code is intended to do? Do you think it works as intended? Why or why not?

10. Write a very short start() method for a JavaFX program which uses a border panel. In the center of the border panel, display a grid of 100 buttons, arranged in 10 rows and 10 columns. Each button should be labeled with its grid cell location. For example, (1,2) would be the button in row 1 column 2.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.