Jump to content

So for Lesson 15(For those who want an exact answer) we have to have a "bank account" where people start off with 1,000 dollars that you need to type in. You need to be able to withdraw and deposit money and then print the balance. I believe I have everything in place but I will see if someone can help me. My biggest problem it seems is that when I run it, it tells me that you can't make a static reference to a non-static reference.

 

First Part:

 

package overDrawn;

import java.util.*;
import java.io.*;

public class Tester {

    public static void main(String[] args) {
        
        Scanner kbReader = new Scanner(System.in);
        System.out.print("What is your first name?_");
        String a = kbReader.next();
        System.out.print("What is your last name?_");
        String b = kbReader.next();
        String accountee = a + " " + b;
        
        System.out.println("1. Deposit");
        System.out.println("2. Withdrawal\n");
        
        Scanner Key = new Scanner(System.in);
        System.out.print("What would you like to do?_");
        int choice = Key.nextInt();
        
        switch (choice)
        {
        case 1:
            System.out.print("How much are you depositing today?_");
            Scanner Board = new Scanner(System.in);
            double myDeposit = Board.nextDouble();
            BankAccount.deposit(myDeposit);
            System.out.print("The " + accountee + " now has a balance of " + BankAccount.balance);
            break;
        case 2:
            System.out.print("How much are you withdrawing today?_");
            Scanner d = new Scanner(System.in);
            double myWithdrawal = d.nextDouble();
            BankAccount.withdraw(myWithdrawal);
            System.out.print("The " + accountee + " now has a balance of " + BankAccount.balance);
            break;
        }
    
    }

}

 

Second Part:

 

package overDrawn;

import java.util.*;
import java.io.*;

public class Tester {

    public static void main(String[] args) {
        
        Scanner kbReader = new Scanner(System.in);
        System.out.print("What is your first name?_");
        String a = kbReader.next();
        System.out.print("What is your last name?_");
        String b = kbReader.next();
        String accountee = a + " " + b;
        
        System.out.println("1. Deposit");
        System.out.println("2. Withdrawal\n");
        
        Scanner Key = new Scanner(System.in);
        System.out.print("What would you like to do?_");
        int choice = Key.nextInt();
        
        switch (choice)
        {
        case 1:
            System.out.print("How much are you depositing today?_");
            Scanner Board = new Scanner(System.in);
            double myDeposit = Board.nextDouble();
            BankAccount.deposit(myDeposit);
            System.out.print("The " + accountee + " now has a balance of " + BankAccount.balance);
            break;
        case 2:
            System.out.print("How much are you withdrawing today?_");
            Scanner d = new Scanner(System.in);
            double myWithdrawal = d.nextDouble();
            BankAccount.withdraw(myWithdrawal);
            System.out.print("The " + accountee + " now has a balance of " + BankAccount.balance);
            break;
        }
    
    }

}

post-12151-0-48733000-1415623014.jpg
 

Current System: CPU - I5-6500 | Motherboard - ASRock H170M-ITX/ac | RAM - Mushkin Blackline 16GB DDR4 @ 2400mHz | GPU - EVGA 1060 3GB | Case - Fractal Design Nano S | Storage - 250GB 850 EVO, 3TB Barracuda | PSU - EVGA 450W 80+ Bronze | Display - AOC 22" 1080p IPS | Cooling - Phanteks PH-TC12DX_BK | Keyboard - Cooler Master QuickFire Rapid(MX Blues) | Mouse - Logitech G602 | Sound - Schiit Stack | Operating System - Windows 10

 

The OG System: I3-2370M @ 2.4 GHz, 750GB 5400 RPM HDD, 8GB RAM @1333Mhz, Lenovo Z580 Laptop (Ubuntu 16.04 LTS).

 

Peripherals: G602, AKG 240, Sennheiser HD 6XX, Audio-Technica 2500, Oneplus 5T, Odroid C2(NAS).

Link to comment
https://linustechtips.com/topic/248081-blue-pelican-java-help/
Share on other sites

Link to post
Share on other sites

It might be a mistake but you have class Tester added twice and don't include your BankAccount class.

 

Also, please use code tags. Use the blue < > icon in the editor when posting or manually use code tags.

[code]// Enter your code here between the tagspublic class Example{    // ...}[/code]

With all of that said, your issue seems to be these lines

BankAccount.deposit(myDeposit);// andBankAccount.withdraw(myWithdrawal);

Unless deposit and withdraw are static, you first have to create a BankAccount object to be able to use them

BankAccount ba = new BankAccount(...); // Parameters in constructor if needed// then call methods like soba.deposit(...);ba.withdraw(...);
Link to comment
https://linustechtips.com/topic/248081-blue-pelican-java-help/#findComment-3402467
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×