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

    Default java error: ')' expected

    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: java error: ')' expected

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

    wat is the problem????

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,373
    Blog Entries
    7
    Rep Power
    25

    Default Re: java error: ')' expected

    Don't double post. I'm closing this thread.

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. 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
  2. '(' expected error in JAVA HELP!
    By eel in forum New To Java
    Replies: 1
    Last Post: 09-19-2010, 11:33 AM
  3. Replies: 0
    Last Post: 06-26-2009, 09:23 PM
  4. Replies: 9
    Last Post: 11-23-2008, 12:03 AM
  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
  •