100% tevredenheidsgarantie Direct beschikbaar na betaling Zowel online als in PDF Je zit nergens aan vast
logo-home
COMP 249 Programming Methodology II Sample midterm examination 2024 with complete solution €12,92   In winkelwagen

Tentamen (uitwerkingen)

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

 6 keer bekeken  0 keer verkocht
  • Vak
  • Instelling

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

Voorbeeld 2 van de 10  pagina's

  • 12 november 2023
  • 10
  • 2023/2024
  • Tentamen (uitwerkingen)
  • Vragen en antwoorden
  • Onbekend
avatar-seller
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"));
}

Voordelen van het kopen van samenvattingen bij Stuvia op een rij:

√  	Verzekerd van kwaliteit door reviews

√ Verzekerd van kwaliteit door reviews

Stuvia-klanten hebben meer dan 700.000 samenvattingen beoordeeld. Zo weet je zeker dat je de beste documenten koopt!

Snel en makkelijk kopen

Snel en makkelijk kopen

Je betaalt supersnel en eenmalig met iDeal, Bancontact of creditcard voor de samenvatting. Zonder lidmaatschap.

Focus op de essentie

Focus op de essentie

Samenvattingen worden geschreven voor en door anderen. Daarom zijn de samenvattingen altijd betrouwbaar en actueel. Zo kom je snel tot de kern!

Veelgestelde vragen

Wat krijg ik als ik dit document koop?

Je krijgt een PDF, die direct beschikbaar is na je aankoop. Het gekochte document is altijd, overal en oneindig toegankelijk via je profiel.

Tevredenheidsgarantie: hoe werkt dat?

Onze tevredenheidsgarantie zorgt ervoor dat je altijd een studiedocument vindt dat goed bij je past. Je vult een formulier in en onze klantenservice regelt de rest.

Van wie koop ik deze samenvatting?

Stuvia is een marktplaats, je koop dit document dus niet van ons, maar van verkoper Wiseman. Stuvia faciliteert de betaling aan de verkoper.

Zit ik meteen vast aan een abonnement?

Nee, je koopt alleen deze samenvatting voor €12,92. Je zit daarna nergens aan vast.

Is Stuvia te vertrouwen?

4,6 sterren op Google & Trustpilot (+1000 reviews)

Afgelopen 30 dagen zijn er 78291 samenvattingen verkocht

Opgericht in 2010, al 14 jaar dé plek om samenvattingen te kopen

Start met verkopen
€12,92
  • (0)
  Kopen