473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

type saftey and static reference errors

nomad
664 Expert 512MB
Hello Everyone...
I have rewrite my code and I ran into some problems.
I have two problems.

1. What does this mean "Type safety: The method add(Object) belongs to the raw type ArrayList. References to generic type ArrayList<E> should be parameterized" at this statement
Expand|Select|Wrap|Line Numbers
  1. arlist.add(temp);
2. how do I change this "Cannot make a static reference to the non-static field empid"
Expand|Select|Wrap|Line Numbers
  1.  for(String idx :  empid
)


Thanks
nomad


here is my code

Expand|Select|Wrap|Line Numbers
  1.  
  2. import java.util.*;
  3.  
  4. class Employee {
  5.     static final int size = 10;
  6.  
  7.     private String empid;
  8.  
  9.     private String lname;
  10.     public Employee(String id) {
  11.         empid = id;
  12.     }// close the employeeclass loop
  13.  
  14.     /**
  15.      * Constructors.
  16.      */
  17.     public Employee() {
  18.  
  19.     }
  20.  
  21.     public Employee(String id, String fn) {
  22.         empid = id;
  23.  
  24.  
  25.     }// close public EmployeeClass
  26.  
  27.     /*
  28.      * accessors make info available
  29.      */
  30.     public String getEmpId() {
  31.         return empid;
  32.     }
  33.  
  34.  
  35.     /*
  36.      * Mutator Methods
  37.      */
  38.     public void setEmpId(String id) {
  39.         this.empid = id;
  40.     }
  41. }
  42.  
  43. /**
  44.  * The EmployeeDatabase class stores each Employee in an arraylist. Methods
  45.  * exist to add new Employees, search Employees, and print Employees to the
  46.  * console.
  47.  */
  48. public class Employee_listing {
  49.  
  50.     static ArrayList arlist;
  51.     int empid = arlist.size();
  52.     /**
  53.      * displayMatch inputs a keyword from the user. It then iterates through the
  54.      * ArrayList of Employees and outputs each one to the screen if the Employee
  55.      * information contains the keyword.
  56.      */
  57.  
  58.     public static Employee inputEmployee() {
  59.         Employee temp = null;
  60.         Scanner input_flag = new Scanner(System.in);
  61.  
  62.         System.out.println("Enter Employee Id Number AB1234==>");
  63.         String empid = input_flag.next();
  64.  
  65. //need to add find section here
  66.         System.out.print("Enter Last Name Doe==>");
  67.         String ln = input_flag.next();
  68.  
  69.         System.out.print("Enter First Name John==>");
  70.         String fn = input_flag.next();
  71.  
  72.         System.out.print("Enter Street ==>");
  73.         String st = input_flag.next();
  74.  
  75.         System.out.print("Enter City ==>");
  76.         String ct = input_flag.next();
  77.  
  78.         System.out.print("Enter Zip ==>");
  79.         String zp = input_flag.next();
  80.  
  81.         System.out.print("Enter years worked ==>");
  82.         Integer years = input_flag.nextInt();
  83.  
  84.         System.out.print("Enter payrate as double ==>");
  85.         Double pr = input_flag.nextDouble();
  86.  
  87.         // make an object
  88.         temp = new Employee(empid, );
  89.         return temp;
  90.  
  91.  
  92.  
  93.     }
  94.  
  95.  
  96.     /**
  97.      * @param Add
  98.      *            a employee to the db. using a scanner to see if an Employee is
  99.      *            in the db if no add them
  100.      */
  101.  
  102.     public static void main(String[] args) {
  103.  
  104.         arlist = new ArrayList<Employee>();
  105.  
  106.         Scanner input_flag = new Scanner(System.in);
  107.         int choice;
  108.         System.out.println("Make a Section: ");
  109.         System.out.println("1. Enter ");
  110.         System.out.println("2. Find ");
  111.         System.out.println("3. Exit ");
  112.         System.out.print("\nPlease press Enter afer each response");
  113.         System.out.println("Enter your chose please: ");
  114.         choice = input_flag.nextInt();
  115.         input_flag.nextLine();
  116.         if (choice == 1) {// if 1 is select go to makePerson
  117.             Employee temp=inputEmployee();
  118.             arlist.add(temp);
  119.             //--
  120.         }
  121.  
  122. /**
  123. * displayMatch inputs a keyword from the user. It then iterates through the
  124. * ArrayList of Employees and outputs each one to the screen if the Employee
  125. * information contains the keyword.
  126. */
  127.         if (choice == 2) {// if 2 is select go to find
  128.             String ans;
  129.             System.out.print("Enter name==> ");
  130.             ans = input_flag.next();
  131.  
  132.             // loop through the array
  133.             int pos = 0;
  134.  
  135.             for(String idx :  empid) {
  136.                     if( ans.equalsIgnoreCase(idx)) {
  137.                             break;
  138.                     } else {
  139.                             pos++;
  140.                     }
  141.             }
  142.             if(pos >= empid.length) {
  143.                     System.out.println("Did not find name");
  144.             } else {
  145.             //---
  146.             }
  147.         }
  148.         if (choice == 3) {
  149.             //--
  150.         }
  151.  
  152.     }
  153.  
  154. }
