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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:45:09+00:00 2026-06-03T19:45:09+00:00

Needed some help with my logic again. Assuming the Loan class exists, I have

  • 0

Needed some help with my logic again. Assuming the Loan class exists, I have a file containing Loan objects. I am reading the Loan objects from the file and calculating the total Loan amount. I gave one of the instances a variable name ld just to prove to myself that getLoanAmount() method works.

Now at the end in my while loop, I kept thinking on how to calculate the loan objects but turn them into integers. I’m thinking that the input.readObject() method is returning an instance of the object, so it would only make sense to go about getting the integer value like this:

sum = sum + input.readObject().getLoanAmount();

But, I’m getting an error saying that it can’t find the symbol getLoanAmount() and that’s where I’m puzzled. I thought I nailed it. Can someone tell me why my logic is wrong. As usual I would really appreciate it. Here’s the code:

import java.io.*;
import java.util.Date;
public class RestoringObjects19_7 {
    public static void main(String[] args) throws IOException {
        int sum = 0;
        try {
            ObjectOutputStream output = new ObjectOutputStream(
              new FileOutputStream("Exercise19_7.dat"));
            Loan ld = new Loan(1000);
            System.out.println(ld.getLoanAmount()); //WORKS HERE

            output.writeObject(ld);
            output.writeObject(new Loan(2000));
            output.writeObject(new Loan(3000));
            output.writeObject(new Loan(4000));
            output.writeObject(new Loan(5000));

            output.close();
            ObjectInputStream input = new ObjectInputStream(
              new FileInputStream("Exercise19.7.dat"));
            while(true) {
                sum = sum + input.readObject().getLoanAmount(); //ERROR HERE??
            }
        } catch (Exception e) {
            System.out.println("Sum: " + sum);
        }
  }
}
  • 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-03T19:45:10+00:00Added an answer on June 3, 2026 at 7:45 pm

    This looks like it’s homework, so I’ll give you hints instead of a full blown answer:

    • The method input.readObject() returns type is Object.
    • getLoanAmount() is a method that is defined on objects of type Loan.

    Hope this helps you figure out what might be wrong with your code.

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

Sidebar

Related Questions

Some MATLAB help needed ! I have an set of 1s and 0s, I
well, i have a big file, there are some contents i needed to be
I need some help again. I have a GridView with CheckBox es in first
I have some icons inside divs and needed to lay them out with a
I have some age-restricted content needed to confirm 18 years old stuff. so I
Skip to the specific question as needed. Some background: The scenario: I have a
im using mvc framework and i have learned some techniques that help me with
Okay, I am stumped on this one and need some quick help. I have
I needed some help with creating custom trees given an arithmetic expression. Say, for
I needed some help with plotting a velocity vs forcing term diagram for a

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.