I am honestly stumped.

I need to Create a BankAccount class that has the following:

a) Instance variables for: name, accountNumber, balance, typeOfAccount
b) Accessor/mutator method for each instance variable (You will end up having 8 methods)
c) Create a displayAccountInfo() method that displays the account information as follows:

Account Type: <the account type>
Name: <account holder's name>
Account Number: <the account number>
Balance: $<balance> should display with formatting: $#,###.##

Create a BankAccountDriver class that does the following:

a) Create an instance of BankAccount
b) Prompt the user for the type of account, their name, account number (which we will auto-create later), and initial balance. After each prompt, call the correct mutator method on the instance to set that data.
c) Call the displayAccountInfo() method.

Be sure your runtime execution is similar to the following:

Name: John Doe
Account Type: Checking
Account Number: 123456
Account Balance: 5000

Hello John Doe, here is your account information:

Name: John Doe
Account Type: Checking
Account Number: 123456
Account Balance: $5,000.00

can anyone help me with this

Recommended Answers

All 41 Replies

We don't do homework but we do help when you've tried and get stuck. You shouldn't be stumped if this is homework because you would have done course work leading up to this.
Have you even managed to create the BankAccount class?
Post up hwat you've done so far and then, maybe, someone will help.

Always post your code of what you've done so far when you say you're stuck or not sure what to do next. We can't help you if we haven't seen what you've done so far and give you guidance on corrections and on what to do next.

As hericles said, post back with the complete code and someone should be able to help us, including me.

I havent even started the code :/ nor have i created the class. ive been out sick for the first week of class, and i havent taken a programming class in over a year.

