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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:38:56+00:00 2026-06-11T21:38:56+00:00

I am writing a program that keeps track of different transactions done over time.

  • 0

I am writing a program that keeps track of different transactions
done over time. I have a main class, and also another class named
CheckingAccount.java.

I have a main class formatted this way.

public class Main
{
   public static void main (String[] args)
   { 
         CheckingAccount c = new CheckingAccount(bal);
         --line of code---
         --line of code---
         --line of code---          
   }

   public static int getTransCode()
   {
         --line of code---
   }
   public static double getTransAmt()
   {
         --line of code---
   }
   public static void processCheck(double trAm, int tCode, boolean monthCh)
   {
        double curCharge=0.15;

        CheckingAccount.setBalance(trAm,tCode,curCharge,monthCh);
        CheckingAccount.setServiceCharge(curCharge);
   }
   public static void processDeposit(double trAm, int tCode, boolean monthCh)
   {
        double curCharge=0.10;

        CheckingAccount.setBalance(trAm,tCode,curCharge,monthCh);
        CheckingAccount.setServiceCharge(curCharge);
   } 
}

This is my CheckingAccount.java

public class CheckingAccount
{
   private double balance;
   private double totalServiceCharge;

   public CheckingAccount(double initialBalance)
   {
        balance = initialBalance;
        totalServiceCharge = totalServiceCharge;
   }

   public double getBalance()
   {
        return balance;
   }

   public void setBalance(double tAm, int Code, double charge, boolean mChrg)
   {
        if(tCode == 1)
        balance = (balance - tAm) - charge;
        else //if(tCode == 2)
            balance = (balance + tAm) - charge;
   }

   public double getServiceCharge()
   {
        return totalServiceCharge;
   }

   public void setServiceCharge(double currentServiceCharge)
   {
        totalServiceCharge = totalServiceCharge+currentServiceCharge;
   }
}

So the lines I can’t get to work are CheckingAccount.setBalance() and CheckingAccount.setServiceCharge() inside the functions on my main class. What I’m trying to do is to call the the methods I created (setBalance, and setServiceCharge) in my class, from functions that I created on my main class (processCheck, and processDeposit).

But I cannot get it to run, I keep running with these error messages.

non-static method setBalance(double,int,double,boolean) cannot be referenced from a static context
CheckingAccount.setBalance(trAm,tCode,curCharge,monthCh);

  • 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-11T21:38:58+00:00Added an answer on June 11, 2026 at 9:38 pm

    You are calling your setBalance through classname which is wrong…. setBalance() method is non-static, so it is defined to specific instance of the class, not for a class..

    **CheckingAccount.setBalance(trAm,tCode,curCharge,monthCh);
    CheckingAccount.setServiceCharge(curCharge);**
    

    You need to create an instance of CheckingAccount to call the method..

    Secondly, in your constructor of CheckingAccount class, you haven’t passed any argument for totalService, but you are setting one with an unknown variable..
    You will get a compiler error there..
    Either you need to initialize your totalServiceCharge with a fixed value or, you can pass it as an argument from main.. And change your constructor as below..

    public CheckingAccount(double initialBalance, ** double totalServiceCharge)
    {
        balance = initialBalance;
        this.totalServiceCharge = totalServiceCharge;
    }
    

    Then from main, call it like this: –

    CheckingAccount ca = new CheckingAccount(bal, totalServiceCharge);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey Guys, I am writing a performance monitor program that keeps track of different
I'm learning Python and writing a program that keeps track of the total number
Im writing a program that should read input via stdin, so I have the
So I'm writing a program which keeps a track of various documents like e-mails,
I am writing a program that allows multiple users the share screenshots. Every time
I am writing a Log Unifier program. That is, I have a system that
I'm writing a program that handles DBs and writes any changes into ListView for
I'm writing a program that's parsing an XML file to java objects using smooks.
I'm writing a program that reads huge file (3x280 GB) and does a fitting
I am writing a program that permutes a list of names based on 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.