Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Can you please help me to solve this error.

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can you please help me to solve this error.

    package pkg6.pkg2.addex2.encapsulation;

    import java.util.Scanner;

    public class Addex2Encapsulation {

    public double bal = 100;

    public double getBalance(double gbal) {
    return gbal;
    }

    public void setBalance(double gbal) {
    System.out.println("Enter you Deposit:");
    Scanner scanner;
    scanner = new Scanner(System.in);
    gbal = scanner.nextDouble();
    System.out.println(gbal);
    gbal = bal;
    }

    public static void main(String[] args) {
    Addex2Encapsulation balance = new Addex2Encapsulation();

    balance.setBalance(gbal); // i ma having an error here. can u help
    System.out.println(balance.bal);[/B]

    }


    }


  2. #2
    Junior Member
    Join Date
    Apr 2013
    Posts
    2
    My Mood
    Asleep
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can you please help me to solve this error.

    It looks like you need to use bal instead of gbal. The variable gbal is not declared in main.

    Also, your getBalance is going to return exactly what was passed to it. You may want to change this to: return this.bal;

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can you please help me to solve this error.

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Can you please help me to solve this error.

    public void setBalance(double gbal) {
       System.out.println("Enter you Deposit:");
       Scanner scanner;
       scanner = new Scanner(System.in);
       gbal = scanner.nextDouble();
       System.out.println(gbal);
       gbal = bal;  //what did you intend to do here?
    }

Similar Threads

  1. [SOLVED] Easy error to solve in a minute. Help please, I don't want to fail Java Programming again.
    By ihatejava in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 15th, 2012, 04:30 PM
  2. anyone can help me to solve this?
    By d3sm0nd in forum What's Wrong With My Code?
    Replies: 13
    Last Post: June 27th, 2012, 06:47 AM
  3. My code have a simple error but i dont know how to solve it !!!
    By Blackhawk1993 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 17th, 2011, 01:12 PM
  4. Please solve my error occured java.lang.NullPointerExceptio
    By Viruthagiri in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: March 24th, 2010, 08:29 AM
  5. help me out with the following code to solve the error
    By romilc in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 11th, 2009, 03:45 AM

Tags for this Thread