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

Chemical Solutions and pH Search Code

The document describes a pseudocode and Java program to search for a chemical solution based on its pH value. The program first takes input for the number of chemical solutions and their names and pH values, storing them in arrays. It then takes input for the pH value to search for. It loops through the pH values array and checks for a match, displaying the matching chemical solution and pH value if found or a "not found" message if no match.
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)
149 views6 pages

Chemical Solutions and pH Search Code

The document describes a pseudocode and Java program to search for a chemical solution based on its pH value. The program first takes input for the number of chemical solutions and their names and pH values, storing them in arrays. It then takes input for the pH value to search for. It loops through the pH values array and checks for a match, displaying the matching chemical solution and pH value if found or a "not found" message if no match.
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

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