You are on page 1of 6

AINA NAJWA BINTI RAZALI

F2T8
DRAFT ASSIGNMENT SC025

I = n, chemical solution, pH values, pH value to be search


P = determine chemical solution by searching the pH values
O = chemical solutions, pH values, counter or ‘’Chemical solution not found”

Pseudocode
Start
Counter = 0
Read n
Declare, create, initialize array (chemical solutions[n], pH values[n])
While (counter<n)
Read chemical solution[counter]
Read pH values[counter]
Counter = counter + 1
End while
Read pH to be search
Counter = 0
While (counter < n)
If (pH value to be search = pH values[counter])
Display chemical solutions[counter], pH values[counter], index location
Else
Display “Chemical solution not found”
End if
Stop
Flowchart
Java code
//Assignment SDS SC025 Session 2021/2022
//Author name : Aina Najwa Binti Razali
//AINA NAJWA F2T8 ASSIGMENT SDS SC025 SESSION 2021/2022 SET 2

import java.util.Scanner;
class F2T8Assignment{
public static void main(String[] args){

System.out.println("Welcome to sejahtera Chemical Company Information System:");


System.out.println("*********************************************************");

Scanner sc = new Scanner(System.in);


int n;

System.out.print("Enter n, number of chemical solutions : ");


n = sc.nextInt();
int counter = 0;

String[] chemicalSolutions = new String[n];


double[] phValues = new double[n];

for(counter = 0; counter < n ; counter = counter + 1){


System.out.print("Enter chemical solution's name : " );
chemicalSolutions[counter] = sc.next();
chemicalSolutions[counter] = chemicalSolutions[counter] + sc.nextLine();

System.out.print("Enter pH value : ");


phValues[counter] = sc.nextDouble();
}
System.out.print("Write the pH value to find the solution that you want to know: ");
double phValueToBeSearch = sc.nextDouble();
output
value found

No value found
for (counter = 0; counter < n ; counter = counter + 1){
if (phValueToBeSearch == phValues[counter])
{
System.out.println("Chemical solution " + chemicalSolutions[counter] + " with pH value
" + phValues[counter] + " present at index " + counter);
}

else
counter = counter + 1;
if (counter == n){
System.out.println("Chemical solution not found");
}
}
System.out.println("******************************************************");

}
}

You might also like