6 Replies - 299 Views - Last Post: 22 January 2013 - 10:54 AM Rate Topic: -----

#1 hambonie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 13-March 12

"illegal start of expression" errors in banking test program

Posted 22 January 2013 - 08:47 AM

I have an assignment to write an account management program that resembles and ATM. I have each component working fine but my instructor wants it to be menu based. i have created a menu with some else ifs but now the program will not compile.

//java 2
//11.3
//
//test account program
   
   import javax.swing.JOptionPane;
	import java.util.Date;
   public class TestAccount {
   public static void main(String[] args) {
      
         Account chkAct = new CheckingAccount(0303445, 0.00, 0.5, 500.00);
         Account savAct = new SavingsAccount(0404445, 0.00, 1.5);
			
		/////////////menu/////////////////////////
		
		String chs = JOptionPane.showInputDialog(null,
		"Enter Your Name: ", "Account Log In", JOptionPane.INFORMATION_MESSAGE);
		Customer customer = new Customer(chs);
		
		boolean menu = true;
		while(menu) {
		
			String choice = JOptionPane.showInputDialogu(null,
			customer.getCustomerName() + "'s Banking Options for " + customer.getDate() + "\n"
			+ "\n1. Savings Deposit"
			+ "\n2. Savings Withdrawal"
			+ "\n3. Checking Deposit"
			+ "\n4. Checking Withdrawal"
			+ "\n.5 Exit\n\n","Selection Menu", JOptionPane.INFORMATION_MESSAGE);
			
			
			 
		///////////////new account constants/////
      
         //Account chkAct = new CheckingAccount(0303445, 0.00, 0.5, 500.00);
         //Account savAct = new SavingsAccount(0404445, 0.00, 1.5);
         
      	///////////////////////checking deposit////////////////
			
			if(choice.equals("1")) {
       
         JOptionPane.showMessageDialog(null, "New Checking Account: \n" + chkAct, 
				"New Checking Account Information", JOptionPane.INFORMATION_MESSAGE);
          
         chkAct.deposit(Double.parseDouble(JOptionPane.showInputDialog(null, 
            "Deposit amount:\n" + chkAct, "Depositing Funds", JOptionPane.INFORMATION_MESSAGE)));
				
			JOptionPane.showMessageDialog(null, "Balance: \n" + chkAct, 
			"Checking Account Overview", JOptionPane.INFORMATION_MESSAGE);
	      
      	}
         //////////////checking withdraw//////
			
			else if(choice.equals("2")){
			
			
			
			JOptionPane.showMessageDialog(null, "New Checking Account: \n" + chkAct, 
				"New Checking Account Information", JOptionPane.INFORMATION_MESSAGE);
			
			chkAct.withdrawal(Double.parseDouble(JOptionPane.showInputDialog(null, 
            "Withdrawal amount:\n" + chkAct, "Withdrawing Funds", JOptionPane.INFORMATION_MESSAGE)));
			      		  
                     
         JOptionPane.showMessageDialog(null, "Balance: \n" + chkAct, 
			"Checking Account Overview", JOptionPane.INFORMATION_MESSAGE);
          
      	} 
      	/////////////////////////savings deposit/////////////////
			
			else if(choice.equals("3")) {
      
         JOptionPane.showMessageDialog(null, "New savings account: \n" + savAct, 
				"New Savings Account Information", JOptionPane.INFORMATION_MESSAGE);
          
         savAct.deposit(Double.parseDouble(JOptionPane.showInputDialog(null, 
            "Deposit amount:\n" + savAct, "Depositing Funds", JOptionPane.INFORMATION_MESSAGE)));
				
			JOptionPane.showMessageDialog(null, "Balance: \n" + savAct, 
				"Savings Account Overview", JOptionPane.INFORMATION_MESSAGE);
				
			}	
				
			//////////savings	withdraw//////////////
			
			else if (choice.equals("4")) {
			
			JOptionPane.showMessageDialog(null, "New savings account: \n" + savAct, 
				"New Savings Account Information", JOptionPane.INFORMATION_MESSAGE);
			      
      	
         savAct.withdrawal(Double.parseDouble(JOptionPane.showInputDialog(null, 
            "Withdrawal amount:\n" + savAct, "Withdrawing Funds", JOptionPane.INFORMATION_MESSAGE)));
      		  
                     
         JOptionPane.showMessageDialog(null, "Balance: \n" + savAct, 
				"Savings Account Overview", JOptionPane.INFORMATION_MESSAGE);   
         
      }
		
		/////////////////////exit////////////////////
		else if (choice.equals("5")) {
		
		JOptionPane.showMessageDialog(null,
		"Exiting Account", "EXIT", JOptionPane.INFORMATION_MESSAGE);
		menu = false;
		}
   	
   			
		//////////////invalid selection//////////////
		
		else { 
		JOptionPane.showMessageDialog(null,
		"INVALID SELECTION! \n\n Please Enter 1-5 ", "INVALID SELECTION WARNING", JOptionPane.INFORMATION_MESSAGE);
		}
		
		///////////////transactins/////////////////////
      
      public static void checkingWithdrawal(CheckingAccount chkAct, double amt) {
         chkAct.withdrawal(amt);
      }
      
      public static void savingsWithdrawal(SavingsAccount savAct, double amt) {
         savAct.withdrawal(amt);
      }
   
   }}}




I am receiving the following errors related to the last 4 lines of code
 ----jGRASP exec: javac -g TestAccount.java

TestAccount.java:119: error: illegal start of expression
      public static void checkingWithdrawal(CheckingAccount chkAct, double amt) {
      ^
TestAccount.java:119: error: illegal start of expression
      public static void checkingWithdrawal(CheckingAccount chkAct, double amt) {
             ^
TestAccount.java:119: error: ';' expected
      public static void checkingWithdrawal(CheckingAccount chkAct, double amt) {
                   ^
TestAccount.java:119: error: ')' expected
      public static void checkingWithdrawal(CheckingAccount chkAct, double amt) {
                                                           ^
TestAccount.java:119: error: illegal start of expression
      public static void checkingWithdrawal(CheckingAccount chkAct, double amt) {
                                                                  ^
TestAccount.java:119: error: ';' expected
      public static void checkingWithdrawal(CheckingAccount chkAct, double amt) {
                                                                   ^
TestAccount.java:119: error: not a statement
      public static void checkingWithdrawal(CheckingAccount chkAct, double amt) {
                                                                           ^
TestAccount.java:119: error: ';' expected
      public static void checkingWithdrawal(CheckingAccount chkAct, double amt) {
                                                                              ^
TestAccount.java:123: error: illegal start of expression
      public static void savingsWithdrawal(SavingsAccount savAct, double amt) {
      ^
TestAccount.java:123: error: illegal start of expression
      public static void savingsWithdrawal(SavingsAccount savAct, double amt) {
             ^
TestAccount.java:123: error: ';' expected
      public static void savingsWithdrawal(SavingsAccount savAct, double amt) {
                   ^
TestAccount.java:123: error: ')' expected
      public static void savingsWithdrawal(SavingsAccount savAct, double amt) {
                                                         ^
TestAccount.java:123: error: illegal start of expression
      public static void savingsWithdrawal(SavingsAccount savAct, double amt) {
                                                                ^
TestAccount.java:123: error: ';' expected
      public static void savingsWithdrawal(SavingsAccount savAct, double amt) {
                                                                 ^
TestAccount.java:123: error: not a statement
      public static void savingsWithdrawal(SavingsAccount savAct, double amt) {
                                                                         ^
TestAccount.java:123: error: ';' expected
      public static void savingsWithdrawal(SavingsAccount savAct, double amt) {
                                                                            ^
16 errors

 ----jGRASP wedge2: exit code for process is 1.
 ----jGRASP: operation complete.



Is This A Good Question/Topic? 0
  • +

Replies To: "illegal start of expression" errors in banking test program

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2194
  • View blog
  • Posts: 5,222
  • Joined: 10-September 10

Re: "illegal start of expression" errors in banking test program

Posted 22 January 2013 - 08:54 AM

Your last two methods are not only declared inside another method, main(), but inside a while loop.

Move those two methods outside the main() method so that they are at the same level as the main() method.

Stacking the close braces all on one line as you've done at the end is a bad practice. Spread them out to different lines and indent your code properly.
Was This Post Helpful? 1
  • +
  • -

#3 hambonie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 13-March 12

Re: "illegal start of expression" errors in banking test program

Posted 22 January 2013 - 09:06 AM

View PostGregBrannon, on 22 January 2013 - 08:54 AM, said:

Your last two methods are not only declared inside another method, main(), but inside a while loop.

Move those two methods outside the main() method so that they are at the same level as the main() method.

Stacking the close braces all on one line as you've done at the end is a bad practice. Spread them out to different lines and indent your code properly.



i am confused about how to do this. i added a brace after the while loop as an attempt to get the final 4 lines out of the loop. but i am still getting errors
//java 2
//11.3
//by taddei
//test account program2
   
   import javax.swing.JOptionPane;
	import java.util.Date;
   public class TestAccount {
   public static void main(String[] args) {
      
         Account chkAct = new CheckingAccount(0303445, 0.00, 0.5, 500.00);
         Account savAct = new SavingsAccount(0404445, 0.00, 1.5);
			
		/////////////menu/////////////////////////
		
		String chs = JOptionPane.showInputDialog(null,
		"Enter Your Name: ", "Account Log In", JOptionPane.INFORMATION_MESSAGE);
		Customer customer = new Customer(chs);
		
		boolean menu = true;
		while(menu) {
		
			String choice = JOptionPane.showInputDialogu(null,
			customer.getCustomerName() + "'s Banking Options for " + customer.getDate() + "\n"
			+ "\n1. Savings Deposit"
			+ "\n2. Savings Withdrawal"
			+ "\n3. Checking Deposit"
			+ "\n4. Checking Withdrawal"
			+ "\n.5 Exit\n\n","Selection Menu", JOptionPane.INFORMATION_MESSAGE);
			
			
			 
		///////////////new account constants/////
      
         //Account chkAct = new CheckingAccount(0303445, 0.00, 0.5, 500.00);
         //Account savAct = new SavingsAccount(0404445, 0.00, 1.5);
         
      	///////////////////////checking deposit////////////////
			
			if(choice.equals("1")) {
       
         JOptionPane.showMessageDialog(null, "New Checking Account: \n" + chkAct, 
				"New Checking Account Information", JOptionPane.INFORMATION_MESSAGE);
          
         chkAct.deposit(Double.parseDouble(JOptionPane.showInputDialog(null, 
            "Deposit amount:\n" + chkAct, "Depositing Funds", JOptionPane.INFORMATION_MESSAGE)));
				
			JOptionPane.showMessageDialog(null, "Balance: \n" + chkAct, 
			"Checking Account Overview", JOptionPane.INFORMATION_MESSAGE);
	      
      	}
         //////////////checking withdraw//////
			
			else if(choice.equals("2")){
			
			
			
			JOptionPane.showMessageDialog(null, "New Checking Account: \n" + chkAct, 
				"New Checking Account Information", JOptionPane.INFORMATION_MESSAGE);
			
			chkAct.withdrawal(Double.parseDouble(JOptionPane.showInputDialog(null, 
            "Withdrawal amount:\n" + chkAct, "Withdrawing Funds", JOptionPane.INFORMATION_MESSAGE)));
			      		  
                     
         JOptionPane.showMessageDialog(null, "Balance: \n" + chkAct, 
			"Checking Account Overview", JOptionPane.INFORMATION_MESSAGE);
          
      	} 
      	/////////////////////////savings deposit/////////////////
			
			else if(choice.equals("3")) {
      
         JOptionPane.showMessageDialog(null, "New savings account: \n" + savAct, 
				"New Savings Account Information", JOptionPane.INFORMATION_MESSAGE);
          
         savAct.deposit(Double.parseDouble(JOptionPane.showInputDialog(null, 
            "Deposit amount:\n" + savAct, "Depositing Funds", JOptionPane.INFORMATION_MESSAGE)));
				
			JOptionPane.showMessageDialog(null, "Balance: \n" + savAct, 
				"Savings Account Overview", JOptionPane.INFORMATION_MESSAGE);
				
			}	
				
			//////////savings	withdraw//////////////
			
			else if (choice.equals("4")) {
			
			JOptionPane.showMessageDialog(null, "New savings account: \n" + savAct, 
				"New Savings Account Information", JOptionPane.INFORMATION_MESSAGE);
			      
      	
         savAct.withdrawal(Double.parseDouble(JOptionPane.showInputDialog(null, 
            "Withdrawal amount:\n" + savAct, "Withdrawing Funds", JOptionPane.INFORMATION_MESSAGE)));
      		  
                     
         JOptionPane.showMessageDialog(null, "Balance: \n" + savAct, 
				"Savings Account Overview", JOptionPane.INFORMATION_MESSAGE);   
         
      }
		
		/////////////////////exit////////////////////
		else if (choice.equals("5")) {
		
		JOptionPane.showMessageDialog(null,
		"Exiting Account", "EXIT", JOptionPane.INFORMATION_MESSAGE);
		menu = false;
		}
   	
   			
		//////////////invalid selection//////////////
		
		else { 
		JOptionPane.showMessageDialog(null,
		"INVALID SELECTION! \n\n Please Enter 1-5 ", "INVALID SELECTION WARNING", JOptionPane.INFORMATION_MESSAGE);
		}
		////i added this brace...is this what you mean 
		}//<---
		///////////////transactins/////////////////////
      
      public static void checkingWithdrawal(CheckingAccount chkAct, double amt) {
         chkAct.withdrawal(amt);
      }
      
      public static void savingsWithdrawal(SavingsAccount savAct, double amt) {
         savAct.withdrawal(amt);
      }
   
}
}
   



I am still getting the following errors:
----jGRASP exec: javac -g TestAccount.java

TestAccount.java:120: error: illegal start of expression
      public static void checkingWithdrawal(CheckingAccount chkAct, double amt) {
      ^
TestAccount.java:120: error: illegal start of expression
      public static void checkingWithdrawal(CheckingAccount chkAct, double amt) {
             ^
TestAccount.java:120: error: ';' expected
      public static void checkingWithdrawal(CheckingAccount chkAct, double amt) {
                   ^
TestAccount.java:120: error: ')' expected
      public static void checkingWithdrawal(CheckingAccount chkAct, double amt) {
                                                           ^
TestAccount.java:120: error: illegal start of expression
      public static void checkingWithdrawal(CheckingAccount chkAct, double amt) {
                                                                  ^
TestAccount.java:120: error: ';' expected
      public static void checkingWithdrawal(CheckingAccount chkAct, double amt) {
                                                                   ^
TestAccount.java:120: error: not a statement
      public static void checkingWithdrawal(CheckingAccount chkAct, double amt) {
                                                                           ^
TestAccount.java:120: error: ';' expected
      public static void checkingWithdrawal(CheckingAccount chkAct, double amt) {
                                                                              ^
TestAccount.java:124: error: illegal start of expression
      public static void savingsWithdrawal(SavingsAccount savAct, double amt) {
      ^
TestAccount.java:124: error: illegal start of expression
      public static void savingsWithdrawal(SavingsAccount savAct, double amt) {
             ^
TestAccount.java:124: error: ';' expected
      public static void savingsWithdrawal(SavingsAccount savAct, double amt) {
                   ^
TestAccount.java:124: error: ')' expected
      public static void savingsWithdrawal(SavingsAccount savAct, double amt) {
                                                         ^
TestAccount.java:124: error: illegal start of expression
      public static void savingsWithdrawal(SavingsAccount savAct, double amt) {
                                                                ^
TestAccount.java:124: error: ';' expected
      public static void savingsWithdrawal(SavingsAccount savAct, double amt) {
                                                                 ^
TestAccount.java:124: error: not a statement
      public static void savingsWithdrawal(SavingsAccount savAct, double amt) {
                                                                         ^
TestAccount.java:124: error: ';' expected
      public static void savingsWithdrawal(SavingsAccount savAct, double amt) {
                                                                            ^
16 errors

 ----jGRASP wedge2: exit code for process is 1.
 ----jGRASP: operation complete.


Was This Post Helpful? 0
  • +
  • -

#4 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2194
  • View blog
  • Posts: 5,222
  • Joined: 10-September 10

Re: "illegal start of expression" errors in banking test program

Posted 22 January 2013 - 09:15 AM

The closing brace you added moved the methods outside of the while loop, up one level. Add another closing brace after the one you already added to move the methods up another level to be outside the main() method and at the same level as the main() method. Of course you'll have to remove a closing brace from the end to keep the open and close braces even.
Was This Post Helpful? 1
  • +
  • -

#5 hambonie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 13-March 12

Re: "illegal start of expression" errors in banking test program

Posted 22 January 2013 - 10:20 AM

WOW! that got me down from 17 to 2 errors. Do you have any suggestions?
Remaining errors:
----jGRASP exec: javac -g TestAccount.java

TestAccount.java:18: error: cannot find symbol
		Customer customer = new Customer(chs);
		^
  symbol:   class Customer
  location: class TestAccount
TestAccount.java:18: error: cannot find symbol
		Customer customer = new Customer(chs);
		                        ^
  symbol:   class Customer
  location: class TestAccount
2 errors

 ----jGRASP wedge2: exit code for process is 1.
 ----jGRASP: operation complete.


Was This Post Helpful? 0
  • +
  • -

#6 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2194
  • View blog
  • Posts: 5,222
  • Joined: 10-September 10

Re: "illegal start of expression" errors in banking test program

Posted 22 January 2013 - 10:31 AM

It looks like you've resolved the format errors, but now the compiler doesn't know what the Customer type is. You haven't posted it, but do you have a Customer class in the same folder as the TestAccount and Account classes?
Was This Post Helpful? 1
  • +
  • -

#7 hambonie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 13-March 12

Re: "illegal start of expression" errors in banking test program

Posted 22 January 2013 - 10:54 AM

thanks so much. that was the problem. i made reference to a class that did not exist. i fixed it by eliminating the customer class and just using the account class:
//java 2
//11.3
//by taddei
//test account program2
   
   import javax.swing.JOptionPane;
	import java.util.Date;
   public class TestAccount {
   public static void main(String[] args) {
      
         Account chkAct = new CheckingAccount(0303445, 0.00, 0.5, 500.00);
         Account savAct = new SavingsAccount(0404445, 0.00, 1.5);
			
		/////////////menu/////////////////////////
		
		String chs = JOptionPane.showInputDialog(null,
		"Enter Your Name: ", "Account Log In", JOptionPane.INFORMATION_MESSAGE);
		//Account account = new Account(chs);
		
		
		boolean menu = true;
		while(menu) {
		
			String choice = JOptionPane.showInputDialog(null,
			//account.getNumber() + "'s Banking Options for " + account.getDate() + "\n"
			"Please make a selectiion\n" 
			+ "\n1. Savings Deposit"
			+ "\n2. Savings Withdrawal"
			+ "\n3. Checking Deposit"
			+ "\n4. Checking Withdrawal"
			+ "\n5. Exit\n\n","Selection Menu", JOptionPane.INFORMATION_MESSAGE);
			
			
			 
		///////////////new account constants/////
      
         //Account chkAct = new CheckingAccount(0303445, 0.00, 0.5, 500.00);
         //Account savAct = new SavingsAccount(0404445, 0.00, 1.5);
         
      	///////////////////////checking deposit////////////////
			
			if(choice.equals("1")) {
       
         JOptionPane.showMessageDialog(null, "New Checking Account: \n" + chkAct, 
				"New Checking Account Information", JOptionPane.INFORMATION_MESSAGE);
          
         chkAct.deposit(Double.parseDouble(JOptionPane.showInputDialog(null, 
            "Deposit amount:\n" + chkAct, "Depositing Funds", JOptionPane.INFORMATION_MESSAGE)));
				
			JOptionPane.showMessageDialog(null, "Balance: \n" + chkAct, 
			"Checking Account Overview", JOptionPane.INFORMATION_MESSAGE);
	      
      	}
         //////////////checking withdraw//////
			
			else if(choice.equals("2")){
			
			
			
			JOptionPane.showMessageDialog(null, "New Checking Account: \n" + chkAct, 
				"New Checking Account Information", JOptionPane.INFORMATION_MESSAGE);
			
			chkAct.withdrawal(Double.parseDouble(JOptionPane.showInputDialog(null, 
            "Withdrawal amount:\n" + chkAct, "Withdrawing Funds", JOptionPane.INFORMATION_MESSAGE)));
			      		  
                     
         JOptionPane.showMessageDialog(null, "Balance: \n" + chkAct, 
			"Checking Account Overview", JOptionPane.INFORMATION_MESSAGE);
          
      	} 
      	/////////////////////////savings deposit/////////////////
			
			else if(choice.equals("3")) {
      
         JOptionPane.showMessageDialog(null, "New savings account: \n" + savAct, 
				"New Savings Account Information", JOptionPane.INFORMATION_MESSAGE);
          
         savAct.deposit(Double.parseDouble(JOptionPane.showInputDialog(null, 
            "Deposit amount:\n" + savAct, "Depositing Funds", JOptionPane.INFORMATION_MESSAGE)));
				
			JOptionPane.showMessageDialog(null, "Balance: \n" + savAct, 
				"Savings Account Overview", JOptionPane.INFORMATION_MESSAGE);
				
			}	
				
			//////////savings	withdraw//////////////
			
			else if (choice.equals("4")) {
			
			JOptionPane.showMessageDialog(null, "New savings account: \n" + savAct, 
				"New Savings Account Information", JOptionPane.INFORMATION_MESSAGE);
			      
      	
         savAct.withdrawal(Double.parseDouble(JOptionPane.showInputDialog(null, 
            "Withdrawal amount:\n" + savAct, "Withdrawing Funds", JOptionPane.INFORMATION_MESSAGE)));
      		  
                     
         JOptionPane.showMessageDialog(null, "Balance: \n" + savAct, 
				"Savings Account Overview", JOptionPane.INFORMATION_MESSAGE);   
         
      }
		
		/////////////////////exit////////////////////
		else if (choice.equals("5")) {
		
		JOptionPane.showMessageDialog(null,
		"Exiting Account", "EXIT", JOptionPane.INFORMATION_MESSAGE);
		menu = false;
		}
   	
   			
		//////////////invalid selection//////////////
		
		else { 
		JOptionPane.showMessageDialog(null,
		"INVALID SELECTION! \n\n Please Enter 1-5 ", "INVALID SELECTION WARNING", JOptionPane.INFORMATION_MESSAGE);
		}
		////i added this brace...is this what you mean 
		}//<---
		}
		///////////////transactins/////////////////////
      
      public static void checkingWithdrawal(CheckingAccount chkAct, double amt) {
         chkAct.withdrawal(amt);
      }
      
      public static void savingsWithdrawal(SavingsAccount savAct, double amt) {
         savAct.withdrawal(amt);
      }
   
}

   





Was This Post Helpful? 0
  • +
  • -

Page 1 of 1