Ieffat Assignment 2

You might also like

You are on page 1of 15

Assignment 2 - Repetition Control Structur

Commence Date: 25/10/2022

Due Date: 4/11/202

NAME:MUHAMMAD IEFFAT SYAFI BIN


SAMN

STUDENT ID:5205232215
I

TABLE OF CONTENT

A.FRONT PAG

B.TABLE OF CONTEN

C.INTRODUCTIO

D.DETAILS OF PROBLEM

E.PROBLEM ANALYSI

F.PROGRAM DESIG

G.SOLUTIO

H.CONCLUSION

INTRODUCTIO

Repetition control structure is a structure that allows


the program to do multiple sets of statements
according to the condition tested which is stated
before or after the statement use. There are 3 type
repetition control structures available which are
While loop, DoWhile loop and For loop. There are 2
categories of repetition control structure which are
pre-test loop and Post Test Loop Students are tasked
to answer the question using a selection control
structure
.

DETAILS OF PROBLE

QUESTION

Create a program to collect n number of employee salary


and calculate the average of salary for the company using
For Loo

QUESTION

Create a program to accept positive number for n times


and discard any negative number and show average
positive number using while loo

QUESTION

Create a quiz program to guess the number of vowel


alphabet in the examples sentence below
p

Betty Botter bought some butter But she said the butter’s
bitter If I put it in my batter, it will make my batter bitter
But a bit of better butter will make my batter better So
‘twas better Betty Botter bought a bit of better butte

Peter Piper picked a peck of pickled peppers A peck of


pickled peppers Peter Piper picked If Peter Piper picked a
peck of pickled peppers Where’s the peck of pickled
peppers Peter Piper picked

PROBLEM ANALYSI

QUESTION

INPUT OUTPUT PROCESS

N,SALARY < DISPLAY AVERAGE SALARY


INPUT SALAR
CALCULATE=TOTAL+SAL
AR
AVERAGE=TOTAL+N

QUESTION

INPUT OUTPUT PROCESS

QUANTITY OF NUMBER PROMPT USER QUANTITY OF AVERAGE POSITIVE NUMBER


NUMBER
GET QUANTITY OF NUMBER
<QUANTITY OF NUMBER
GET NUMBER FROM USER
IF<0
TOTAL=TOTAL+NUMBER
ELSE
DISPLAY AVERAGE NUMBER

QUESTION
N

INPUT PROCESS OUTPUT

VOWEL ALPHABET Betty Botter bought some THE NUMBER OF VOWEL


butter But she said the butter’s ALPHABET
bitter If I put it in my batter, it
will make my batter bitter But
a bit of better butter will make
my batter better So ‘twas
better Betty Botter bought a
bit of better butter Or Peter
Piper picked a peck of pickled
peppers A peck of pickled
peppers Peter Piper picked If
Peter Piper picked a peck of
pickled peppers Where’s the
peck of pickled peppers Peter
Piper picked?
PROGRAM DESIG

QUESTION

PSEUDOCOD

STAR

INPUT N,SALAR

CALCULATE TOTAL+SALAR

IF AVERAGE=TOTAL+

EN

FLOWCHART
D

QUESTION

STAR

INPUT NUMBE

PROMPT USER QUANTITY NUMBE

GET QUANTITY OF NUMBER

GET NUMBER FORM USER

TOTAL=TOTAL+NUMBE

ELSE DISPLAY AVERAGE NUMBE

EN
D

FLOWCHAR
T

SOLUTIO

QUESTION

import java.util.Scanner

public class Question 1

public static void main(String [] args

Scanner in = new Scanner(system.in)

int n = in.nextIn

int salary,total =

doubl

for(int = 0;<n ++)

salary = in.nextInt();
e

QUESTION

import java.util.Scanne

public class Question 2

public static void main(String[]args

Scanner sc = new Scanner(system.in

int num

in

total_nu

total=

double averag

System.out.println(“Please Enter quantity of number”)

total num = in.nextInt()

System.out.println(“Please enter a number”

num
t

total = total + num

counter

average=total/total nu

System.out.println(“The Average of positive number is : “


+ average
=

QUESTION

import java.util.Scanne

public class Question 3

public static void main(String[]args

int main ()

char c

int (the number of vowel alphabet

print (“enter a alphabet”)

printf(“vowels:%d”,vowels);
;

CONCLUSIO

QUESTION

USERS INPUT THEIR SALARY.THEN IT LOOPS


USONG FOR LOOP.DISPLAY AVERAGE SALAR

QUESTION

USERS INPUT THE QUANTITY OF NUMBER.THE


NUMBER RANGES FROM POSITIVE AND
NEGATIVE NUMBER.IT LOOPS USING WHILE
LOOP.DISPLAY AVERAGE OF POSITIVE NUMBE

QUESTION

DISPLAY SENTENCE 1 AND 2.USERS CHOOSE


WHICH SENTENCE THEY DESIRED.NUMBER OF
VOWELS IN A SENTENCE IS CALCULATED USING
IF…..ELSE STATEMENT.DISPLAY TOTAL NUMBER
OF VOWELS ALPHABETS.
1

You might also like