100% de satisfacción garantizada Inmediatamente disponible después del pago Tanto en línea como en PDF No estas atado a nada 4.2 TrustPilot
logo-home
Examen

COMP 249 Programming Methodology II Sample midterm examination 2024 with complete solution

Puntuación
-
Vendido
-
Páginas
10
Grado
A+
Subido en
12-11-2023
Escrito en
2023/2024

COMP 249 Programming Methodology II Sample midterm examination 2024 with complete solution

Institución
Grado









Ups! No podemos cargar tu documento ahora. Inténtalo de nuevo o contacta con soporte.

Escuela, estudio y materia

Institución
Estudio
Desconocido

Información del documento

Subido en
12 de noviembre de 2023
Número de páginas
10
Escrito en
2023/2024
Tipo
Examen
Contiene
Preguntas y respuestas

Temas

Vista previa del contenido

Programming Methodology II Sample midterm examination comp249


1) One-dimension arrays.

 What is the output of the following code?
int[] numbers = new int[10];
for(int i=0; i < numbers.length; ++i)
numbers[i] = i * 2;
for(int i=0; i < numbers.length; ++i)
System.out.print(numbers[i] / 2 + "
");
System.out.println();

 Answer : 0 1 2 3 4 5 6 7 8 9

2) Two-dimension arrays

 Show the output produced by the following java code.
int i, j, k, temp; // i and j are indices for the rows and
columns int [ ] [ ] A = { {5, 16, 7, 23, 15,} // 2-
dimension array
{31, 12, 22, 4, 19,}
{41, 21, 14, 37, 8 } };


for (i = 0; i < A.length; i++)
{
for (j = 0; j < A[i].length - 1; j++)
{
k = j + 1;
while (k < 5)
{
if (A[i] [k] < A[i] [j])
{
temp = A[i] [k];
A[[i] [k] = A[i] [j];
A[i] [j] = temp;
}
k = k + 1;
}
System.out.print(“ “ + array[i] [j]);
}
System.out.println(“\n”);
}


, Programming Methodology II Sample midterm examination comp249


 Answer :

5 7 15 16 23
4 12 19 22 31
8 14 21 37 41

3) File I/O and Exceptions.

 Write a main class that processes an input grade file (say grade.dat) storing the
student names, the student ids, the results for the 4 assignments (5% each), the
midterm test (30%), and final examination (50%) for each student. You have to
calculate the final grade out of 100 for each student and display in an output file (say
finalgrade.dat) the student names, the student ids and the final grade. In addition,
you must display on the screen the information for all students that fail.
Also, you must account for all possible exceptions that may be thrown when opening
the files.

Answer :

import java.util.Scanner;
import java.io.FileInputStream;
import java.io.PrintWriter;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.util.InputMismatchException;

public class SampleDemo
{
public static void main(String[] args)
{
String name, id;
double a1, a2, a3, a4, midterm, final, total;

System.out.println("Processing grade file …");
Scanner inputStream = null;
try
{
inputStream = new Scanner(new
FileInputStream("grade.dat"));
}
$13.99
Accede al documento completo:

100% de satisfacción garantizada
Inmediatamente disponible después del pago
Tanto en línea como en PDF
No estas atado a nada

Conoce al vendedor

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
Wiseman NURSING
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
6666
Miembro desde
4 año
Número de seguidores
3837
Documentos
25932
Última venta
6 horas hace
Testsprint

Updated exams .Actual tests 100% verified.ATI,NURSING,PMHNP,TNCC,USMLE,ACLS,WGU AND ALL EXAMS guaranteed success.Here, you will find everything you need in NURSING EXAMS AND TESTBANKS.Contact us, to fetch it for you in minutes if we do not have it in this shop.BUY WITHOUT DOUBT!!!!Always leave a review after purchasing any document so as to make sure our customers are 100% satisfied. **Ace Your Exams with Confidence!**

3.9

1367 reseñas

5
673
4
246
3
210
2
76
1
162

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes