Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › [H] Blue Pelican Java Project Help
New Posts  All Forums:Forum Nav:

[H] Blue Pelican Java Project Help

post #1 of 7
Thread Starter 
Hey everyone, first off, thanks for taking your time to read this.

So I have to make a project with classes using the parameters set by the textbook. The code I came up with for this project is...
Code:
/**
 * @(#)BankAccount.java
 *
 * BankAccount application
 *
 * @author Will O'Rourke
 * @version 1.00 2012/2/20
 */
 
import java.io.*;
import java.util.*;

public class BankAccount {
        public String name;
        public double balance;
        
        public double deposit (double balance){
                balance = balance + 505.22;
                return balance;
        }

        public double withdraw (double balance) {
                balance = balance - 100;
                return balance;
        }

public static void main(String [] args){
        
Scanner kbReader = new Scanner(System.in);
System.out.println("Enter Value of money:");
double balance = kbReader.nextDouble();
Scanner kReader = new Scanner(System.in);
System.out.println("Enter name:");
String name = kReader.next();
balance = balance + balance.deposit;
System.out.println("The amount of money left after depositing is " + balance);
balance = balance - balance.withdraw;
System.out.println("The " + name + " account balance is " + balance);
}
}

When compiling this code, I get two errors. Both are "error: double cannot be dereferenced".

These errors are on the lines in the main string that state balance = balance + balance.deposit; and balance = balance + balance - balance.withdraw;.

What does this error mean?
How can I fix this?
And finally, am I take the wrong approach all together at making this work?

Thanks for the help everybody.
post #2 of 7
EDIT: Wait nvm I see what you are trying to do now, give me a sec to give you a better input tongue.gif

EDIT 2:

This is how it should be done
Code:
import java.io.*;
import java.util.*;

public class BankAccount {

    static public double deposit(double balance) {
        balance = balance + 505.22;
        return balance;
    }

    static public double withdraw(double balance) {
        balance = balance - 100;
        return balance;
    }

    public static void main(String[] args) {

        Scanner kbReader = new Scanner(System.in);
        System.out.println("Enter Value of money:");
        double balance = kbReader.nextDouble();
        Scanner kReader = new Scanner(System.in);
        System.out.println("Enter name:");
        String name = kReader.next();
        balance = deposit(balance);
        System.out.println("The amount of money left after depositing is " + balance);
        balance = withdraw(balance);
        System.out.println("The " + name + " account balance is " + balance);
    }
}


To call a function you only need to put up it's name, and assign it to a value if it has a return, in this case it would be:

balance = deposit( balance );

and

balance= withdraw ( balance );

