How do you compare an Arraylist w/ a scanner

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sandyw
    New Member
    • Mar 2007
    • 122

    #16
    Originally posted by RedSon
    Its a moderate project not one for a brand new beginner. Tell me what the member data in your Employee class is and I will be able to help you further.
    Sure RedSon.

    Code:
    class Employee {
    
    
    
    	private String empid;
    
    
    
    	private String lname;
    
    
    
    	private String fname;
    
    
    
    	private String street;
    
    
    
    	private String city;
    
    
    
    	private String zip;
    
    
    
    	private Integer yearsworked;
    
    
    
    	private Double payrate;
    
    
    
    	public Employee(String id) {
    
    	...
    I can not wait when I will be able to help others. I'm doing that in the other sections of this website.

    sandy
    Last edited by RedSon; Apr 7 '07, 09:58 PM. Reason: Removed non important code

    Comment

    • RedSon
      Recognized Expert Expert
      • Jan 2007
      • 4980

      #17
      It looks like your employee class is a class that models only one employee. There is no collection in your Employee class. If you have a collection of employees you can then iterator across the collection. So back to your original question, if you make an arraylist of employees then you can use your iterator to check and see each element in the arraylist if it has the employee id in it already or not. Does that make sense?

      Comment

      • sandyw
        New Member
        • Mar 2007
        • 122

        #18
        Originally posted by RedSon
        It looks like your employee class is a class that models only one employee. There is no collection in your Employee class. If you have a collection of employees you can then iterator across the collection. So back to your original question, if you make an arraylist of employees then you can use your iterator to check and see each element in the arraylist if it has the employee id in it already or not. Does that make sense?
        Hello RedSon:
        Once again thanks for taking the time to help me esp on a Sat.
        I went back to see what my assignment was.
        Here is its.
        This program will maintain Employee Data for a company. The user will be able to enter new employee data and search on existing employee data. This program will use Arrays or an ArrayList to maintain the information. You will create an Employee Class and from this class create Employee Objects. These objects will be stored in an Array or ArrayList in such a way that they can be searched by the user.
        And the info I listed in the first posting.
        So I'm not sure what I'm suppose to do on how to collect more employees...
        Can you please give me a hint or a clue.
        Thanks
        sandy...

        Comment

        • RedSon
          Recognized Expert Expert
          • Jan 2007
          • 4980

          #19
          • This program will maintain Employee Data for a company.
          • The user will be able to enter new employee data and search on existing employee data.
          • You will create an Employee Class and from this class create Employee Objects.
          • This program will use Arrays or an ArrayList to maintain the information.
          • These objects will be stored in an Array or ArrayList in such a way that they can be searched by the user.


          I broke your assignment down into a few terse statements. So far it looks like you have accomplished the first 3 items. The next step is for you to do that last two items. In order for you to do this you will want to search the Java APIs for the keyword ArrayList. Once you figure out how to implement an ArrayList you will then be able to easily add in some searching functionality.

          Comment

          • sandyw
            New Member
            • Mar 2007
            • 122

            #20
            I have done some work on my Project.
            Im down to one error, I hope!!!!

            here is the error message
            The type Employee is already defined
            occurs here
            public class Employee {


            How do I fix this please

            here is part of my code.

            Code:
            	/**
            	 * The EmployeeDatabase class stores each Employee in an arraylist. Methods
            	 * exist to add new Employees, search Employees, and print Employees to the
            	 * console.
            	 */
            	public class Employee {
            
            		static ArrayList arlist;
            
            		int empid = arlist.size();
            
            		/**
            		 * displayMatch inputs a keyword from the user. It then iterates through the
            		 * ArrayList of Employees and outputs each one to the screen if the Employee
            		 * information contains the keyword.
            		 */
            
            		public static Employee inputEmployee() {
            			Employee temp = null;
            			Employee myEmployee;
            			Scanner input_flag = new Scanner(System.in);
            Thanks
            Sandy

            Comment

            • RedSon
              Recognized Expert Expert
              • Jan 2007
              • 4980

              #21
              Originally posted by sandyw
              I have done some work on my Project.
              Im down to one error, I hope!!!!

              here is the error message
              The type Employee is already defined
              occurs here
              public class Employee {


              How do I fix this please

              here is part of my code.

              Code:
              	/**
              	 * The EmployeeDatabase class stores each Employee in an arraylist. Methods
              	 * exist to add new Employees, search Employees, and print Employees to the
              	 * console.
              	 */
              	public class Employee {
              
              		static ArrayList arlist;
              
              		int empid = arlist.size();
              
              		/**
              		 * displayMatch inputs a keyword from the user. It then iterates through the
              		 * ArrayList of Employees and outputs each one to the screen if the Employee
              		 * information contains the keyword.
              		 */
              
              		public static Employee inputEmployee() {
              			Employee temp = null;
              			Employee myEmployee;
              			Scanner input_flag = new Scanner(System.in);
              Thanks
              Sandy
              You already have a class named Employee, change the name of this class to something else.

              Comment

              • sandyw
                New Member
                • Mar 2007
                • 122

                #22
                Originally posted by RedSon
                You already have a class named Employee, change the name of this class to something else.
                When I change the class to something else. I get the same errors I had before. Man I'm just not getting this stuff.
                I think I just have to start fresh in the search part.

                sandy
                PS thanks again RedSon...

                Comment

                • RedSon
                  Recognized Expert Expert
                  • Jan 2007
                  • 4980

                  #23
                  What errors were you getting before?

                  Comment

                  • sandyw
                    New Member
                    • Mar 2007
                    • 122

                    #24
                    Originally posted by RedSon
                    What errors were you getting before?

                    When I change the class to Employee to Employee_databa se.

                    I would get flag on anthing related to Employee.

                    Comment

                    • RedSon
                      Recognized Expert Expert
                      • Jan 2007
                      • 4980

                      #25
                      Well did you delete your Employee class or just not import it?

                      Comment

                      • sandyw
                        New Member
                        • Mar 2007
                        • 122

                        #26
                        Originally posted by RedSon
                        Well did you delete your Employee class or just not import it?
                        I don't think I ever deleted my Employee class, and I don't think I ever import it.
                        How do I find out if I import it?

                        I wonder if taking an on-line class was the best ideal. We never have a so called class we just read the material and we never get to ask question to the instructor (we can ask question via email but it seems he never gets back to use and that's the reason I'm here on line to get help).
                        We are using the book Big Java 2 edition. I don't find it very helpfull at times.
                        Some of the thing you are helping me is Greek and I have to find out what you mean on line or ask you...

                        sandy

                        Comment

                        • RedSon
                          Recognized Expert Expert
                          • Jan 2007
                          • 4980

                          #27
                          importing files into java source is a very basic activity. Also adding objects to a collection, searching and sorting that collection are also simple with java. I suggest you take some time to ready the first 4 to 6 chapters in your book and then continue this conversation after you have done that. Also there are links that are stickied at the top of this forum that will help you to understand some of the basics of the Java programming language.

                          Comment

                          • sandyw
                            New Member
                            • Mar 2007
                            • 122

                            #28
                            Originally posted by RedSon
                            importing files into java source is a very basic activity. Also adding objects to a collection, searching and sorting that collection are also simple with java. I suggest you take some time to ready the first 4 to 6 chapters in your book and then continue this conversation after you have done that. Also there are links that are stickied at the top of this forum that will help you to understand some of the basics of the Java programming language.
                            Finally I figure out that class problem. It was right in front of my eyes even eclipse was telling what was wrong.
                            Anyways now I have a problem with
                            "The method inputEmployee cannot be declared static; static methods can only be declared in a static or top level type"
                            Part of my code where the problem is occurring.
                            Code:
                            public class Employee {
                                static ArrayList<Employee> arlist;
                            	int empid = arlist.size();
                            	/**
                            	 * displayMatch inputs a keyword from the user. It then iterates through the
                            	 * ArrayList of Employees and outputs each one to the screen if the Employee
                            	 * information contains the keyword.
                            	 */
                            
                            	public static Employee inputEmployee() {
                            		Employee temp = null;
                            
                            		//prompt for data
                            
                            		Scanner input_flag = new Scanner(System.in);
                            		System.out.println("Enter Employee Id Number AB1234==>");
                            		String empid = input_flag.next();
                            Here is the other half of the problem
                            The method main cannot be declared static; static methods can only be declared in a static or top level type
                            Code:
                            public static void main(String[] args) {
                            
                                    arlist = new ArrayList<Employee>();
                            
                                    kbd = new Scanner(System.in);
                            		int choice;
                            		System.out.println("Make a Section: ");
                            Any help would be great...

                            thanks
                            sandy

                            Comment

                            Working...