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

Thread: Help idk what's wrong

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    9
    My Mood
    Dead
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help idk what's wrong

    Im getting an error at line 45 it says identifier expected pls help


    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
     
    package million;
    import java.util.Scanner;
    import java.util.ArrayList;
     
     
     
    /**
     *
     * @author Ernie
     */
    public class Million {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logic here
            int Counter = 0;
            int mill = 0;
            getCustomers();
        }
     
      public static void getCustomers(){
          ArrayList details = new ArrayList();
          Scanner sc = new Scanner(System.in);
          System.out.println("Enter customer first and last name");
          details.add(sc.next());
          details.add(sc.next());
          System.out.println("Enter customer starting balance");
          details.add(sc.nextDouble());
          System.out.println("Enter customer start date");
          details.add(sc.nextInt());
          System.out.println("Enter customer account number");
          details.add(sc.nextInt());
          System.out.println("Customer account is as follows"+details);
          getDetails(details);
          }//end GetCustomers
     
        public static void getDetails(details){
          int sbal = 0;
          while (int mill = 1000000; sbal< mill; Counter++ ){
     
          }
     
      }//end getDetails*/
     
    }//end main


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,462
    My Mood
    Hungover
    Thanks
    144
    Thanked 639 Times in 547 Posts

    Default Re: Help idk what's wrong

    What is on line 45?

    Why does your while loop look like a for loop? Where are the variables in that loop defined?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member jdv's Avatar
    Join Date
    Jul 2014
    Location
    This Land
    Posts
    74
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Default Re: Help idk what's wrong

    This example does not compile because of multiple syntax errors.

    To answer your question, I'll ask my own: for the method signature
    public static void getDetails(details)
    what Java type is "details"?

  4. #4
    Junior Member
    Join Date
    Jun 2014
    Posts
    9
    My Mood
    Dead
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help idk what's wrong

    Thats the array list im trying to pass to the function

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,462
    My Mood
    Hungover
    Thanks
    144
    Thanked 639 Times in 547 Posts

    Default Re: Help idk what's wrong

    Quote Originally Posted by Aosora View Post
    Thats the array list im trying to pass to the function
    Where do you tell the getDetails function that it's an ArrayList?

    Recommended reading: Passing Information to a Method or a Constructor (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    Junior Member
    Join Date
    Jun 2014
    Posts
    9
    My Mood
    Dead
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help idk what's wrong

    Ok fixed how my code and got to pass the array list to my method but now i'm having assigning a element from the array list to a variable its line 47 hope you guys can help me it says "Object cannot be converted to int" and i know i declared that element as an integer its details.get(2)
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
     
    package million;
    import java.util.Scanner;
    import java.util.ArrayList;
     
     
     
    /**
     *
     * @author Ernie
     */
    public class Million {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logic here
            int Counter = 0;
            int mill = 0;
            getCustomers(Counter);
        }
     
      public static void getCustomers(int Counter){
          ArrayList details = new ArrayList();
          Scanner sc = new Scanner(System.in);
          System.out.println("Enter customer first and last name");
          details.add(sc.next());
          details.add(sc.next());
          System.out.println("Enter customer starting balance");
          details.add(sc.nextInt());
          System.out.println("Enter customer start date");
          details.add(sc.nextInt());
          System.out.println("Enter customer account number");
          details.add(sc.nextInt());
          System.out.println("Customer account is as follows"+details);
          getDetails(Counter, details);
          }//end GetCustomers
     
      public static void getDetails(int Counter,ArrayList details){
          int sbal;
          sbal = details.get(2) ; int mill= 1000000;
          while (mill>sbal||(mill!=sbal)){
              Counter = Counter+1;
              sbal = sbal*2;
              System.out.println(sbal);
          }
     
      }//end getDetails*/
     
    }//end main

  7. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,462
    My Mood
    Hungover
    Thanks
    144
    Thanked 639 Times in 547 Posts

    Default Re: Help idk what's wrong

    Your details variable is a raw (non-generic) ArrayList, so it doesn't know what kind of values it's holding. It could be Strings or JPanels or YourWidgets or something else. It doesn't "know" that the ArrayList holds ints (technically Integers).

    You either need to use generics or cast the value returned from the get() function. Google is your friend.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #8
    Member jdv's Avatar
    Join Date
    Jul 2014
    Location
    This Land
    Posts
    74
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Default Re: Help idk what's wrong

    What does ArrayList.get(int) return? Where are you storing the result? Do these types match?

    Hint: this is where you should be paying attention to the warnings your IDE is showing about your use of ArrayList (assuming you are using a recent release of Java).

    e.g., "ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized" will give you a small hint. There is also a one-line hack.

    Not doing the "hack" will require making sure that what you are putting IN the ArrayList is what you are expecting to get OUT.

    Hint: what does Scanner.next() return?
    Last edited by jdv; August 25th, 2014 at 01:43 PM.

  9. #9
    Junior Member
    Join Date
    Jun 2014
    Posts
    9
    My Mood
    Dead
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help idk what's wrong

    Ok i looked up generics and basically its to minimize errors and make code easier to read. I've also looked up some examples and i still don't get what i need to fix please can someone show me cuz apparently im pretty stiff and im so close to finishing my program please anyone this would help me out greatly also i would know what to do in other instances of this occuring.

  10. #10
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,462
    My Mood
    Hungover
    Thanks
    144
    Thanked 639 Times in 547 Posts

    Default Re: Help idk what's wrong

    What have you tried? Where is your updated code? What exactly are you confused about?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  11. #11
    Member jdv's Avatar
    Join Date
    Jul 2014
    Location
    This Land
    Posts
    74
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Default Re: Help idk what's wrong

    Quote Originally Posted by Aosora View Post
    Ok i looked up generics and basically its to minimize errors and make code easier to read. I've also looked up some examples and i still don't get what i need to fix please can someone show me cuz apparently im pretty stiff and im so close to finishing my program please anyone this would help me out greatly also i would know what to do in other instances of this occuring.
    Generics, in your case, will also show you some bugs in your code. You are relying on implicit casting to turn a String into an int.

    My advice is to stop and think about what you are putting INTO the ArrayList, and then what you are doing to fetch those Objects out later.

Similar Threads

  1. Replies: 4
    Last Post: March 6th, 2014, 04:14 PM
  2. Idk what title is appropiate for this lol but someone can help me?
    By patzxc in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 28th, 2012, 06:37 PM
  3. what wrong with this??
    By sephskie in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 14th, 2012, 06:50 PM
  4. Idk what is wrong
    By Devourz in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 28th, 2011, 05:05 AM
  5. Not sure what is wrong
    By dremn2004 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: June 18th, 2011, 10:49 AM