Computer Science

computer science

Description

1. (10 pts) What are the diagrams defined in the UML Standard. Give a one or two sentence

description of each one.

2. (10 pts) Given the following code, how should the toString methods in the classes H2ClassA

and H2ClassB be written to give the indicated output and take advantage of the natural toString

method in H2ClassB?

1  import java.util.ArrayList;

2

3  public class H2ClassA {

4    ArrayList <H2ClassB> list = new ArrayList <H2ClassB>

();

5

6    public static void main (String args []) {

7      H2ClassA y = new H2ClassA ();

8      int [] v = {4, 3, 7, 5, 99, 3};

9      for (int m: v)

10       y.list.add (new H2ClassB (m));

11     System.out.println (y);

12   } // end main

13

14 } // end class H2ClassA

15

16 class H2ClassB {

17   int x;

18   H2ClassB (int a) { x = a;}

19 } // end H2ClassB

OUTPUT:

4 3 7 5 99 3

3. (10 pts) How can the following code be corrected? Give at least two good answers.

1 public class H2ClassC {

2   H2ClassC (int a) {}

3 } // end class H2ClassC

4

5 class H2ClassD extends H2ClassC{

6 } // end class H2ClassD

4. (10 pts) Why does the following code give a compiler error? How should it be fixed?


Related Questions in computer science category