| | |
another little program needing help...
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2008
Posts: 11
Reputation:
Solved Threads: 0
Hey guys, I'm not sure if you can tell how long I've been registered by my status or something but I'm new obviously and having a little problem with an program I'm writing. I get an error message stating that
"The constructor bankofMark.mattsAccount(String, String, String, String, String, String, String,
String, String, String, String, String, String) is undefined"
The application has (or will have) 5 bank accounts and should allow me to make withdrawals and deposits only after you get into the account with a password if statement. Its incomplete at this time because I'm just trying to get my private attributes to show up first. Then I'll write the code to check for sufficient funds later. Anyways, any feedback would be much appreciated.
import java.io.*;
import java.text.*;
import javax.swing.*;
//Banking application that creates 5 accounts and allows them to make a deposit and withdrawal.
public class bankofMark
{//boClass
private String firstName;
private String lastName;
private String Address;
private String City;
private String State;
private String zipCode;
private String Id;
private String passWord;
private int ccLimit;
private double ccBalance;
private double caBalance;
private double saBalance;
private int pinNumber;
public bankofMark(String firstname, String lastname, String address, String city, String state, String zipcode, String id, String password,
int cclimit, double ccbalance, double cabalance, double sabalance, int pinnumber)//This is my constructor
{//boConstructor
firstName = firstname;
lastName = lastname;
Address = address;
City = city;
State = state;
zipCode = zipcode;
Id = id;
passWord = password;
ccLimit = cclimit;
ccBalance = ccbalance;
caBalance = cabalance;
saBalance = sabalance;
pinNumber = pinnumber;
}//eoConstructor
public String getfirstName(){return firstName;}
public void setfirstName(String a){firstName = a;}
public String getlastName(){return lastName;}
public void getlastName(String b){lastName = b;}
public String getaddress(){return Address;}
public void getaddress(String c){Address = c;}
public String getcity(){return City;}
public void getcity(String d){City = d;}
public String getstate(){return State;}
public void getstate(String e){State = e;}
public String getzipcode(){return zipCode;}
public void getzipcode(String f){zipCode = f;}
public String getid(){return Id;}
public void getid(String g){Id = g;}
public String getpassword(){return passWord;}
public void getpassword(String h){passWord = h;}
public int getcclimit(){return ccLimit;}
public void getcclimit(int i){ccLimit = i;}
public double getccbalance(){return ccBalance;}
public void getccbalance(double j){ccBalance = j;}
public double getcabalance(){return caBalance;}
public void getcabalance(double k){caBalance = k;}
public double getsabalance(){return saBalance;}
public void getsabalance(double l){saBalance = l;}
public int getpinnumber(){return pinNumber;}
public void getpinnumber(int m){pinNumber = m;}
public final class mattsAccount extends bankofMark
{
public mattsAccount(String firstname, String lastname, String address, String city, String state, String zipcode, String id,
String password, int cclimit, double ccbalance, double cabalance, double sabalance, int pinnumber)
{
super(firstname, lastname, address, city, state, zipcode, id, password, cclimit, ccbalance, cabalance, sabalance, pinnumber);
}
}
public static void main(String[] args) throws IOException
{//boMain
String Password;
int ID;
DecimalFormat num = new DecimalFormat(",###.00");
System.out.println("Hello and Welcome to Marks Bank.\n This application will allow you to access your account and HOPEFULLY allow you to make deposits and withdrawls");
BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in));
System.out.println();
//BO MATT DAMONS ACCOUNT
System.out.println("Which account are you trying to access:\n" + "1. MattD\n" + "2. BillG\n" + "3. MarkF");
ID = Integer.parseInt(userInput.readLine());
if (ID == 1)
{
System.out.println("Welcome Mr. Damon. Please Enter your Password (case sensitive)");
Password = (userInput.readLine());
if (Password.equals("Damon"))
{
System.out.println("This is your account information");
bankofMark mattsAccount = new mattsAccount
("Matt","Damon","2644 30th Street","Santa Monica","CA","90405","MattD","Damon","1000","400","500","200","1970")
System.out.println(mattsAccount.firstName + "" + mattsAccount.lastName + "" + mattsAccount.Address + "" + mattsAccount.City +
"" + mattsAccount.State + "" + mattsAccount.zipCode + "" + mattsAccount.Id + "" + mattsAccount.passWord + "" +
mattsAccount.ccLimit + "" + mattsAccount.ccBalance + "" + mattsAccount.caBalance + "" + mattsAccount.saBalance + "" +
mattsAccount.pinNumber);
/*this section is dedicated for withdrawing and (maybe) depositing if i can figure out the code to check for
sufficient funds. Then just repeat for the following accounts*/
}
else
{
System.out.println("Incorrect password");
}
}//EO MATT DAMONS ACCOUNT
else if (ID == 2)
{
System.out.println("Welcome Mr. Gates. Please Enter your Password (case sensitive)");
Password = (userInput.readLine());
if (Password.equals("Gates"))
System.out.println("congrats, your in");
else
{
System.out.println("Incorrect password");
}
}
else if (ID == 3)
System.out.println("Welcome Mr. Ferguson. Please Enter your Password");
else
System.out.println("This account does not exist");
}//eoMain
}//eoClass
"The constructor bankofMark.mattsAccount(String, String, String, String, String, String, String,
String, String, String, String, String, String) is undefined"
The application has (or will have) 5 bank accounts and should allow me to make withdrawals and deposits only after you get into the account with a password if statement. Its incomplete at this time because I'm just trying to get my private attributes to show up first. Then I'll write the code to check for sufficient funds later. Anyways, any feedback would be much appreciated.
import java.io.*;
import java.text.*;
import javax.swing.*;
//Banking application that creates 5 accounts and allows them to make a deposit and withdrawal.
public class bankofMark
{//boClass
private String firstName;
private String lastName;
private String Address;
private String City;
private String State;
private String zipCode;
private String Id;
private String passWord;
private int ccLimit;
private double ccBalance;
private double caBalance;
private double saBalance;
private int pinNumber;
public bankofMark(String firstname, String lastname, String address, String city, String state, String zipcode, String id, String password,
int cclimit, double ccbalance, double cabalance, double sabalance, int pinnumber)//This is my constructor
{//boConstructor
firstName = firstname;
lastName = lastname;
Address = address;
City = city;
State = state;
zipCode = zipcode;
Id = id;
passWord = password;
ccLimit = cclimit;
ccBalance = ccbalance;
caBalance = cabalance;
saBalance = sabalance;
pinNumber = pinnumber;
}//eoConstructor
public String getfirstName(){return firstName;}
public void setfirstName(String a){firstName = a;}
public String getlastName(){return lastName;}
public void getlastName(String b){lastName = b;}
public String getaddress(){return Address;}
public void getaddress(String c){Address = c;}
public String getcity(){return City;}
public void getcity(String d){City = d;}
public String getstate(){return State;}
public void getstate(String e){State = e;}
public String getzipcode(){return zipCode;}
public void getzipcode(String f){zipCode = f;}
public String getid(){return Id;}
public void getid(String g){Id = g;}
public String getpassword(){return passWord;}
public void getpassword(String h){passWord = h;}
public int getcclimit(){return ccLimit;}
public void getcclimit(int i){ccLimit = i;}
public double getccbalance(){return ccBalance;}
public void getccbalance(double j){ccBalance = j;}
public double getcabalance(){return caBalance;}
public void getcabalance(double k){caBalance = k;}
public double getsabalance(){return saBalance;}
public void getsabalance(double l){saBalance = l;}
public int getpinnumber(){return pinNumber;}
public void getpinnumber(int m){pinNumber = m;}
public final class mattsAccount extends bankofMark
{
public mattsAccount(String firstname, String lastname, String address, String city, String state, String zipcode, String id,
String password, int cclimit, double ccbalance, double cabalance, double sabalance, int pinnumber)
{
super(firstname, lastname, address, city, state, zipcode, id, password, cclimit, ccbalance, cabalance, sabalance, pinnumber);
}
}
public static void main(String[] args) throws IOException
{//boMain
String Password;
int ID;
DecimalFormat num = new DecimalFormat(",###.00");
System.out.println("Hello and Welcome to Marks Bank.\n This application will allow you to access your account and HOPEFULLY allow you to make deposits and withdrawls");
BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in));
System.out.println();
//BO MATT DAMONS ACCOUNT
System.out.println("Which account are you trying to access:\n" + "1. MattD\n" + "2. BillG\n" + "3. MarkF");
ID = Integer.parseInt(userInput.readLine());
if (ID == 1)
{
System.out.println("Welcome Mr. Damon. Please Enter your Password (case sensitive)");
Password = (userInput.readLine());
if (Password.equals("Damon"))
{
System.out.println("This is your account information");
bankofMark mattsAccount = new mattsAccount
("Matt","Damon","2644 30th Street","Santa Monica","CA","90405","MattD","Damon","1000","400","500","200","1970")
System.out.println(mattsAccount.firstName + "" + mattsAccount.lastName + "" + mattsAccount.Address + "" + mattsAccount.City +
"" + mattsAccount.State + "" + mattsAccount.zipCode + "" + mattsAccount.Id + "" + mattsAccount.passWord + "" +
mattsAccount.ccLimit + "" + mattsAccount.ccBalance + "" + mattsAccount.caBalance + "" + mattsAccount.saBalance + "" +
mattsAccount.pinNumber);
/*this section is dedicated for withdrawing and (maybe) depositing if i can figure out the code to check for
sufficient funds. Then just repeat for the following accounts*/
}
else
{
System.out.println("Incorrect password");
}
}//EO MATT DAMONS ACCOUNT
else if (ID == 2)
{
System.out.println("Welcome Mr. Gates. Please Enter your Password (case sensitive)");
Password = (userInput.readLine());
if (Password.equals("Gates"))
System.out.println("congrats, your in");
else
{
System.out.println("Incorrect password");
}
}
else if (ID == 3)
System.out.println("Welcome Mr. Ferguson. Please Enter your Password");
else
System.out.println("This account does not exist");
}//eoMain
}//eoClass
First things first, it would be helpfull to set small chunks of code between the [ code ] [ /code] tags. Without the spaces that is.
Second: Could you please put your project up for download, unless you don't want that which I understand. I'm also pretty new, so I don't know what the guidelines are for that.
And now finally, for the problem:
Your problem lies within the defining of your object. Your constructor expects
Where you supply
("Matt","Damon","2644 30th Street","Santa Monica","CA","90405","MattD","Damon","1000","400","500","200","1970").
You are giving the values 1000, 400, 500 etc... as strings to your object. You need to give them as normal values. Just try to remove the " " around your doubles and int's
: ("Matt","Damon","2644 30th Street","Santa Monica","CA","90405","MattD","Damon",1000,400,500,200,1970)
I THINK that that could work, however it's been a while since I done java. There is a possibility that you'll have to parse your values to doubles and int's.
Hope this helps.
Second: Could you please put your project up for download, unless you don't want that which I understand. I'm also pretty new, so I don't know what the guidelines are for that.
And now finally, for the problem:
Your problem lies within the defining of your object. Your constructor expects
Java Syntax (Toggle Plain Text)
(String, String, String, String, String, String, String, String, int, double, double, double, int)
("Matt","Damon","2644 30th Street","Santa Monica","CA","90405","MattD","Damon","1000","400","500","200","1970").
You are giving the values 1000, 400, 500 etc... as strings to your object. You need to give them as normal values. Just try to remove the " " around your doubles and int's
: ("Matt","Damon","2644 30th Street","Santa Monica","CA","90405","MattD","Damon",1000,400,500,200,1970)
I THINK that that could work, however it's been a while since I done java. There is a possibility that you'll have to parse your values to doubles and int's.
Hope this helps.
•
•
Join Date: Mar 2008
Posts: 11
Reputation:
Solved Threads: 0
Thanks Jens for the input. I tried removing the "" around all the int and doubles and it removed my previous error and instead replaced it with this one. "Syntax error, insert ";" to complete LocalVariableDeclarationStatement" see attachment error1.jpg.
after i added ";" to the end of the statement, it then moved to this error message "No enclosing instance of type bankofMark is accessible. Must qualify the allocation with an
enclosing instance of type bankofMark (e.g. x.new A() where x is an instance of bankofMark)." see attachment error2.jpg
Any ideas?
also, I'm not sure how annoying this is but i reposted the entire code, this time using the code blocks you told me about.
after i added ";" to the end of the statement, it then moved to this error message "No enclosing instance of type bankofMark is accessible. Must qualify the allocation with an
enclosing instance of type bankofMark (e.g. x.new A() where x is an instance of bankofMark)." see attachment error2.jpg
Any ideas?
also, I'm not sure how annoying this is but i reposted the entire code, this time using the code blocks you told me about.
Java Syntax (Toggle Plain Text)
import java.io.*; import java.text.*; import javax.swing.*; //Banking application that creates 5 accounts and allows them to make a deposit and withdrawal. public class bankofMark {//boClass private String firstName; private String lastName; private String Address; private String City; private String State; private String zipCode; private String Id; private String passWord; private int ccLimit; private double ccBalance; private double caBalance; private double saBalance; private int pinNumber; public bankofMark(String firstname, String lastname, String address, String city, String state, String zipcode, String id, String password, int cclimit, double ccbalance, double cabalance, double sabalance, int pinnumber)//This is my constructor {//boConstructor firstName = firstname; lastName = lastname; Address = address; City = city; State = state; zipCode = zipcode; Id = id; passWord = password; ccLimit = cclimit; ccBalance = ccbalance; caBalance = cabalance; saBalance = sabalance; pinNumber = pinnumber; }//eoConstructor public String getfirstName(){return firstName;} public void setfirstName(String a){firstName = a;} public String getlastName(){return lastName;} public void getlastName(String b){lastName = b;} public String getaddress(){return Address;} public void getaddress(String c){Address = c;} public String getcity(){return City;} public void getcity(String d){City = d;} public String getstate(){return State;} public void getstate(String e){State = e;} public String getzipcode(){return zipCode;} public void getzipcode(String f){zipCode = f;} public String getid(){return Id;} public void getid(String g){Id = g;} public String getpassword(){return passWord;} public void getpassword(String h){passWord = h;} public int getcclimit(){return ccLimit;} public void getcclimit(int i){ccLimit = i;} public double getccbalance(){return ccBalance;} public void getccbalance(double j){ccBalance = j;} public double getcabalance(){return caBalance;} public void getcabalance(double k){caBalance = k;} public double getsabalance(){return saBalance;} public void getsabalance(double l){saBalance = l;} public int getpinnumber(){return pinNumber;} public void getpinnumber(int m){pinNumber = m;} public final class mattsAccount extends bankofMark { public mattsAccount(String firstname, String lastname, String address, String city, String state, String zipcode, String id, String password, int cclimit, double ccbalance, double cabalance, double sabalance, int pinnumber) { super(firstname, lastname, address, city, state, zipcode, id, password, cclimit, ccbalance, cabalance, sabalance, pinnumber); } } public static void main(String[] args) throws IOException {//boMain String Password; int ID; DecimalFormat num = new DecimalFormat(",###.00"); System.out.println("Hello and Welcome to Marks Bank.\n This application will allow you to access your account and HOPEFULLY allow you to make deposits and withdrawls"); BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in)); System.out.println(); //BO MATT DAMONS ACCOUNT System.out.println("Which account are you trying to access:\n" + "1. MattD\n" + "2. BillG\n" + "3. MarkF"); ID = Integer.parseInt(userInput.readLine()); if (ID == 1) { System.out.println("Welcome Mr. Damon. Please Enter your Password (case sensitive)"); Password = (userInput.readLine()); if (Password.equals("Damon")) { System.out.println("This is your account information"); bankofMark mattsAccount = new mattsAccount ("Matt","Damon","2644 30th Street","Santa Monica","CA","90405","MattD","Damon","1000","400","500","200","1970") System.out.println(mattsAccount.firstName + "" + mattsAccount.lastName + "" + mattsAccount.Address + "" + mattsAccount.City + "" + mattsAccount.State + "" + mattsAccount.zipCode + "" + mattsAccount.Id + "" + mattsAccount.passWord + "" + mattsAccount.ccLimit + "" + mattsAccount.ccBalance + "" + mattsAccount.caBalance + "" + mattsAccount.saBalance + "" + mattsAccount.pinNumber); /*this section is dedicated for withdrawing and (maybe) depositing if i can figure out the code to check for sufficient funds. Then just repeat for the following accounts*/ } else { System.out.println("Incorrect password"); } }//EO MATT DAMONS ACCOUNT else if (ID == 2) { System.out.println("Welcome Mr. Gates. Please Enter your Password (case sensitive)"); Password = (userInput.readLine()); if (Password.equals("Gates")) System.out.println("congrats, your in"); else { System.out.println("Incorrect password"); } } else if (ID == 3) System.out.println("Welcome Mr. Ferguson. Please Enter your Password"); else System.out.println("This account does not exist"); }//eoMain }//eoClass
•
•
Join Date: Mar 2008
Posts: 11
Reputation:
Solved Threads: 0
so I'm playing around and instead of:
bankofMark mattsAccount = new mattsAccount
i changed it to:
bankofMark mattsAccount = mattsAccount.new mattsAccount
I'm not sure if thats the proper syntax, but it just gives me an error now stating "The local variable mattsAccount may not have been initialized" I don't know the syntax for that problem. I'm not even sure if I'm on the right track.
bankofMark mattsAccount = new mattsAccount
i changed it to:
bankofMark mattsAccount = mattsAccount.new mattsAccount
I'm not sure if thats the proper syntax, but it just gives me an error now stating "The local variable mattsAccount may not have been initialized" I don't know the syntax for that problem. I'm not even sure if I'm on the right track.
•
•
Join Date: Mar 2008
Posts: 11
Reputation:
Solved Threads: 0
So after poking around more, i changed it to this:
This allows it to run but whenever i get to that point where it displays the account information, it crashes giving me this error message: "Exception in thread "main" java.lang.NullPointerException at bankofMark.main(bankofMark.java:99)"
Does this mean i need to parse?
Java Syntax (Toggle Plain Text)
System.out.println("This is your account information"); bankofMark mattsAccount = null; mattsAccount.new mattsAccount ("Matt","Damon","2644 30th Street","Santa Monica","CA","90405","MattD","Damon",1000,400,500,200,1970); System.out.println(mattsAccount.firstName + "" + mattsAccount.lastName + "" + mattsAccount.Address + "" + mattsAccount.City + "" + mattsAccount.State + "" + mattsAccount.zipCode + "" + mattsAccount.Id + "" + mattsAccount.passWord + "" + mattsAccount.ccLimit + "" + mattsAccount.ccBalance + "" + mattsAccount.caBalance + "" + mattsAccount.saBalance + "" + mattsAccount.pinNumber);
This allows it to run but whenever i get to that point where it displays the account information, it crashes giving me this error message: "Exception in thread "main" java.lang.NullPointerException at bankofMark.main(bankofMark.java:99)"
Does this mean i need to parse?
Last edited by krookedkop; Apr 2nd, 2008 at 3:29 pm.
I think that your object gets instantiated since you use the format bankofmark name = new bankofmark(constructor items);
But the problem lies in your constructor. You should add this. before each value in the constructorclass to declare that you are using the variable from that constructorclass.
It's all about scopes
so either
OR
even better and much much easier
To recapitulate (if that is the word in english).
Your objectcreation is possibly right, you just don't give a value to any of the fields.
Do this with this.
But the problem lies in your constructor. You should add this. before each value in the constructorclass to declare that you are using the variable from that constructorclass.
It's all about scopes

