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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:54:28+00:00 2026-05-27T03:54:28+00:00

I having some trouble with an APCS assignment. The program is supposed to read

  • 0

I having some trouble with an APCS assignment. The program is supposed to read strings with a length of two from a text file – test1.txt – and print out percentages of: a) girl-girl, boy-boy, boy-girl or girl-boy combinations, and b) the total number of individual groups.

I’ve been trying for an hour to figure this out! Although I’m suspicious of the String declaration in line 25, I don’t have a way to confirm that. Furthermore, I’m worried that I messed up my if-else-if-else loop without prompting a compiler error.

The source code is attached for your reference. If you need any additional information, please don’t hesitate to ask.

Since I’m a new user with a reputation < 10, please see the attached image:

http://imgur.com/7HpJF

For elaboration on what isn’t working. I took a screenshot and wrote relevant comments on it!

/**
 * Family takes user input of sets of boys, girls, and boys + girls. Results are then
 * tabulated and displayed in a percentage form to the user. The total number of 
 * individuals are also displayed.
 * 
 * @E. Chu
 * @Alpha
 */

import java.util.Scanner;
import java.io.File;
import java.io.IOException;

public class Family {

   public static void main (String[] args) throws IOException {

   int boyCount = 0;
   int girlCount = 0;
   double boyGroupCount = 0.0;
   double girlGroupCount = 0.0;
   int mixedGroupCount = 0;
   int totalPersonCount = 0;
   double totalGroupCount;
   String currentToken = "  ";
   Scanner inFile = new Scanner (new File ("test1.txt"));

   while (inFile.hasNextLine()) {
       currentToken = inFile.nextLine( );
       if (currentToken == "BG") {
          boyCount++;
          girlCount++; 
          mixedGroupCount++; }
       else if (currentToken == "GB") {
           boyCount++;
           girlCount++;
           mixedGroupCount++; } 
       else if (currentToken == "BB") {
          boyCount += 2; 
          boyGroupCount++; }
       else {
          girlCount += 2; 
          girlGroupCount++; } 
   }

   inFile.close();
   totalPersonCount = boyCount + girlCount;
   totalGroupCount = boyGroupCount + girlGroupCount + mixedGroupCount;
   System.out.println("Sample Size: " + totalPersonCount);
   System.out.println("Two Boys (%): " + boyGroupCount / totalGroupCount + "%");
   System.out.println("One Boy, One Girl (%): " + mixedGroupCount + "%");
   System.out.println("Two Girls (%): " + girlGroupCount / totalGroupCount + "%");

} // End of main method.

} // End of class Family.
  • 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-27T03:54:29+00:00Added an answer on May 27, 2026 at 3:54 am

    currentToken == "BB" should be currentToken.equals("BB")

    Don’t use == use the method equals instead

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

Sidebar

Related Questions

I´m having some trouble retrieving a collection of strings in a projection: say that
I'm having some trouble getting log4net to work from ASP.NET 3.5. This is the
Having some trouble sending properly formatted HTML e-mail from a PHP script. I am
Having some trouble with the CSS alignment of text generated with @font-face. For some
I'm having some trouble with GSON, mainly deserializing from JSON to a POJO. I
Im having some trouble looping through some xml data. The xml file is structured
Having some trouble getting this query to work correctly. mysql_query(DELETE FROM `table` WHERE `id`
Having some trouble passing values from one class to another. I basically have a
Having some trouble getting a JSON feed to load from my site. I'm starting
I'm having some trouble searching for any similar match in two fields. For example

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.