Create another class Report holding a main function. This class will ask the user for type of data to be displayed like 1. Medical report 2. Grocery purchase bill 3. Electricity bill 4. Exit Once the choice is selected, write the code for invoking appropriate methods of the respective class for reading the details of three household and display the information in java program
import java.util.ArrayList;
import java.util.Scanner;
public class WordDetection {
Scanner sc;
ArrayList<String> li;
int arrayLength;
void getArray(){
li = new ArrayList<String>();
sc = new Scanner(System.in);
System.out.println("Please enter the total number of word count in the array:");
arrayLength = Integer.parseInt(sc.nextLine());
System.out.println(arrayLength);
System.out.println("Please enter the words");
for(int j=0;j<arrayLength;j++){
li.add(sc.next());
}
}
void displayArrayElements(){
System.out.println("\n The array elements are listed below");
if(li.isEmpty()) {
System.out.println("ArrayList is Empty..Please enter the values");
}
else {
for(int i=0; i<li.size(); i++) {
System.out.println(li.get(i));
}
}
}
void searchElement(){
char ch=' ';
int[] a = new int[Character.MAX_VALUE + 1];
System.out.println("\n Please enter the starting letter of thw word");
char firstLetter = sc.next().charAt(0);
System.out.println("\n Please enter the last letter of thw word");
char lastLetter = sc.next().charAt(0);
if(li.isEmpty()) {
System.out.println("ArrayList is Empty..");
}else {
for (int i = 0; i < li.size(); i++) {
if(li.contains(firstLetter)){
if(li.contains(lastLetter)){
System.out.println(li.get(i));
}
}
}
}
}
public static void main(String args[]){
WordDetection wd=new WordDetection();
wd.getArray();
wd.displayArrayElements();
wd.searchElement();
}
}
Comments
Leave a comment