May 29, 2023, 02:50:28 PM
Welcome, Guest. Please login or register
News: Stay up to date with everything that's happening at http://twitter.digitalsignage.com

MediaSignage support forum



Author Topic: Java problem! Why do I get this error? Could anyone please help remove the bug :  (Read 3505 times)

debicavett

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
warning: [unchecked] unchecked call to add(E) as a member of the raw type
java.util.ArrayList

Here is my code...

import java.util.*;

class Emp {

public Emp(String n, double s, int year, int month, int day) {
name = n;
salary = s;
GregorianCalendar calendar = new GregorianCalendar(year, month - 1, day);
hireDay = calendar.getTime();
}

public String getName() {
return name;
}

public double getSalary() {
return salary;
}

public Date getHireDay() {
return hireDay;
}

public void raiseSalary(double byPercent) {
double raise = salary * byPercent / 100;
salary += raise;
}

private String name;
private double salary;
private Date hireDay;
}


import java.util.*;

public class TestArrayList {

public static void main(String[] args) {

ArrayList staff = new ArrayList();

staff.add(new Emp("Raj", 20000, 2005, 9, 14));
staff.add(new Emp("Deep", 35000, 2009, 12, 5));
staff.add(new Emp("Mr. Rai", 50000, 2011, 1, 13));

for(int i = 0; i < staff.size() ; i++) {
Emp e = (Emp) staff.get(i);
e.raiseSalary(5);
}

for(int i = 0; i < staff.size(); i++) {
Emp e = (Emp) staff.get(i);
System.out.println("Name: " + e.getName()
+ " Salary: " + e.getSalary()
+ " Hire day: " + e.getHireDay());
}
}
}




Thanks Mark for your help! It worked :)

 

Carbonate design by Bloc
variant: carbon
SMF 2.0.12 | SMF © 2016, Simple Machines