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 7526303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:47:34+00:00 2026-05-30T03:47:34+00:00

I was looking for a little help as I’m at my wits end on

  • 0

I was looking for a little help as I’m at my wits end on how to accomplish this.

The assignment is to read in a file that contains state names, the governor of that state and the compensation he gets.

Example of the file:

California Tim John $50,000 $78,890 $30,000
North Dakota John Jones $30,000 $40,000 $56,000
Washington Susan K. Bones $30,000 $40,000 $56,000

As you can see, a name can contain more than three words (including the middle initial)

The output I’m supposed to get is the presidents name followed by the total compensation..

Example of output:

Susan K. Bones $126,000

I’ve already written code that prints out the total compensation. But I’m stuck on reading the names. How do I ignore the state names which can contain at most two words and just take the governor’s name?

Here is my code for the total compensation.

Also note: I have to use Scanner on this.

Scanner in = new Scanner(file);
            in.nextLine();      
                do {
                    double totalCompensation = 0.0; 
                    String readLine = in.nextLine();
                    readLine = readLine.replaceAll(",", "").replace("$", " ");
                    String presidentName = "";
                    Scanner readNumber = new Scanner(readLine);
                    while(readNumber.hasNext()) {                               
                        if (readNumber.hasNextDouble()) 
                            totalCompensation += readNumber.nextDouble();
                        else {
                            readNumber.next();
                        }
                    }

Another note: don’t worry, I do have a while(in.hasNextLine()) to close the do loop, later on in my code. I just don’t really want to paste in the whole thing.

Any hints would be welcome! Thanks!

  • 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-30T03:47:35+00:00Added an answer on May 30, 2026 at 3:47 am

    If you KNOW ahead of time that you will only ever see US state names, you could have your code look for a state name first. Since you know what part is the state name and what part is the compensation, whatever is left must be the governor’s name. There’s only 50 states, so this isn’t impossibly difficult.

    If this is more generic and can be a city/country/whatever and not just a US, there’s not a way to distinguish without a better separator character (or quotes to define the “state name” and “governor name”.

    EDIT: You mention that there is a further requirement that the “leader” name will be of the form “Firstname LastName” “Firstname M. Lastname” or “F. Middlename Lastname”. NOW you have enough to solve the answer.

    As you pull strings out with the scanner, put them in a list (or if you learned this datatype, a stack is more appropriate). Go through the list backwards. If the 2nd element is an initial, you know the name has three parts. If the 3rd element is an initial, you know the name has three parts. If neither is an initial, you know the name has two parts. Whatever is not the name of the leader is the name of the place.

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

Sidebar

Related Questions

I need a little help with navigating a json file. I'm looking to get
I am looking for a little bit help on this situation. I have a
I'm looking for a little help with this table. First: The table isn't being
I'm looking for a little help structuring a web form to include PHP validation
I have heard conflicting stories on this topic and am looking for a little
I am looking for a little help with designing a query using C#/LINQ to
Looking for a little Wordpress help, I've created prev/next links when viewing a post
I'm looking A little help on parsing XML from the internet to an Android
Looking for a little help trying to get the value of two selected buttons,
New here, looking to get a little help with my XmlDocument. Is it possible

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.