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

  • Home
  • SEARCH
  • 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 6700699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:50:46+00:00 2026-05-26T06:50:46+00:00

I am a student trying to finish a lab assignment. I have two files,

  • 0

I am a student trying to finish a lab assignment.
I have two files, Sentence.java and Sentence.Tester.java but I’m confused about filling in the public String findWord() method and public String insertSecondWord() though I could have done both files completely wrong.
The findWord method is supposed to returns the index location of a given word in the sentence, but wouldn’t that be based on user input(Also the insertSecondWord() uses input) depends on the ?

However the teacher said the scanner method is only in the tester and only use string methods in the sentence. Could someone please explain how edit the findWord() and insertSecondWord() methods so they work correctly?

Thanks 🙂

Edit 1: Put in the new code for the two methods I am having problems with but now I am getting 7 errors

error: cannot find symbol on 45, 67, 76, and 85 as well as two errors on 56 as well as an error missing method body or declare abstract.

(These could be simply errors that I am not catching but I have worked on this and another lab all day and am java brain dead).

/**
 *A Sentence provides information about the contents of a sentence.
 */
 public class Sentence
{
    // instance field (only one!)
    private String phrase;


    /**
     * Constructs a Sentence object with a given String
     * @param phrase the selected phrase
     */
    public Sentence(String sentence)
    {
        phrase = sentence;
    }
    /**
     * Returns the number of characters in the sentence
     * @return the number of characters in the sentence
     */
     // add the remaining methods as described

    public int characterCount()

    {
        int count = phrase.length();
        return count;
    }
    /**
     * Returns the first word of the sentence
     * @return the first word
     */

    public String firstWord()

    {
        String first = phrase.substring(0, sentence.indexOf(" "));


    }
    /**
     * Returns the last word of the sentence
     * @return the the last word of the sentence
     */

    public String lastWord()
    {
        String last = phrase.substring(sentence.lastIndexOf(" "), sentence.length());
    }

    /**
     * find returns the index location of a given word in the sentence
     * @param the word being searched for
     * @return the index location
     */

    public int findWord(String word);
    {
        int find = indexOf(word);
    }
    /**
     * changes the sentence by inserting a given word after the existing first word
     * @param second the word being added
     */

    public void insertSecondWord(String second)
    {
        String replace = replace.phrase(" ",  second);
    }
    /**
     * returns the sentence
     * @return the sentence
     */

    public String getSentence()
    {
        return sentence;
    }


}

// The Scanner is ONLY in the tester, not Sentence. Use string methods in Sentence





import javax.swing.JOptionPane;

/**
 * A class to test the CoinCounter class
 */

public class CoinCounterTester
{
    /**
     * Tests methods of the CoinCounter class
     * @param args not used
     */
    public static void main(String[] args)
    {
        CoinCounter coinCounter = new CoinCounter(int quarters, int dimes, int nickels, int pennies);

        String penny = JOptionPane.showInputDialog("Enter the quantity of pennies");
        int pennies = Integer.parseInt(penny);

        String nickel = JOptionPane.showInputDialog("Enter the quantity of nickels");
        int nickels = Integer.parseInt(nickel);

        String dime = JOptionPane.showInputDialog("Enter the quantity of dimes");
        int dimes = Integer.parseInt(dime);

        String quarter = JOptionPane.showInputDialog("Enter the quantity of quarters");
        int quarters = Integer.parseInt(quarter);



        System.exit(0);
    }
}
  • 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-05-26T06:50:46+00:00Added an answer on May 26, 2026 at 6:50 am

    I don’t think it would be helpful to just write the solution for you, but here are the pieces you need. 🙂

    1. This is the documentation for Java strings. It will be invaluable for any sentence parsing utilities you may need.
    2. indexOf() can be used several difference ways, not just char finding! You can search for the first index location of "these words" in a string with indexOf("these words").
    3. replaceFirst() is quite powerful. For example, you change the string "My dog loves treats" to "My "My cat loves treats" with replaceFirst(" dog", " cat").

    Best of luck!

    EDIT:

    Oh, I might add that your methods have some odd return values and parameters! insertSecondWord() takes a string and returns nothing, so it should be public void insertSecondWord(String word). findWork() takes a string and returns and integer index, so it should be public int findWord(String word).

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

Sidebar

Related Questions

I have two tables: subject and student. I'm trying to count the number of
I have two classes Teacher and Student . I am trying to get teacher
I have two classes Person and Student. I'm currently trying to derive the Student
I am student, trying to finish a homework lab. Right now I am struggling
Programming Student here...trying to work on a project but I'm stuck. The project is
I'm trying to calculate the average of a student's marks: import java.util.Scanner; public class
I've been trying to include a structure called student in a student.h file, but
I am trying to create a student that has many awards So I have
I am a student trying to implement the DES algorithm. I have a choice
Problem: * I'm trying to calculate the number of consecutive absence each student have

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.