Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8819207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:17:51+00:00 2026-06-14T05:17:51+00:00

I want to ask you if is it possible to change/decompose my code to

  • 0

I want to ask you if is it possible to change/decompose my code to 2-3 classes, add constructors (if possible not empty) and/or add more methods. If need program can have more functions.

 public class Testing {


            public static void main(String args[]) throws Exception {
                Scanner input = new Scanner(System.in);
                System.out.println("Select word from list:");
                System.out.println();

                try {
                    FileReader fr = new FileReader("src/lt/kvk/i3_2/test/List.txt"); // this is list of words, everything all right here
                    BufferedReader br = new BufferedReader(fr);
                    String s;
                    while((s = br.readLine()) != null) {
                        System.out.println(s);
                    }
                    fr.close();
                    String stilius = input.nextLine();   // eneter word which I want to count in File.txt
                    BufferedReader bf = new BufferedReader(new FileReader("src/lt/kvk/i3_2/test/File.txt")); // from this file I need to count word which I entered before

                    int counter = 0;                
                    String line;

                    System.out.println("Looking for information");
                    ArrayList<String> resultList = new ArrayList<String>();
                    String name = null;
            while (( line = bf.readLine()) != null){
                    if (line.trim().length() == 0) name = null;
                    else if (name == null) name = line;
                    int indexfound = line.indexOf(stilius);
                          if (indexfound > -1) {
                   counter++;
                   resultList.add(name);
   }
                    }
                    if (counter > 0) {
                        System.out.println("Word are repeated "+ counter + "times");}
                        else {
                        System.out.println("Error...");
                    }
                    bf.close(); 

                }
                catch (IOException e) {
                    System.out.println("Error:" + e.toString());
                    }
                }
            }

Program counting words (entered by keyboard) from file.txt and elect who repeated this word for ex.: if I enter word: One It shows:

Word One repeated 3 times by John, Elisa, Albert

file.txt looks like:

John //first line - name
One
Three
Four

Peter //first line - name
Two
Three

Elisa //first line - name
One
Three

Albert //first line - name
One
Three
Four

Nicole //first line - name
Two
Four

I don’t know really if is possible to decompose this code to 2-3 classes. If someone could help me, thank you very much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:17:52+00:00Added an answer on June 14, 2026 at 5:17 am

    I would start by defining two classes:

    • WordFile
    • WordFileEntry

    A WordFile-object should consist of a list of WordFileEntry-objects. A WordFileEntry consists of String name and List<String> words.

    The counting of repetitions could be done by a WordFile-object itself. The logic of reading a file could be written in the WordFile-class or a separate class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to ask for help. I need to write code that remotely connect
I want to ask question is there possible way with jQuery to change a
I want to ask if it is possible to change UITabBarController to another UITabBarController
I want to ask wether it's possible to develop a J2ME application for Nokia
I want to ask that If have read that it is possible to give
I want to ask, is possible to create on-line card game, only with using
Possible Duplicate: How can WCF consuming data from database phpmyadmin? I want to ask
want to ask user to input something but not want to wait forever. There
OK, not really sure if this is possible but thought I'd ask anyway :)
I am afraid to ask a strange question but I want to change pathInfo

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.