Okay, so I have a little assignment to do which needs some array of classes and calling various methods to get the job done. Essentially, I am looking to learn a bit through this program as well and the idea of it is to create a customer account, deposit, withdraw etc. I have written this code so far and I am getting the errors that I gave below. Please help me out in any way possible. And is var++ not an allowed option to increment a number in Java??
import java.util.*;
public class Bank
{
int cId;
String cName;
float cBalance;
}
class Banking
{
public static void main(String args[])
{
int limit=1;
System.out.println(+limit);
while (limit==1)
{
System.out.println("Menu:");
System.out.println("1. Add Customer");
System.out.println("2. View Customer Details");
System.out.println("3. Banking Options");
System.out.println("Enter choice:");
Scanner scan = new Scanner (System.in);
int i=scan.nextInt();
switch (i)
{
case 1:
{
System.out.println("Add the customer");
Customer();
}
/*case 2:
{
System.out.println("Customer details");
getCustomer();
}
case 3:
{
System.out.println("Banking options");
System.out.println("1. Deposit");
System.out.println("2. Withdraw");
System.out.println("3. Balance Enquiry");
Scanner scan1 = new Scanner (System.in);
int j=scan1.nextInt();
switch (j)
{
case 1:
{
System.out.println("Deposit");
deposit();
}
case 2:
{
System.out.println("Withdraw");
withdraw();
}
case 3:
{
System.out.println("Balance Enquiry");
balance();
}
}
}
} */
System.out.println("Enter 0 to exit or 1 to continue operations");
Scanner s = new Scanner (System.in);
limit=scan.nextInt();
}
}
}
}
public static void Customer (String []a)
{
int cust=0;
Bank c[cust] = new Bank();
System.out.println("Enter customer ID:");
Scanner scan11 = new Scanner (System.in);
int k=scan11.nextInt();
c[cust].cId=k;
System.out.println("Enter customer name:");
Scanner scan12 = new Scanner (System.in);
String name=scan12.next();
c[cust].cName=name;
System.out.println("Enter starting balance:");
Scanner scan132 = new Scanner (System.in);
float bal=scan132.nextFloat();
c[cust].cBalance=bal;
System.out.print("Customer id=" +c[cust].cId );
cust++;
}
}
And the errors are given here:
bank.java:73: class, interface, or enum expected
public static void Customer (String []a)
^
bank.java:76: class, interface, or enum expected
Bank c[cust] = new Bank();
^
bank.java:77: class, interface, or enum expected
System.out.println("Enter customer ID:");
^
bank.java:78: class, interface, or enum expected
Scanner scan11 = new Scanner (System.in);
^
bank.java:79: class, interface, or enum expected
int k=scan11.nextInt();
^
bank.java:80: class, interface, or enum expected
c[cust].cId=k;
^
bank.java:81: class, interface, or enum expected
System.out.println("Enter customer name:");
^
bank.java:82: class, interface, or enum expected
Scanner scan12 = new Scanner (System.in);
^
bank.java:83: class, interface, or enum expected
String name=scan12.next();
^
bank.java:84: class, interface, or enum expected
c[cust].cName=name;
^
bank.java:85: class, interface, or enum expected
System.out.println("Enter starting balance:");
^
bank.java:86: class, interface, or enum expected
Scanner scan132 = new Scanner (System.in);
^
bank.java:87: class, interface, or enum expected
float bal=scan132.nextFloat();
^
bank.java:88: class, interface, or enum expected
c[cust].cBalance=bal;
^
bank.java:90: class, interface, or enum expected
System.out.print("Customer id=" +c[cust].cId );
^
bank.java:91: class, interface, or enum expected
cust++;
^
bank.java:94: class, interface, or enum expected
}
^
17 errors
Thanks a lot guys!!
Regarding:
Usually this means look at the line above. You may be missing a semicolon or have too many or too few curly braces. Make sure that your curly braces line up exactly, and good code formatting and indentation will help you in doing this. By the way, your formatting is horrible and this is contributing to your not finding your errors.
This line:
Bank c[cust] = new Bank();makes no sense whatsoever. what are you trying to do here?
Most important: read the tutorials and learn the basics. Add small amounts of code at a time and compile frequently. Don’t add any new code until all compilation problems are solved, else you’ll end up with nothing more than a rat’s nest of errors.