Results 1 to 10 of 10
  1. #1
    joel7 is offline Member
    Join Date
    Nov 2012
    Posts
    22
    Rep Power
    0

    Default error: ')' expected java

    Java Code:
    import java.util.Scanner;
    public class Testing {
    
        public static void main(String[] args){
        	Scanner input = new Scanner(System.in);
    
        	String bkId = null;
    		String bkTitle = null;
    		String bkPublisher = null;
    		String bkAuthor = null;
    
    		String mgId = null;
    		String mgTitle = null;
    		String mgPublisher = null;
    		String mgDate1 = null;
    
    		String npId = null;
    		String npTitle = null;
    		String npPublisher = null;
    		String npDate2 = null;
    
    		int chooseMenu,booksAdd,displayItem;
    
        	System.out.println("<><><><><>Welcome to KDU UC Library Management System<><><><><>");
        	System.out.println("\n1.Add Books \n2.Display Books \n3.Search Books");
        	chooseMenu = input.nextInt();
    
        	switch(chooseMenu){
        		case 1:
        			System.out.println("\n1.Add Books \n2.Add Megazine \n3.Add Newspaper");
        			booksAdd = input.nextInt();
    
        	    switch(booksAdd){
        		case 1:
        			Book[] addBooks = new Book[20];
    
        	    for(int a=0; a<10; a++){
        	    	addBooks[a] = new Book();
    	     	}
    
    	     	for(int a=0; a<10; a++){
    
        		System.out.println("Enter ID:");
        		bkId = input.nextLine();
    
        		for(int b=0;b<addBooks.length;b++){
    				while(addBooks[b].id.equals(bkId)){
    					System.out.println("Duplicate ID");
    					System.out.println("Enter ID for books "+(a+1) + ":");
    					bkId = input.nextLine();
    				}
    			}
    
        		System.out.println("Enter Title:");
        		bkTitle = input.nextLine();
    
        		System.out.println("Enter Publisher:");
        		bkPublisher = input.nextLine();
    
        		System.out.println("Enter Author:");
        		bkAuthor = input.nextLine();
    
        		addBooks[a] = new Book(bkId,bkTitle,bkPublisher,bkAuthor);
    
        	}
        	    case 2:
        		Megazine[] addMegazine = new Megazine[20];
    
        			for(int c=0; c<10; c++){
    			addMegazine[c] = new Megazine();
    		}
    
        	for(int c=0; c<10; c++){
    
        		System.out.println("Enter ID:");
        		mgId = input.nextLine();
    
        		for(int d=0;d<addMegazine.length;d++){
    				while(addMegazine[d].id.equals(mgId)){
    					System.out.println("Duplicate ID");
    					System.out.println("Enter ID for megazine "+(c+1) + ":");
    					mgId = input.nextLine();
    				}
    			}
    
        		System.out.println("Enter Title:");
        		mgTitle = input.nextLine();
    
        		System.out.println("Enter Publisher:");
        		mgPublisher = input.nextLine();
    
        		System.out.println("Enter Date:");
        		mgDate1 = input.nextLine();
    
        		addMegazine[c] = new Megazine(mgId,mgTitle,mgPublisher,mgDate1);
    
        	}
             	case 3:
        		Newspaper[] addNews = new Newspaper[20];
    
        		for(int e=0; e<10; e++){
    			addNews[e] = new Newspaper();
    		}
    
        	for(int e=0; e<10; e++){
    
        		System.out.println("Enter ID:");
        		npId = input.nextLine();
    
        		for(int f=0;f<addNews.length;f++){
    				while(addNews[f].id.equals(npId)){
    					System.out.println("Duplicate ID");
    					System.out.println("Enter ID for newspaper "+(e+1) + ":");
    					npId = input.nextLine();
    				}
    			}
    
        		System.out.println("Enter Title:");
        		npTitle = input.nextLine();
    
        		System.out.println("Enter Publisher:");
        		npPublisher = input.nextLine();
    
        		System.out.println("Enter Date:");
        		npDate2 = input.nextLine();
    
        		addNews[e] = new Newspaper(npId,npTitle,npPublisher,npDate2);
    
        	}
        	default:
        		System.out.println("Invalid");
        		break;
        	}
        	case 2:
        		System.out.println("\n1.Display Book\n2.Display Megazine\n3.Display Newspaper");
        		displayItem = input.nextInt();
    
        		switch(displayItem){
        			case 1:
        				for(int b=0;b<addBooks.length;b++){
                  	        System.out.println("\nBook Details" + (1+b) + "Book ID: " + addBooks[b].getId() + "\nBook Title: " + addBooks[b].getTitle() +
                  		                       "\nBook Publisher: " + addBooks[b].getPublisher() + "\nBook Author: " + addBooks[b].getAuthor());
                }
        	    break;
        	    case 2:
        	    	 for(int mg=0;mg<addMegazine.length;mg++){
    	                 System.out.println("\nMegazine Details" + (1+mg) + "Megazine ID: " + addMegazine[mg].getId() + "\nMegazine Title: " + addMegazine[mg].getTitle() +
    	            	                    "\nMegazine Publisher: " + addMegazine[mg].getPublisher() + "\nMegazine Date: " + addMegazine[mg].getDate1());
        	}
        	break;
        	case 3:
        		for(int np=0;np<addNews.length;np++){
                 	System.out.println("\nNewspaper Details" + (1+np) + "Newspaper ID: " + addNews[np].getId() + "\nNewspaper Title: " + addNews[np].getTitle() +
                 		               "\nNewspaper Publisher: " + addNews[np].getPublisher() + "\nNewspaper Date: " + addNews[np].getDate2();
                }
                break;
                default:
                	System.out.println("Invalid");
                	break;
         }
         default:
         	System.out.println("Invalid");
         	break;
       }
    }
    }

  2. #2
    joel7 is offline Member
    Join Date
    Nov 2012
    Posts
    22
    Rep Power
    0

    Default Re: error: ')' expected java

    error message :
    C:\Users\Joel\Desktop\Testing.java:154: error: ')' expected
    "\nNewspaper Publisher: " + addNews[np].getPublisher() + "\nNewspaper Date: " + addNews[np].getDate2();
    ^
    error: ')' expected

    can anyone solve or tell me what wrong with the code???

    p.s.
    asap

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,568
    Blog Entries
    7
    Rep Power
    21

    Default Re: error: ')' expected java

    Quote Originally Posted by joel7 View Post
    error message :
    error: ')' expected
    Come on; take a wild guess.

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    joel7 is offline Member
    Join Date
    Nov 2012
    Posts
    22
    Rep Power
    0

    Default Re: error: ')' expected java

    ok tell me jos

    where is tat error and what to replace ???

    tq
    ps.asap

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,044
    Rep Power
    20

    Default Re: error: ')' expected java

    Quote Originally Posted by joel7 View Post
    ps.asap
    Please stop asking that.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    joel7 is offline Member
    Join Date
    Nov 2012
    Posts
    22
    Rep Power
    0

    Default Re: error: ')' expected java

    ok toll
    u identify the problem of my code

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,044
    Rep Power
    20

    Default Re: error: ')' expected java

    Well, I could be wrong, but it looks to me like it's expecting a ')', which implies you are missing one somewhere on that line.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,568
    Blog Entries
    7
    Rep Power
    21

    Default Re: error: ')' expected java

    Quote Originally Posted by Tolls View Post
    Well, I could be wrong, but it looks to me like it's expecting a ')', which implies you are missing one somewhere on that line.
    Admit it; you're just guessing.

    kind regards,

    Jos ;-)
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,303
    Rep Power
    20

    Default Re: error: ')' expected java

    Quote Originally Posted by JosAH View Post
    Admit it; you're just guessing.

    kind regards,

    Jos ;-)
    Shouldn't the semicolon come after the closing parenthesis?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,568
    Blog Entries
    7
    Rep Power
    21

    Default Re: error: ')' expected java

    Quote Originally Posted by DarrylBurke View Post
    Shouldn't the semicolon come after the closing parenthesis?

    db
    Don't be so bourgeois; there's nothing wrong with descending ASCII (or Unicode) order; duh ...

    kindest regards,

    Jos ;-)
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. java error: ')' expected
    By joel7 in forum New To Java
    Replies: 2
    Last Post: 11-27-2012, 04:01 PM
  2. class interface or enum expected Imports java.io.*; error
    By prathamkool in forum New To Java
    Replies: 2
    Last Post: 10-02-2011, 04:53 PM
  3. '(' expected error in JAVA HELP!
    By eel in forum New To Java
    Replies: 1
    Last Post: 09-19-2010, 11:33 AM
  4. Replies: 0
    Last Post: 06-26-2009, 09:23 PM
  5. Error: myframe.java:26: ')' expected
    By barney in forum AWT / Swing
    Replies: 1
    Last Post: 07-31-2007, 07:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •