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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:58:02+00:00 2026-06-14T14:58:02+00:00

Im a student programmer so only been studying since september. Had an assignment this

  • 0

Im a student programmer so only been studying since september. Had an assignment this week to read in data from a text file called datingdata.txt and create a class for the information storing each persons info in a position of an array. The data was in the format ‘George Robson M 38 11000’ where the name was up to 20 characters. Then we had to compare each person for matches, where they were of an opposite sex, within 5 years of each other in age and had at least 3 common interests (the 1 meaning they were interested in that activity and 0 if not). I have got it working up to the nested for loops at the end and have a feeling I am missing brackets because it keeps coming up with an error that it cannot find symbols. Any help?

    import java.io.*;
    import static java.lang.Math.*;
    class PersonInfo
   {
    String name;
    char sex;
    int age;
    String interest;

    public void setname (String anyName)
       { name = anyName; }

    public void setsex (char anysex)
       { sex = anysex; }

    public void setage (int anyage)
       { age = anyage; }

    public void setinterest (String anyinterest)
       { interest = anyinterest; }

    public String getName ()
       { return name; }

    public char getsex ()
       { return sex; }

    public int getage ()
    {return age;  }

    public String getinterest ()
    {return interest;    }

    void print ()
       {
        System.out.println(name + " " + sex + " " + age + " " + interest);
       }

    PersonInfo (String name, char sex, int age, String interest)
       {
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.interest = interest;
       }
    }

    class Practical6
      {
    public static void main(String[] args) throws IOException
       {
        //read in file
        BufferedReader fileInput;
        fileInput = new BufferedReader(new FileReader("datingdata.txt"));

        //create an array for storing each persons information
        PersonInfo[] People = new PersonInfo[20];

        //fields to use in creating PersonInfo
        String name;
        char sex;
        int age;
        String interest;

        int i = 0;
        int count = 0;

        //read in each line and store in an array
        while (fileInput.ready ())                                  
           {                                                    
            String information;
            information = fileInput.readLine ();                                
           // System.out.println (information);
            name = information.substring(0,20);
            sex = information.charAt(20);
            age = Integer.parseInt(information.substring(22,24));   
            interest = information.substring(25,30);
            People[i]= new PersonInfo (name, sex, age, interest);
            i++;                                
           } 
        fileInput.close(); 

        //pring out the array

        for (int j = 0; j < People.length; j++)
            People[j].print();


        //go through each element of array and compare to another record for a match
        for (int k = 0; k < People.length; k++)
            for (int l = 0; l <People.length; l++)
            if (People[k].getsex() != People[l].getsex())
                if(math.abs(People[k].getage()-People[l].getage()) <=5)
                {for(int m = 0; m < 5; m++)
                    if((People[k].getinterest.charAt(m)=='1')  && (People[l].getinterest.charAt(m)=='1'));
                            count++;
                            if(count==3)
                                System.out.println(People[k].getname + " is a match with " + People[l].getname);
                }

            }
            }
  • 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-14T14:58:03+00:00Added an answer on June 14, 2026 at 2:58 pm
    for (int k = 0; k < People.length; k++)
        for (int l = 0; l <People.length; l++)
        if (People[k].getsex() != People[l].getsex())
            if(Math.abs(People[k].getage()-People[l].getage()) <=5)
            {for(int m = 0; m < 5; m++)
                if((People[k].getinterest().charAt(m)=='1')  && (People[l].getinterest().charAt(m)=='1'));
                        count++;
                        if(count==3)
                            System.out.println(People[k].getName() + " is a match with " + People[l].getName());
            }
    

    some syntax error:
    1. Math.abs() instead of math.abs()
    2. getinterest() instead of getinterest
    3. getName() instead of getname

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

Sidebar

Related Questions

I'm a college student who's had several internships and consider myself a decent programmer.
I am a student programmer using Qt to build a GUI interface fro my
I am a student programmer using QT to develop and application for work. Currently
A student in my class brought this to my attention, and I didn't have
INSERT INTO [Temp].[dbo].[Student] ([Fname], [Lname], [Gender]) VALUES (N'Aname', N'Alname', N'Male') GO This codes workes
I'm currently a student and I'm studying PHP, I'm trying to make a simple
I am student programmer and I am using Qt to develop a GUI interface
I am a student programmer currently designing a GUI for my company with Qt
Iam just a beginner student socket programming.I tried a simple code from TCP/IP Sockets
I'm a beginner in C# and JSON, I've only been coding in Java (Basic

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.