Watch a few java tutorial videos, get the knowledge back of basic things, syntax, formatting, etc until you feel comfortable with it. Then write what you can till you get stuck, then come back and post what you've done.

 */
 class is BankAccount
 */
 public class BankAccount
 {
 private static int nextAccountNumber = 123456;
 private static int balance = 5000;
 public static int tpyeofaccount = checking;
 {

this is what ive got so far but i dont understand how i would use mutator or accessors or how to create a display

Mutators and accessors are simply ways of accessing and/or changing the private variables instead of accessing them directly.

So, instead of having BankAccount.balance = 20000 you would have a method in the class that sets the value (generally these methods start with get and set so their use is obvious).
E.g.
BankAccount.setBalance(20000);
and in the class a method setBalance that accepts the input and alters the private variable. So, in terms of your question the eight methods referred to would be the get/set for each private variable - one to set it and one to return it.

so what would just onr set look like? if i saw an example im sure id get it down

public void setBalance(int bal) { // double, float or decimal maybe?
   this.balance = bal;
}

setBalance() is then called by the class that creates and uses the BankAccount class.
Man, I'm a soft touch...

so something like this right?

    */
    class is BankAccount
    */
    public class BankAccount
    {
    private static int nextAccountNumber = 123456;
    private static int balance = 5000; 
    public static int tpyeofaccount = checking;
    {
    public void setBalance(int bal)
       this.balance = bal;
    public void setAccountNumber(int AccountNumber);
       this.Accountnumber = AccountNumber;
    public void settypeofaccount(int typeofaccount)
       this.typeofaccount(int typeofaccount)

Close but your

this.Accountnumber = AccountNumber;

needs to match the variable defined at the top of the class (nextAccountNumber) otherwise this.Accountnumber won't match anything.
I notice the specs say the amount needs to be formatted and includes decimal points so you'll need to switch away from int.

becuase im using decimals i would mark it as double then instead correct?

Yes, you can use double variables if there are decimal places in the data.

I hope you fixed what hericles referred to, next step is implement getters
public void getAccountNumber(){
return AccountNumber;}
so when getAccountNumber is called it would return the Account number of the object it was called by

Actually, I've not seen how the OP models his problem yet but rather jumps into programming. This will be very messy and clueless when it gets further and further; besides, this is a bad idea of teaching programming...

Before getting into programming, why not outline what you will be using in the BankAccount, BankAccountDriver classes? This step is a way to understand the problem and relate to programming (concept). At least, define what constructor/variables/methods should be in the class without filling any method definition (follow your problem instruction). This step may even be pseudo code. Once you get it all done, you can then start coding using the instruction and you will be able to easily fill all requirement...

how do i outline it? like im honestly confused on the whole thing

Taywin is referring to at least outlining the classes you will need, either is pseudo code (which a close approxmation of code but written to give you an overview and clarity) or something even more basic. You would end up with skeleton classes that, as a minimum, showed the variables and methods needed by each class, method signatures, parameters and return types, etc so you could know your proposed solution addresses the problem.

again im confused. im sorry im a bit illiterate here.

Well, to be honest, that approach isn't really needed for something like this. You're dealing with two fairly simple classes with limited interaction. I tend to jump start into projects like that.

So, lets recap. Where are you at now?
Do you have your BankAccount class done, with the needed private variables and getter/setters for each?

Yes. The orignal project description explains exactly what the structure is, and lists all the variables, methods etc, in the right order, so there's no need for any further outlining or design in this case.

 */
    class is BankAccount
    */
    public class BankAccount
    {
    private static int name = John Doe
    private static double nextAccountNumber = 123456;
    private static int balance = 5000;
    public static int tpyeofaccount = checking;
    {
    public void setname(int name);
    this.name = name
    public void setBalance(int bal);
    this.balance = bal;
    public void setAccountNumber(int AccountNumber);
    this.nextAccountnumber =nextAccountNumber;
    public void settypeofaccount(double typeofaccount)
    this.typeofaccount(int typeofaccount)

this is what i have so far. i think it covers the first part correct?

You should try compiling ypour code. The compiler will give you lots of messages that will tell you exactly what your errors are.

i did and i dont quite understand what the errors mean .-.

BankAccount.java:1: error: class, interface, or enum expected
*/
^
BankAccount.java:2: error: '{' expected
class is BankAccount

   BankAccount.java:1: error: class, interface, or enum expected
*/
^
BankAccount.java:2: error: '{' expected
class is BankAccount
        ^
BankAccount.java:6: error: ';' expected
private static int name = John Doe
                              ^
BankAccount.java:6: error: <identifier> expected
private static int name = John Doe
                                  ^
BankAccount.java:11: error: illegal start of expression
public void setname(int name);
^
BankAccount.java:11: error: illegal start of expression
public void setname(int name);
       ^
BankAccount.java:11: error: ';' expected
public void setname(int name);
                   ^
BankAccount.java:11: error: ';' expected
public void setname(int name);
                            ^
BankAccount.java:12: error: ';' expected
this.name = name
                ^
BankAccount.java:13: error: illegal start of expression
public void setBalance(int bal);
^
BankAccount.java:13: error: ';' expected
public void setBalance(int bal);
      ^
BankAccount.java:13: error: '.class' expected
public void setBalance(int bal);
                           ^
BankAccount.java:13: error: ';' expected
public void setBalance(int bal);
                              ^
BankAccount.java:15: error: illegal start of expression
public void setAccountNumber(int AccountNumber);
^
BankAccount.java:15: error: illegal start of expression
public void setAccountNumber(int AccountNumber);
       ^
BankAccount.java:15: error: ';' expected
public void setAccountNumber(int AccountNumber);
                            ^
BankAccount.java:15: error: ';' expected
public void setAccountNumber(int AccountNumber);
                                              ^
BankAccount.java:17: error: illegal start of expression
public void settypeofaccount(double typeofaccount)
^
BankAccount.java:17: error: illegal start of expression
public void settypeofaccount(double typeofaccount)
       ^
BankAccount.java:17: error: ';' expected
public void settypeofaccount(double typeofaccount)
                            ^
BankAccount.java:17: error: ';' expected
public void settypeofaccount(double typeofaccount)
                                                 ^
BankAccount.java:18: error: '.class' expected
this.typeofaccount(int typeofaccount)
                       ^
BankAccount.java:18: error: ';' expected
this.typeofaccount(int typeofaccount)
                                    ^
BankAccount.java:18: error: reached end of file while parsing
this.typeofaccount(int typeofaccount)
                                     ^
BankAccount.java:19: error: reached end of file while parsing
25 errors     ^

To make a comment you have to do

/*
 Some comment here
 */

and not to do

*/
Some comment here
*/

Also most of the errors are rather self-explenatory and you should be able to fix them easily

alright i fixed the errors and got the first part to commpile, now can someone explain the second part to me?

this.name = name
  1. Every statement in java ends with a semi colon.
  2. You need to enclose statements of a method in curly braces.
  3. Enclosing multiple statements in a curly braces creates a block of code and you don't need to put semi colon after a block of code.

Example :

public int methodName(){
    // statements;
}

And you might wanna post the error messages after you update you code.

@iamcreasy you may want to read whole thread before posting because @shadowsrose1 said

alright i fixed the errors and got the first part to commpile, now can someone explain the second part to me?

yea the ony thing that is stumping me now is the second part. i think i have to use boolean for something but my instructor hasnt messaged me back and i honestly dont know where to go from here on it

By the "second port" do you mean the BankAccountDriver class? If so:

Start at the beginning and work through it one step at at time

Create a BankAccountDriver class...
yo have already created one class, so you know how to do that

... that does the following: a) Create an instance of BankAccount ...

do you know how to create an instance of a class? If not use Google to find a beginners tutorial that shows you how to do it

... b) Prompt the user for the type of account ...

do you know how to prompt the user and get a reply? If not look for a tutorial on the Scanner class

(etc)

ps: You don't need a boolean for any of this

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.