Apr 5 '07 #1
4 3113
RedSon
5,000 Expert 4TB
In the future please adhere to the proper naming of new thread questions.

See Use a Good Thread Title
Apr 5 '07 #2
RedSon
5,000 Expert 4TB
In your first question you must have an object type between brackets so that the data structure knows what object it is allowed to operate on.

Your other question has something to do with the way that you are calling the method. Either it needs to be called statically in which you put the ClassName.MethodName(arguments) or you must create an object of ClassName and then call methods using the object (ie classObject.MethodName(arguments))
Apr 5 '07 #3
nomad
664 Expert 512MB
I sudden realized that I can make problem 2 static.
Will have to rethink this...

thanks
damon
Apr 5 '07 #4
nomad
664 Expert 512MB
this project is driving me crazy!!!!!!!!!!!!!!
Apr 5 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Terje Slettebø | last post by:
Hi. I'm new here, and sorry if this has been discussed before; I didn't find it searching the PHP groups. (I've also read recommendations to cross-post to the other PHP groups, but if that is...
12
by: Aaron Watters | last post by:
I'm doing a heart/lung bypass procedure on a largish Python program at the moment and it prompted the thought that the methodology I'm using would be absolutely impossible with a more "type safe"...
7
by: shahehe | last post by:
The following code seems fine to me but when I tried to compile it using g++ test.C, I got lots of errors, why? #include <iostream> static const int MAX_STACK = 100; class Stack
0
by: Nashat Wanly | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaskdr/html/askgui06032003.asp Don't Lock Type Objects! Why Lock(typeof(ClassName)) or SyncLock GetType(ClassName) Is Bad Rico...
5
by: jmd | last post by:
hello. i am trying VC++ 7.1 (with vsnet 2003). my example : class Complex { public: Complex ( float re_ = 0.0, float im_ = 0.0 ) : re(re_), im(im_) {} float Re () { return ( re ); } float...
4
by: st_ev_fe | last post by:
Hi people, I've been doing C for about 7 years now. But I'm new to C++. I've decided that C++'s operator overloading could be very handy. I'm writing something much like auto_ptr, except for...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
5
by: Med | last post by:
Hi, Could someone please tell me if I undrestand the concept of "Thread Saftey" correctly in Multi-threaded web application (asp.net 2) using following examples: 1. Class A is NOT a thread...
5
by: Fei Liu | last post by:
Hello, I just hit a strange problem regarding SFINAE. The following code causes compile error (void cannot be array element type), I thought SFINA should match test(...) version instead and not...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.