0% found this document useful (0 votes)
17 views6 pages

IS184203 Algorithm and Programming MT Paper 2023

Uploaded by

Ahmad
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)
17 views6 pages

IS184203 Algorithm and Programming MT Paper 2023

Uploaded by

Ahmad
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/ 6

INSTITUT TEKNOLOGI SEPULUH NOPEMBER

Department of Information Systems


Undergraduate Program

SEMESTER 2 MIDTERM EXAMINATION 2022/23

IS184203 – Algorithm and Programming (3 credits)

Course Convenors:
Ahmad Muklason
Renny Pradina Kusumawardani
Rizal Risnanda Hutama

27 March 2023 TIME ALLOWED: 2 HOURS

INSTRUCTIONS TO CANDIDATES

1. This examination paper contains SEVEN (7) questions

2. Answer strictly FIVE (5) questions only, i.e. questions numbers 1,


either 2 or 3, 4, 5, and either 6 or 7. The marks for each question are
indicated at the beginning of each question.

3. Answer the questions in any order.

4. This is CLOSED BOOK exam.

5. When justification is required, you MUST write down systematically


the steps in the workings.

6. Please work independently, and Good Luck!


IS184203

Question 1. (15 marks)


The code below is created to determine whether a toddler is stunting or not.
A toddler is said stunting if his/her z-score is less than the standard, i.e.
0.45. The z-score is counted using the following formula: z−score = 2− w−hy
,
whereas w, h, y are weight (in 100 gram), height (in cm), and age (in months)
respectively. However the code contains five lines causing errors. Fix, the
code to know whether a toddler with 100 cm height, 15 kg weight, and 36
month old is stunting or not!

public class Stunting{


public static void main(String[] args) {
int todAge= 36;
___ todHeight=___
int todWeight=15;
___ zScore = ___
boolen isStunting= ___
if (___) ____
if (___) System.out.println("stunting");
else System.out.println("normal");
}
}

Question 2. (15 marks)


Suppose a method is defined as follow:

public static void secretMethod(int a, int b){


char code [] = {’h’,’e’,’a’,’r’,’t’};
int c=0;
do {
System.out.print("#");
if (c<5) c++;
if (a%3==0) a = a+3;
else a++;
System.out.print(code[c]);
} while (a<b);

2
IS184203

int i = (a+b)%5;
if (i<0) i=0;
System.out.println(a+""+b+code[i]);
}

What is the output from the following method call?Briefly justify your an-
swer!

(a) secretMethod(5,2)

(b) secretMethod(1,4)

Question 3. (15 marks)


Suppose a method is defined as follow:

public static void mystery(int a, int b){


char code [] = {’l’,’o’,’v’,’e’};
boolean whenever [] ={true,false,true,true,false};
for(int i=0;i<5;i+=2){
if(!whenever[i]) System.out.print("*");
if (a<b){
int c= (a+b)%4;
System.out.print(code[c]);
a=a+2;
}
}
System.out.println(a+b+""+b+"*");
}

What is the output from the following method call?Briefly justify your an-
swer!

(a) mystery(2,5)

(b) mystery(10,2)

3
IS184203

Question 4. (20 marks)


Complete the following method definition:

public static void squareStars(int n){


//your code goes here

In order to generate expected output with its respective method call as follow:

Please note that your code has to work with parameter n, any integers greater
than 0.

Question 5. (20 marks)


Given an input file namely hujan bulan juni.txt shown below:

Hujan Bulan Juni


tak ada yang lebih tabah
dari hujan bulan Juni
dirahasiakannya rintik rindunya
kepada pohon berbunga itu
tak ada yang lebih bijak
dari hujan bulan Juni
dihapusnya jejak-jejak kakinya
yang ragu-ragu di jalan itu
tak ada yang lebih arif
dari hujan bulan Juni
dibiarkannya yang tak terucapkan
diserap akar pohon bunga itu
(1989)
Sapardi Djoko Damono

4
IS184203

Create a complete java code, namely Hujan.java with a main method to


read the file and print out the number of times the word ”hujan” occurs in
the text, regardless of capitalization.

Question 6. (30 marks)


To foster a competitive atmosphere, Waskito School, a private school in
Surabaya, initiate to open Quick Express class. Selected students in this
class will finish their senior high school within 1 year only. Therefore, the
school carried out IQ test to the new students. The students will pass the
fast track class entry exam if their IQ ≥ 120 and greater than the average
IQ of their peers. To automate the selection process, you are asked to help
the school developing a complete java program. namely Waskito.java allow
the school to enter the students names and their IQ Score, count how many
students passed the Quick Express Class, and spot the student with highest
IQ score. More specifically, your code should:

a. Ask the users how many students taking the entry test

b. For each student, ask the user to enter the student name and his/her IQ
score

c. Store the student names and their respective IQ score into two separated
array variables

d. Count the average and highest IQ score

e. Count the number of students passed the Quick Express Class

f. Print the number of students pass the Quick Express Class, the name of
student with the highest IQ score, and the highest IQ score

Please note that you should ask the user input from console (System.in).

Question 7. (30 marks)


Today is very defining moment for Juminten, a final year, computer science
student in Coding University. She finally can make her dream, being accepted
as exchange student in The University of Edinburgh, Scotland, really comes
true. This morning She is going to catch her very first flight in her life.

5
IS184203

Using Emprit Airways, she will be leaving Soekarno Hatta Airport in Jakarta
to Heathrow Airplot in London and having connecting flight to Edinburgh
afterward. She brings three travel bags, labeled as A, B, and C. Since she is
allowed to bring exactly one bag to the cabin, she has to check in the other
two bags. However, the Emprit Airways has restriction that the total weight
of checked baggage is not allowed to exceed D Kgs and the maximum weight
of cabin bag is E Kgs. Given the baggage.txt file as input, help Juminten
to check whether she can bring all her bags or not.

Sample Input:
5
1 1 1 15 5
8 7 6 15 5
8 5 7 15 6
19 1 5 20 5
9 5 7 15 6

Sample expected Output:


YES
NO
YES
YES
NO

The first line of the input contains a single integer T denoting the number of
test cases. The description of T test cases follows. Each test case contains
a single line of input, five space separated integers A,B,C,D,E. Create a
complete java program, namely Emprit.java.

You might also like