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 2 of 2

Thread: Basic question, but cant figure it out, answer is probably obvious

  1. #1
    Junior Member
    Join Date
    Apr 2020
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Basic question, but cant figure it out, answer is probably obvious

    **** Solved thank you!


    First off, I am very VERY new to Java and my college ended up going online for this class, so I having hard time on some things.

    I have the following code, (see below). The issue is it will not return a new balance amount. I have tried many changes and cannot get it to work. If someone could please explain where I am messing up and why, I'd appreciate it.

    package pkg05lab;
     
    import java.util.Scanner;
     
    public class AccountHolder 
    {
        static Scanner sc = new Scanner(System.in);
        static double balance;
     
     
        public static void main(String args[])
        {
     
        AccountHolder myAccount = new AccountHolder();    
     
        System.out.printf("Initial Balance is: %.2f%n%n", 
                myAccount.getBalance());
     
        System.out.println("Please enter the Balance: ");    
        double newBalance = sc.nextDouble();
        myAccount.setBalance(newBalance);
     
        System.out.printf("Amount in current Balance is: %.2f%n", 
                myAccount.getBalance());
     
        }
        private double newBalance;
     
        public void setBalance(double balance) 
        {
            newBalance = balance;
        }
     
        public double getBalance() 
        {
            return balance;
        }
     
    }

    Output when run:

    run:
    Initial Balance is: 0.00

    Please enter the Balance:
    1234.56
    Amount in current Balance is: 0.00
    BUILD SUCCESSFUL (total time: 13 seconds)
    Last edited by CTaylor; April 30th, 2020 at 04:16 PM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Basic question, but cant figure it out, answer is probably obvious

    it will not return a new balance amount
    Please copy the full contents of the console from when you run the program and paste it here so we can see what you are talking about.
    Add some comments where the output is not what you want and show what you want the output to be.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. please answer my question.
    By sgt98 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 16th, 2014, 06:31 AM
  2. Can You Answer This basic Question "DDD
    By amiel in forum Java Theory & Questions
    Replies: 4
    Last Post: July 2nd, 2013, 09:08 AM
  3. [SOLVED] please answer this question,tq
    By suganti selvaraj in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 6th, 2013, 12:50 AM
  4. Having trouble over here, sorry if the answer is obvious.....
    By thatguywhoprograms in forum What's Wrong With My Code?
    Replies: 6
    Last Post: December 19th, 2011, 12:59 PM
  5. please answer some basic question
    By togaurav in forum Java Theory & Questions
    Replies: 5
    Last Post: April 16th, 2011, 07:58 AM