Also in the top you declare a public string name and a public double balance, if you plan to re-declare them on the main, there is no need for them there.
Edited by Barbaroti - 2/20/12 at 7:29pm
First Build
(17 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k @4.5Ghz Gigabyte Z68X-UD7 B3 MSI 6950 G.Skill Sniper 2x4GB 
Hard DriveHard DriveHard DriveCooling
Crucial M4 64GB Samsung SpinPoint 250GB Hitachi 1TB Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows Server 2012 Samsung S22B300 22' ViewSonic VA703B 17" CM Quickfire TK 
PowerCaseMouse
Corsair HX850 NZXT Phantom Mionix Naos 3200 
  hide details  
Reply
First Build
(17 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k @4.5Ghz Gigabyte Z68X-UD7 B3 MSI 6950 G.Skill Sniper 2x4GB 
Hard DriveHard DriveHard DriveCooling
Crucial M4 64GB Samsung SpinPoint 250GB Hitachi 1TB Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows Server 2012 Samsung S22B300 22' ViewSonic VA703B 17" CM Quickfire TK 
PowerCaseMouse
Corsair HX850 NZXT Phantom Mionix Naos 3200 
  hide details  
Reply
post #3 of 7
Thread Starter 
hmm. What you said sorta confused me. Can you post an example in a related situation? Sorry, You don't have to use the exact code, you can change things, just point out where the problem is solved. tongue.gif.

and may I ask what the OOP way is?
post #4 of 7
Your methods deposit and withdraw require a parameter (that you defined as double balance)

instead of
Code:
balance = balance + balance.deposit;
/* ... */
balance = balance - balance.withdraw;

try this
Code:
balance += deposit(balance);
/* ... */
balance -= withdraw(balance);

You might also need to make your methods static

So...
Code:
public static double deposit(double balance)

/* and */

public static double withdraw(double balance)

As for the error. It simply means that you called the datatype wrong... easy fix!

hope that helps!thumb.gif
Flash Penguin
(20 items)
 
Audio Stuffs
(9 items)
 
FileSerpent
(10 items)
 
CPUMotherboardGraphicsGraphics
Xeon W3520 EVGA X58 Classified GTX 275 GTX 275 
GraphicsRAMHard DriveHard Drive
GT 640 G.Skill Trident 1710 Mhz @ 6.7.6.18 Vertex 2 Seagate 1tb 7200.12 
Optical DriveCoolingCoolingCooling
LG Multi-DVD Writer Apogee XT Bitspower mobo and mosfet blocks for EVGA e760 Feser 360 and Feser 240 
OSMonitorKeyboardPower
Win7 x86-64 3x LG W2353V 23" 1080p G15 Gaming Keyboard (V1) [BFG] ES-800 
CaseMouseMouse PadAudio
Antec 1200 LED/Window/HDD rack Modded Logitech G700 An old mousepad (shows a computer with ISA slots) Asus Essence ST 
AudioAudioAudioAudio
Rega Saturn-R CDP/DAC Rega Elicit-R Integrated Amplifier Vandersteen Audio Treo Four-Way, Ported Floor-S... Rega RP8 w/ Exact2 cartridge 
AudioAudioAudioAudio
Cambridge Audio Stream Magic 6 Network Player Beyerdynamic Tesla T1 Headphones reterminated t... Sennheiser HDVA 600 Rega DAC 
Audio
Nordost QB4 w/ Nordost Heimdall Norse 2 Mains C... 
CPUMotherboardRAMHard Drive
Xeon E3-1240 V3 ASROCK E3C226D2I 2x8GB 1333 Kingston Unbuffered ECC 2x WD Black 500 GB in Raid 1 
Hard DriveCoolingOSPower
8x WD Red 3TB in Raid 10 Noctua NH-U9B Windows Server 2012 x64 Seasonic SS-400FL2 400w 
CaseOther
iStarUSA S-917 Adaptec 8885 Raid Controller 
  hide details  
Reply
Flash Penguin
(20 items)
 
Audio Stuffs
(9 items)
 
FileSerpent
(10 items)
 
CPUMotherboardGraphicsGraphics
Xeon W3520 EVGA X58 Classified GTX 275 GTX 275 
GraphicsRAMHard DriveHard Drive
GT 640 G.Skill Trident 1710 Mhz @ 6.7.6.18 Vertex 2 Seagate 1tb 7200.12 
Optical DriveCoolingCoolingCooling
LG Multi-DVD Writer Apogee XT Bitspower mobo and mosfet blocks for EVGA e760 Feser 360 and Feser 240 
OSMonitorKeyboardPower
Win7 x86-64 3x LG W2353V 23" 1080p G15 Gaming Keyboard (V1) [BFG] ES-800 
CaseMouseMouse PadAudio
Antec 1200 LED/Window/HDD rack Modded Logitech G700 An old mousepad (shows a computer with ISA slots) Asus Essence ST 
AudioAudioAudioAudio
Rega Saturn-R CDP/DAC Rega Elicit-R Integrated Amplifier Vandersteen Audio Treo Four-Way, Ported Floor-S... Rega RP8 w/ Exact2 cartridge 
AudioAudioAudioAudio
Cambridge Audio Stream Magic 6 Network Player Beyerdynamic Tesla T1 Headphones reterminated t... Sennheiser HDVA 600 Rega DAC 
Audio
Nordost QB4 w/ Nordost Heimdall Norse 2 Mains C... 
CPUMotherboardRAMHard Drive
Xeon E3-1240 V3 ASROCK E3C226D2I 2x8GB 1333 Kingston Unbuffered ECC 2x WD Black 500 GB in Raid 1 
Hard DriveCoolingOSPower
8x WD Red 3TB in Raid 10 Noctua NH-U9B Windows Server 2012 x64 Seasonic SS-400FL2 400w 
CaseOther
iStarUSA S-917 Adaptec 8885 Raid Controller 
  hide details  
Reply
post #5 of 7
Thread Starter 
Thanks everyone! and ughh. It is always those little frustrating errors...
post #6 of 7
Sorry for the confusion, I always seem to relate Java to Object Oriented Programming instead of Procedimental Programming, since that's how I normally work with java, my bad tongue.gif

ColSanderz has a small mistake, if he does balance = balance + desposit(balance) would be the same as saying: balance = balance + balance + 505.22, which I don't think that's how you planned for it to work.
First Build
(17 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k @4.5Ghz Gigabyte Z68X-UD7 B3 MSI 6950 G.Skill Sniper 2x4GB 
Hard DriveHard DriveHard DriveCooling
Crucial M4 64GB Samsung SpinPoint 250GB Hitachi 1TB Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows Server 2012 Samsung S22B300 22' ViewSonic VA703B 17" CM Quickfire TK 
PowerCaseMouse
Corsair HX850 NZXT Phantom Mionix Naos 3200 
  hide details  
Reply
First Build
(17 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k @4.5Ghz Gigabyte Z68X-UD7 B3 MSI 6950 G.Skill Sniper 2x4GB 
Hard DriveHard DriveHard DriveCooling
Crucial M4 64GB Samsung SpinPoint 250GB Hitachi 1TB Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows Server 2012 Samsung S22B300 22' ViewSonic VA703B 17" CM Quickfire TK 
PowerCaseMouse
Corsair HX850 NZXT Phantom Mionix Naos 3200 
  hide details  
Reply
post #7 of 7
Thread Starter 
ahh. I see. Well thank you all now(: You each have an iou tongue.gif
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › [H] Blue Pelican Java Project Help