Answer to Question #167506 in Java | JSP | JSF for ritheesh

Question #167506

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


1
Expert's answer
2021-02-28T07:03:52-0500
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();
    }
    
    
    }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog