another little program needing help...

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2008
Posts: 11
Reputation: krookedkop is an unknown quantity at this point 
Solved Threads: 0
krookedkop krookedkop is offline Offline
Newbie Poster

another little program needing help...

 
0
  #1
Apr 2nd, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 11
Reputation: krookedkop is an unknown quantity at this point 
Solved Threads: 0
krookedkop krookedkop is offline Offline
Newbie Poster

Re: another little program needing help...

 
0
  #2
Apr 2nd, 2008
Sorry guys, i just noticed that its not really clear where the error lies. Its right after "//BO MATT DAMONS ACCOUNT" and 11 lines down.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 47
Reputation: Jens is an unknown quantity at this point 
Solved Threads: 5
Jens's Avatar
Jens Jens is offline Offline
Light Poster

Re: another little program needing help...

 
0
  #3
Apr 2nd, 2008
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
  1. (String, String, String, String, String, String, String,
  2. String, int, double, double, double, int)
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 11
Reputation: krookedkop is an unknown quantity at this point 
Solved Threads: 0
krookedkop krookedkop is offline Offline
Newbie Poster

Re: another little program needing help...

 
0
  #4
Apr 2nd, 2008
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.

  1. import java.io.*;
  2. import java.text.*;
  3. import javax.swing.*;
  4.  
  5. //Banking application that creates 5 accounts and allows them to make a deposit and withdrawal.
  6.  
  7. public class bankofMark
  8. {//boClass
  9. private String firstName;
  10. private String lastName;
  11. private String Address;
  12. private String City;
  13. private String State;
  14. private String zipCode;
  15. private String Id;
  16. private String passWord;
  17. private int ccLimit;
  18. private double ccBalance;
  19. private double caBalance;
  20. private double saBalance;
  21. private int pinNumber;
  22.  
  23. public bankofMark(String firstname, String lastname, String address, String city, String state, String zipcode, String id, String password,
  24. int cclimit, double ccbalance, double cabalance, double sabalance, int pinnumber)//This is my constructor
  25.  
  26. {//boConstructor
  27. firstName = firstname;
  28. lastName = lastname;
  29. Address = address;
  30. City = city;
  31. State = state;
  32. zipCode = zipcode;
  33. Id = id;
  34. passWord = password;
  35. ccLimit = cclimit;
  36. ccBalance = ccbalance;
  37. caBalance = cabalance;
  38. saBalance = sabalance;
  39. pinNumber = pinnumber;
  40. }//eoConstructor
  41.  
  42. public String getfirstName(){return firstName;}
  43. public void setfirstName(String a){firstName = a;}
  44. public String getlastName(){return lastName;}
  45. public void getlastName(String b){lastName = b;}
  46. public String getaddress(){return Address;}
  47. public void getaddress(String c){Address = c;}
  48. public String getcity(){return City;}
  49. public void getcity(String d){City = d;}
  50. public String getstate(){return State;}
  51. public void getstate(String e){State = e;}
  52. public String getzipcode(){return zipCode;}
  53. public void getzipcode(String f){zipCode = f;}
  54. public String getid(){return Id;}
  55. public void getid(String g){Id = g;}
  56. public String getpassword(){return passWord;}
  57. public void getpassword(String h){passWord = h;}
  58. public int getcclimit(){return ccLimit;}
  59. public void getcclimit(int i){ccLimit = i;}
  60. public double getccbalance(){return ccBalance;}
  61. public void getccbalance(double j){ccBalance = j;}
  62. public double getcabalance(){return caBalance;}
  63. public void getcabalance(double k){caBalance = k;}
  64. public double getsabalance(){return saBalance;}
  65. public void getsabalance(double l){saBalance = l;}
  66. public int getpinnumber(){return pinNumber;}
  67. public void getpinnumber(int m){pinNumber = m;}
  68.  
  69. public final class mattsAccount extends bankofMark
  70. {
  71. public mattsAccount(String firstname, String lastname, String address, String city, String state, String zipcode, String id,
  72. String password, int cclimit, double ccbalance, double cabalance, double sabalance, int pinnumber)
  73. {
  74. super(firstname, lastname, address, city, state, zipcode, id, password, cclimit, ccbalance, cabalance, sabalance, pinnumber);
  75. }
  76. }
  77.  
  78. public static void main(String[] args) throws IOException
  79. {//boMain
  80. String Password;
  81. int ID;
  82. DecimalFormat num = new DecimalFormat(",###.00");
  83.  
  84. 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");
  85. BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in));
  86. System.out.println();
  87.  
  88. //BO MATT DAMONS ACCOUNT
  89. System.out.println("Which account are you trying to access:\n" + "1. MattD\n" + "2. BillG\n" + "3. MarkF");
  90. ID = Integer.parseInt(userInput.readLine());
  91. if (ID == 1)
  92. {
  93. System.out.println("Welcome Mr. Damon. Please Enter your Password (case sensitive)");
  94. Password = (userInput.readLine());
  95. if (Password.equals("Damon"))
  96. {
  97. System.out.println("This is your account information");
  98. bankofMark mattsAccount = new mattsAccount
  99. ("Matt","Damon","2644 30th Street","Santa Monica","CA","90405","MattD","Damon","1000","400","500","200","1970")
  100. System.out.println(mattsAccount.firstName + "" + mattsAccount.lastName + "" + mattsAccount.Address + "" + mattsAccount.City +
  101. "" + mattsAccount.State + "" + mattsAccount.zipCode + "" + mattsAccount.Id + "" + mattsAccount.passWord + "" +
  102. mattsAccount.ccLimit + "" + mattsAccount.ccBalance + "" + mattsAccount.caBalance + "" + mattsAccount.saBalance + "" +
  103. mattsAccount.pinNumber);
  104.  
  105. /*this section is dedicated for withdrawing and (maybe) depositing if i can figure out the code to check for
  106. sufficient funds. Then just repeat for the following accounts*/
  107. }
  108. else
  109. {
  110. System.out.println("Incorrect password");
  111. }
  112. }//EO MATT DAMONS ACCOUNT
  113. else if (ID == 2)
  114. {
  115. System.out.println("Welcome Mr. Gates. Please Enter your Password (case sensitive)");
  116. Password = (userInput.readLine());
  117. if (Password.equals("Gates"))
  118. System.out.println("congrats, your in");
  119. else
  120. {
  121. System.out.println("Incorrect password");
  122. }
  123. }
  124. else if (ID == 3)
  125. System.out.println("Welcome Mr. Ferguson. Please Enter your Password");
  126. else
  127. System.out.println("This account does not exist");
  128. }//eoMain
  129.  
  130. }//eoClass
Attached Thumbnails
error1.jpg   error2.jpg  
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 11
Reputation: krookedkop is an unknown quantity at this point 
Solved Threads: 0
krookedkop krookedkop is offline Offline
Newbie Poster

Re: another little program needing help...

 
0
  #5
Apr 2nd, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 11
Reputation: krookedkop is an unknown quantity at this point 
Solved Threads: 0
krookedkop krookedkop is offline Offline
Newbie Poster

Re: another little program needing help...

 
0
  #6
Apr 2nd, 2008
So after poking around more, i changed it to this:
  1. System.out.println("This is your account information");
  2. bankofMark mattsAccount = null;
  3. mattsAccount.new mattsAccount
  4. ("Matt","Damon","2644 30th Street","Santa Monica","CA","90405","MattD","Damon",1000,400,500,200,1970);
  5. 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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 47
Reputation: Jens is an unknown quantity at this point 
Solved Threads: 5
Jens's Avatar
Jens Jens is offline Offline
Light Poster

Re: another little program needing help...

 
0
  #7
Apr 2nd, 2008
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
  1. mattsAccount.ccBalance = ccbalance;
OR
even better and much much easier
  1. this.ccBalance = ccbalance;

  1. {//boConstructor
  2. firstName = firstname;
  3. lastName = lastname;
  4. Address = address;
  5. City = city;
  6. State = state;
  7. zipCode = zipcode;
  8. Id = id;
  9. passWord = password;
  10. ccLimit = cclimit;
  11. ccBalance = ccbalance;
  12. caBalance = cabalance;
  13. saBalance = sabalance;
  14. pinNumber = pinnumber;
  15. }//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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 11
Reputation: krookedkop is an unknown quantity at this point 
Solved Threads: 0
krookedkop krookedkop is offline Offline
Newbie Poster

Re: another little program needing help...

 
0
  #8
Apr 2nd, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 47
Reputation: Jens is an unknown quantity at this point 
Solved Threads: 5
Jens's Avatar
Jens Jens is offline Offline
Light Poster

Re: another little program needing help...

 
0
  #9
Apr 2nd, 2008
Not a problem and glad I could help. We are here to learn .

Good luck coding
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 11
Reputation: krookedkop is an unknown quantity at this point 
Solved Threads: 0
krookedkop krookedkop is offline Offline
Newbie Poster

Re: another little program needing help...

 
0
  #10
Apr 2nd, 2008
Last thing btw,

you know the code for adding the deposit to the initial amount in the saBalance by chance?

I think its:

  1. public bankofMark(double initialAmount)
  2. {saBalance = initialAmount;}
  3.  
  4. public void deposit(double amount)
  5. {saBalance += amount;}
  6.  
  7. public double getBalance()
  8. {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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum


Views: 1248 | Replies: 19
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC