0% found this document useful (0 votes)
34 views

AP Assignment 2022

The document describes an assignment for an advanced programming class. It includes 4 questions - the first two involve reading from and writing to a text file using arrays, the third involves creating and accessing a 2D array. Students are instructed to submit their code and attend a demonstration session by the deadline to receive marks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

AP Assignment 2022

The document describes an assignment for an advanced programming class. It includes 4 questions - the first two involve reading from and writing to a text file using arrays, the third involves creating and accessing a 2D array. Students are instructed to submit their code and attend a demonstration session by the deadline to receive marks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Al-Baha University ‫ﺟ ﺎﻣ ﻌ ﺔ اﻟﺑ ﺎﺣ ﺔ‬

Faculty of Computer Science and ‫ﻛ ﻠﯾ ﺔ ﻋ ﻠو م اﻟﺣ ﺎﺳ ب و ﺗ ﻘ ﻧ ﯾ ﺔ اﻟﻣ ﻌ ﻠو ﻣ ﺎت‬


Information Technology

Advanced Programming
Assignment
21h October 2022
25/03/1444
(20 marks: 15 for written answers and 5 for discussions)

Introduction
• The purpose of this assignment is to assess student in:
• CLO 2.5 (11 Marks): code programs that read, write, and modify text file.
• CLO 2.1 (9 Marks): create and use multidimensional Arrays.
• There are four questions in the assignment, and you are asked to fulfill all the requirements,
use the most appropriate datatypes, and use comments to explain your code.
• The answers should be your own.
• Use (Rafid) to submit your source files in a single .ZIP file.
• Each source code file must
• Contain a program header (a comment at the top of the source file that includes your
name, studentID, the date, and a brief description of your solution).
• An appropriate level of comments.
• Follow a consistent style of indentation.
• Follow the usual Java conventions for constant and variable names.
• The deadline for submitting your assignment through (Rafid) is 11:59 pm (Midnight), Friday,
4th November 2022 (10th of Rabi II 1444 H).
• When submitting work, it is your responsibility to ensure that all work submitted is
• Consistent with stated requirements
• Entirely your own work
• On time
• Marks will be awarded on the basis of the following scheme:
• Question 1 (50%): 10 marks
• Question 2 (25%): 5 marks
• Discussion and demonstration (25%): 5 marks (1 for Q1 and 4 for Q2)

Please note that there are severe penalties for submitting work which is not your own. If you have
used code which you have found on the Internet or from any other source, then you must signal that
fact with appropriate program comments.

Also, note that to obtain the mark you must attend a session to demonstrate your assignment and to answer
questions about any aspect of it. There will be a schedule for these sessions. So, make sure you attend your
session as non-attendance will result in your work not being marked.

1
Al-Baha University ‫ﺟ ﺎﻣ ﻌ ﺔ اﻟﺑ ﺎﺣ ﺔ‬
Faculty of Computer Science and ‫ﻛ ﻠﯾ ﺔ ﻋ ﻠو م اﻟﺣ ﺎﺳ ب و ﺗ ﻘ ﻧ ﯾ ﺔ اﻟﻣ ﻌ ﻠو ﻣ ﺎت‬
Information Technology

Question 1 (CLO 2.5): Developing programs that read, write, and modify
text file. [10 Marks]

Section (1) [5 Marks]:


Write a java program that prompts a user to insert scores of ten students and print out "in a text file"
these scores.
You should:
1. Create a file named "outFile.txt"
2. Declare an array named scores of the int type to store the user inputs.
3. Ask the user to enter the scores with the following message: "Enter the scores of 10
students:"
4. Use Scanner and store the user inputs in the array.
5. Do not forget to close the file after finishing writing to it.

The output in outFile.txt should appear as shown:

Figure 1 Expected outcomes of Program 1

Note: You can enter numbers of your choice.

2
Al-Baha University ‫ﺟ ﺎﻣ ﻌ ﺔ اﻟﺑ ﺎﺣ ﺔ‬
Faculty of Computer Science and ‫ﻛ ﻠﯾ ﺔ ﻋ ﻠو م اﻟﺣ ﺎﺳ ب و ﺗ ﻘ ﻧ ﯾ ﺔ اﻟﻣ ﻌ ﻠو ﻣ ﺎت‬
Information Technology
Section (2) [5 Marks]:

Write a java program that reads the scores from the file "outFile.txt" and then prints out the highest
and lowest scores among them to the console.
You should:
1. Open the file you created in the previous question: "outFile.txt"
2. Declare an array named mark of type int with size 10. You will use the array to store the
scores you read from the file.
3. Find and print out the highest and lowest marks using for loop from the stored elements in
the mark array.

The output should appear as shown:

Figure 2 Expected outcomes of Program 2

Note: The numbers are those you entered in "outFile.txt".

3
Al-Baha University ‫ﺟ ﺎﻣ ﻌ ﺔ اﻟﺑ ﺎﺣ ﺔ‬
Faculty of Computer Science and ‫ﻛ ﻠﯾ ﺔ ﻋ ﻠو م اﻟﺣ ﺎﺳ ب و ﺗ ﻘ ﻧ ﯾ ﺔ اﻟﻣ ﻌ ﻠو ﻣ ﺎت‬
Information Technology

Question 2 (CLO 2.3): Create and use multidimensional Arrays. [5 Marks]


Write a Java program to create a 2-dimension array named numbers.
You should:
1. Insert 12 elements in the array as follows:

2 15 3 37
3 8 1 14
46 3 5 9

2. Print all elements of the array using for loops as shown in figure 3.

3. Check if the elements in the array are even or odd such that:
if the element is even, print out: element is even
else if the element is odd, print out: element is odd
Note: element is the number stored in the array.

Expected Output:

Figure 3 Expected outcomes of Program3

*** THE END ***

You might also like