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 5 of 5

Thread: What´s wron with this code?

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Location
    Stockholm
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default What´s wron with this code?

    import java.util.ArrayList;
    import java.util.Scanner;
     
    public class Prylregister {   
     
     
        Scanner tangentbord = new Scanner(System.in);
     
        public static void main(String[] args) {
            ArrayList<Pryl> allaPrylar = new ArrayList<Pryl>();
     
            ArrayList<Person> allaPersoner = new ArrayList<Person>();
            Scanner tangentbord = new Scanner(System.in);
     
            System.out.println("Hej och välkommen till Prylprogrammet! ");
            for(;;){
     
     
           System.out.print("1 Skapa person, 2 Skapa pryl, 3 Visa alla, 4 Visa rikaste, 5 Visa viss person,6 Börskrash, 7 Avsluta: ");
     
           int kommando = Integer.parseInt(tangentbord.nextLine());
           switch (kommando){
     
            case 1: System.out.print("Skapa person ");
            System.out.println("Ange namn: ");
            String namn = tangentbord.nextLine();
     
            for (int x = 0; x<allaPersoner.size(); x++){
                        if(allaPersoner.size()>0){
                       for(Person p : allaPersoner) {
                                if (p.getNamn().equalsIgnoreCase(namn)) {
                               System.out.println("Den personen finns redan ");
                           }
     
                              else { 
     
                                     allaPersoner.add(new Person(namn));
     
                            }
                            }
                      }
               }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,345
    Thanks
    49
    Thanked 2,200 Times in 2,173 Posts

    Default Re: What´s wron with this code?

    If there are errors you need to copy the full text and paste it here.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    14
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default Re: What´s wron with this code?

    as far as i can understand.. u missed a lots of '}'....
    also you declared Scanner object "tangentbord" twice.....
    assuming you have written Pryl and Person classes.....i couldn't find any more errors.

  4. #4
    Junior Member
    Join Date
    Jan 2013
    Location
    Stockholm
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What´s wron with this code?

    Thank you for your answer!
    In case 1 i want to register a person in arrayList if the person does not already exist but the code do nothing so far ?!

  5. #5
    Junior Member
    Join Date
    Nov 2012
    Posts
    14
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default Re: What´s wron with this code?

    dude... first post the code as Norm said...
    also post the errors.......

Similar Threads

  1. Trouble Porting my Java File Reading Code to Android Code
    By Gravity Games in forum Android Development
    Replies: 0
    Last Post: December 6th, 2012, 03:38 PM
  2. Replies: 5
    Last Post: November 14th, 2012, 09:47 AM
  3. Help needed - Embedding javascript code in JSP code.
    By chinnu in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: October 29th, 2012, 01:09 PM
  4. Replies: 3
    Last Post: September 3rd, 2012, 11:36 AM
  5. Code is giving an error in console, but there are no errors apparent in the code!
    By JamEngulfer221 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 15th, 2011, 08:30 PM