Lab Quiz 3



Home | Resources | Homeworks | Slides | Labs | Contacts | Submit | Forums | Private

This is not the correct lab quiz

This is the lab quiz from last semester

 

Pledged lab quiz

The only "good programming practice" that is required for this lab is to include your name and e-mail ID in the header comments. You are welcome to include more, but make sure you get the programs working first, as the quiz is timed.

This is a pledged lab quiz.  The activities of this week are not to be discussed outside of lab. The quiz is open textbook but nothing else. You are to submit one program, ArrayQuiz.java, which contains the ArrayQuiz class.  No template file is being provided.  There are 4 methods that you have to implement in ArrayQuiz.java.

 

Instance variables

There is to be only one instance variable in the ArrayQuiz class.  The variable is an (single dimensional) int array named array.  This variable MUST be public (as otherwise it will not allow our testing routines to work correctly and you will get a VERY low score) - we realize this is not the best way to write a program, but otherwise you would have to implement an additional method.

 

Methods

You are to implement four methods in the ArrayQuiz class.  You are welcome to implement more, but only these four methods will be graded.

 

Sample usage

If method main() had the following definition.

 public static void main(String[] args) {
        int[] a = { 5, 25, 125 };
        int[] b = { 1, 2, 3 };
        int[] c = { 10, 100, 1000 };

        ArrayQuiz a1 = new ArrayQuiz( 3 );

        ArrayQuiz a2 = new ArrayQuiz( a );

        ArrayQuiz a3 = new ArrayQuiz( 3 );
        a3.populate( 10 );

        ArrayQuiz a4 = new ArrayQuiz ( b );
        a4.add( c );

        System.out.print("a1 = ");
        for (int i = 0; i < a1.array.length; ++i ) { System.out.print( a1.array[i] + " "); }
        System.out.println();

        System.out.print("a2 = ");
        for (int i = 0; i < a2.array.length; ++i ) { System.out.print( a2.array[i] + " "); }
        System.out.println();

        System.out.print("a3 = ");
        for (int i = 0; i < a3.array.length; ++i ) { System.out.print( a3.array[i] + " "); }
        System.out.println();

        System.out.print("a4 = ");
        for (int i = 0; i < a4.array.length; ++i ) { System.out.print( a4.array[i] + " "); }
        System.out.println();
    }  

The output would be the following.

a1 = 0 0 0 
a2 = 5 25 125 
a3 = 10 10 10 
a4 = 11 102 1003  

Submission

When you are finished, submit your ArrayQuiz.java file.