IT JAVA

profilememzr1989
IT401_Assignment3_Questions.docx

Pg. 04

Question Four

Assignment 3

Deadline: Tuesday 09/04/2019 @ 23:59

[Total Mark for this Assignment is 6]

Business Computer Languages

IT 401

https://www.seu.edu.sa/sites/ar/SitePages/images/logo.png

College of Computing and Informatics

Question One

1.5 Mark

Learning Outcome(s):

- Demonstrate Integrated Development Environment (IDE) for the editing, building, debugging, and testing of programs. 

- Develop a program based on specification using programming language elements including syntax, data types, conditional statement, control structures, procedures and arrays.

Write a complete Java program (code + screenshot of output) that performs the following:

Given the following marks of a student: 84, 72, 91, 61, 69, 77

· Create an array (marksArray) to include all of student marks.

· Create a method (smallest) to find the smallest mark and print its value.

· Create a method (average) to compute the average of a student marks and return its value to the caller.

· Create a new array (backup) to copy all marks of the current array (marksArray). (Hint: use Arrays.copyOf method)

Answer:

Question Two

1.5 Mark

Learning Outcome(s):

- - Demonstrate Integrated Development Environment (IDE) for the editing, building, debugging, and testing of programs. 

- Develop a program based on specification using programming language elements including syntax, data types, conditional statement, control structures, procedures and arrays.

Write a complete Java program (code + screenshot of output) that performs the following:

· Create an array list and add the following items: [Toyota, Nissan, Mercedes, Mazda].

· Print out the existing items of the array list on the screen.

· Replace the item “Mercedes” with “Kia”, and remove the item “Mazda”.

· Print out the current array list items in the opposite order.

Answer:

Question Three

1.5 Mark

Learning Outcome(s):

- - Demonstrate Integrated Development Environment (IDE) for the editing, building, debugging, and testing of programs. 

- Develop a program based on specification using programming language elements including syntax, data types, conditional statement, control structures, procedures and arrays.

Write a complete Java program (code + screenshot of output) that performs the following:

· Write a while loop that reads integer values entered by user.

· Stop when a user enters any non-integer value.

· Compute the sum of all entered values that are greater than Zero and print the result on the screen.

Answer:

Question Four

Learning Outcome(s):

- Demonstrate Integrated Development Environment (IDE) for the editing, building, debugging, and testing of programs. 

- Develop a program based on specification using programming language elements including syntax, data types, conditional statement, control structures, procedures and arrays.

1.5 Mark

Each of the following Java code contains one or more errors. Find the error(s) and modify the code so that it will work properly.

#

Original Code

Correct Code

1.

int[] values= values [10];

for (int i = 0; i <= 10; i++)

{

values [i] = i * i;

}

2.

int count= -10;

while (count<0)

{

System.out.println(count);

}

3.

for (double i : values)

{

Sum = sum + values [i];

i++;

}

4.

int fractions[] = [2.8, 5.5, 4.6];

5.

ArrayList<int> arr = new ArrayList();

arr.add(5);

System.out.println(arr.length);

6.

for (int i = 0; i < arrSize; i++)

{

System.out.println(values);

}