Search Police by ID, Mini Java Program
You got an assignment in your class to create a program in which you can Search Police by ID.
Also, the program should have police basic data such as name, id, working hours, working days and other detail.
In this Search Police by ID Mini Java Program you can do that, also you can modify the code according to your needs.
Search Police by ID Java Mini Program
Create a new java class and name it as “PoliceSearch” and save the file name as “PoliceSearch.java”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
package police; import java.util.Scanner; //Initialized the class public class PoliceSearch { //main function public static void main(String[] args) { //creating user input object Scanner input = new Scanner(System.in); //String array data type. Multi-dimensional array which is storing name, hours and working days of the police. String[][] police = { {"Jazib Hussain","0900-1700", "Monday-Thursday"}, {"Jawad Hussain","1700-0100", "Monday-Thursday"}, {"Shafiq Ahmad","0900-1700", "Friday-Sunday"}, {"Osama Khalid","0900-1700", "Tuesday-Saturday"}, {"Raheel Khan","0300-1100", "Friday-Sunday"}, {"Arshad Ali Khan","1100-1800", "Saturday-Sunday"}, } int another = 1; //initiliazing the while loop for consective searches. while(another == 1) { System.out.println("Search Police by Id"); int id = input.nextInt(); if( id > police.length) { System.out.println("Please Enter Valid ID"); } else { System.out.println("Police Name: " + police[id][0]); System.out.println("Working Hours : " + police[id][1]); System.out.println("Working Days : " + police[id][2]); System.out.println("+++++++++++++++++++++++++++++++++"); System.out.println("Do you Want Another Search?"); System.out.println("Enter 1-Yes, 0-No"); another = input.nextInt(); } } System.out.println("Search has Been Completed"); } } |
[[Also Check Android Transparent Activity Tutorial?]]
Final Words on Java Mini Program
You can easily modify this mini program according to your needs such as you can get input from the user through loops and can show the output by using loops.
If there is any question just ask us in the comment section. We will try our best to get back to you as soon as possible.