so either
Java Syntax (Toggle Plain Text)
mattsAccount.ccBalance = ccbalance;
even better and much much easier
Java Syntax (Toggle Plain Text)
this.ccBalance = ccbalance;
Java Syntax (Toggle Plain Text)
{//boConstructor firstName = firstname; lastName = lastname; Address = address; City = city; State = state; zipCode = zipcode; Id = id; passWord = password; ccLimit = cclimit; ccBalance = ccbalance; caBalance = cabalance; saBalance = sabalance; pinNumber = pinnumber; }//eoConstructor
To recapitulate (if that is the word in english).
Your objectcreation is possibly right, you just don't give a value to any of the fields.
Do this with this.
•
•
Join Date: Mar 2008
Posts: 11
Reputation:
Solved Threads: 0
My gosh Jens, thank you so much for your input on this program. I FINALLY got it to work with your help. When i read you last post it stated:
"I think that your object gets instantiated since you use the format bankofmark name = new bankofmark(constructor items);"
I read it and noticed that the example you gave wasn't the one i had in the code. I had this:
bankofMark mattsAccount = new mattsAccount<<<<this was the problem, it should be "bankofmark" not "mattsAccount"
I really appreciate all the help you've given me. Seemed like i was just talking to myself for a while there. Much props.
"I think that your object gets instantiated since you use the format bankofmark name = new bankofmark(constructor items);"
I read it and noticed that the example you gave wasn't the one i had in the code. I had this:
bankofMark mattsAccount = new mattsAccount<<<<this was the problem, it should be "bankofmark" not "mattsAccount"
I really appreciate all the help you've given me. Seemed like i was just talking to myself for a while there. Much props.
•
•
Join Date: Mar 2008
Posts: 11
Reputation:
Solved Threads: 0
Last thing btw,
you know the code for adding the deposit to the initial amount in the saBalance by chance?
I think its:
i declare that right above the main, but how do i return the balance inside the main?
you know the code for adding the deposit to the initial amount in the saBalance by chance?
I think its:
Java Syntax (Toggle Plain Text)
public bankofMark(double initialAmount) {saBalance = initialAmount;} public void deposit(double amount) {saBalance += amount;} public double getBalance() {return saBalance;}
i declare that right above the main, but how do i return the balance inside the main?
Last edited by krookedkop; Apr 2nd, 2008 at 5:08 pm.
![]() |
Similar Threads
- Login screen (Pascal and Delphi)
- Simple while loop in c++ (C++)
- Needing some help!!! (Perl)
- Newby girl needing desparate help (Java)
- needing help really fast (Pascal and Delphi)
- Running a program in a computer with no OS (C)
- Needing help with About:Blank XP SP1 (Viruses, Spyware and other Nasties)
Other Threads in the Java Forum
- Previous Thread: Help needed.
- Next Thread: scanner class and switch statments
Views: 1248 | Replies: 19
| Thread Tools | Search this Thread |
Tag cloud for Java
add android api apple applet application arguments array arrays automation bank binary bluetooth chat chooser class classes client code component converter database digit draw eclipse equation error event exception file fractal functiontesting game givemetehcodez graphics gui health helpwithhomework html hyper ide idea image infinite input int integer j2me java javame javaprojects jmf jni jpanel julia linux list loop main map method methods mobile myregfun netbeans newbie nonstatic number object oracle pattern pearl print problem program programming project recursion scanner screen scrollbar server set size sms socket sort spamblocker sql sqlserver string superclass swing test thread threads time transfer tree windows





