Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: i cant find the error when insert while

  1. #1
    Junior Member
    Join Date
    Dec 2020
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default i cant find the error when insert while

    import java.util.*;

    public class Ship {

    //variables
    protected ArrayList<Container> Containers = new ArrayList<Container>();
    protected boolean more=true;

    ContainerCargo CC = new ContainerCargo("I1", "PEIRAEUS", 1);
    ContainerRefridgerator CR = new ContainerRefridgerator("I2", "PIRAEUS", 1);
    Scanner Keyboard = new Scanner(System.in);

    while (more) {
    System.out.println("What kind of ship do you want to add? 1: CARGO, 2: REFRIDGERATOR");
    int answer = Keyboard.nextInt();
    Keyboard.nextLine();
    int ship = 1;
    switch (ship) {
    case 1:
    System.out.println("You select CARGO conatiner");
    CC.printInfo();
    Containers.add(CC);
    break;
    case 2:
    System.out.println("You select REFRIGERATOR");
    CR.printinfo();
    Containers.add(CR);
    break;
    default:
    System.out.println("You didn't enlist other container");
    }
    Keyboard.nextLine();
    System.out.println("More container? (y/n)");
    String moreContainer = Keyboard.nextLine();
    if(moreContainer.equals("n"))
    more = false;
    }
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: i cant find the error when insert while

    Please copy the full text of the error message and paste it here. It has important info about the error.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    poulisdim (December 5th, 2020)

  4. #3
    Junior Member
    Join Date
    Dec 2020
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: i cant find the error when insert while

    import java.util.*;
     
    public class Ship  {
     
    	//variables
    	protected ArrayList<Container> Containers = new ArrayList<Container>();
    	protected boolean more=true;
     
    	ContainerCargo CC = new ContainerCargo("I1", "PEIRAEUS", 1);
    	ContainerRefridgerator CR = new ContainerRefridgerator("I2", "PIRAEUS", 1);
    	Scanner Keyboard = new Scanner(System.in);	
     
    	while (more) {
    	    System.out.println("What kind of ship do you want to add? 1: CARGO, 2: REFRIDGERATOR");
    		int answer = Keyboard.nextInt();
    		Keyboard.nextLine();
    		int ship = 1;
    			switch (ship) {
    				case 1:
    					System.out.println("You select CARGO conatiner");
    					CC.printInfo();
    					Containers.add(CC);
    					break;
    				case 2:
    					System.out.println("You select REFRIGERATOR");
    					CR.printinfo();
    					Containers.add(CR);
    					break;
    				default:
    					System.out.println("You didn't enlist other container");
    			}
    		Keyboard.nextLine();
    		System.out.println("More container? (y/n)");
    		String moreContainer = Keyboard.nextLine();
    		if(moreContainer.equals("n"))
    		more = false;	
    	} 
    }

    the error:
    Description Resource Path Location Type
    Syntax error on token ";", { expected after this token Ship.java /ContainerManagement/src line 11 Java Problem
    Syntax error, insert "}" to complete ClassBody Ship.java /ContainerManagement/src line 38 Java Problem

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: i cant find the error when insert while

    The statements after line 10 need to be inside of a method or constructor. They can not be at the class level.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Help me find the error here.
    By koolkirtzz in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 5th, 2013, 05:01 AM
  2. Exception Error on jps page to insert into database
    By Lcc_terri in forum Exceptions
    Replies: 1
    Last Post: February 13th, 2013, 09:09 AM
  3. Replies: 2
    Last Post: June 15th, 2011, 03:49 PM
  4. Replies: 1
    Last Post: June 11th, 2011, 05:39 AM
  5. Replies: 1
    Last Post: January 15th, 2010, 01:32 AM