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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:11:22+00:00 2026-06-04T14:11:22+00:00

I’m doing my homework on java I/O data, the problem is i’m not allowed

  • 0

I’m doing my homework on java I/O data, the problem is i’m not allowed to use object serialization to load data from a binary file.

Here is the assignment requirements:

Persistence, writing objects to file and reading objects from file (Text format)

• All objects should be written to a single file in a text format
• All objects should be read form the same file
• You should use JFileChooser

I have 3 classes: Unit, Assessment, and Task.

The Assessment class is abstract while IndividualAssessment & GroupAssessment are concrete subclasses.

Unit has a collection of Assessment and Assessment has a collection of Tasks.

I could save all data to one text file with FileWriter but I don’t know how to read each line of the text file in to the proper Assessment class.

What I mean is how do you recognize which line is for IndividualAssessment or GroupAssessment classes.

Here is the code I tried but it’s not working:

BufferedReader bf = new BufferedReader(file);
While (bf.readLine != null){
    Unit u = new Unit(bf);
    diary.add(u);
    try{
        Assessment a = new IndividualAssessment(bf);
    } catch (IOException ex){
        Assessment a = new GroupAssessment(bf);
            }
    u.add(a);
    Task t = new Task(bf);
    a.add(t);
  • 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-04T14:11:23+00:00Added an answer on June 4, 2026 at 2:11 pm

    You should probably start with storing the content of the line you read in a String object. So it would look something like this:

    String line = bf.readLine();
    while(line != null) {
        // Add code to look at your line to figure out what kind of object it 
        // represents.   For example you could add a one character prefix to each 
        // line when you write it to specify which object it is ('U', 'A' or 'T').
        // Based on that, you can call a constructor of the appropriate object that
        // takes a String as input. Then let the constructor deal with parsing the
        // line for the object it represents. This way you don't end up with some
        // massive parsing routine.
    
        char code = line.charAt(0);
        if(code == 'T') {
            Task task = new Task();
            task.initFromString(line.sustring(1));
            ... Do something with your task
        }
        else if(code == ...) {
        }
    
        line = bf.readLine();    // Read the next line
    }
    

    Define some interface that all your object should implement:

    public interface TextExportable {
        public char getClassIdentifier();
        public void initFromString(String s);
    }
    

    I’m not sure what your objects look like but let’s say for example:

    public class Task implements TextExportable {
        private String name;
    
        public Task() {} // For the pseudo-serialization
    
        public Task(String name) { // For creating the object by hand
            this.name = name;
        }
    
        public char getClassIdentifier() {
            return 'T';
        }
    
        public String toString() {
            return getClassIdentifier()+name;
        }
    
        public void initFromString(String line) {
            this.name = line;
            // Here, you would need extra parsing if you have more than one attribute
            // and dissect the line
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:

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.