Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Recompile with -Xlint:unchecked for details.

807601May 8 2008 — edited May 9 2008
Getting this weird message when I compile this program. I've looked it up and I'm confused by it, so I came here.

This is what I get when I compile
--------------------Configuration: <Default>--------------------
Note: G:\AP Comp. Sci\Labs\lab20.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Process completed.
And here's my program.
/**
 * @(#)lab20.java
 *
 *
 * @author 
 * @version 1.00 2008/5/8
 */

import java.io.*;
import java.util.*;
import java.text.DecimalFormat;

public class lab20 {

    public static void main(String args[]) throws IOException
    {
    	List studentArray = new List();
     	studentArray.getList();
    	studentArray.checkIfEmpty();
    	studentArray.pause();
    	
    	studentArray.display("UNSORTED LIST OF STUDENTS");
    	studentArray.pause();
    	
    	studentArray.gpaSort();
    	studentArray.display("STUDENTS SORTED IN DESCENDING ORDER BY GPA");
    	studentArray.pause();
    	
    	Person thisPerson = getPerson();
    	studentArray.insert(thisPerson);
    	
    	studentArray.display("STUDENTS SORTED BY GPA WITH NEW STUDENT ADDED");
    	studentArray.pause();
    	
   // 	studentArray.removeFailing();
   
   //	studentArray.display("STUDENTS SORTED BY GPA WITH FAILIN STUDENTS REMOVED");
   //	studentArray.pause();
   		
   		int index = studentArray.search(thisPerson);
   		if (index == -1)
   			System.out.println(thisPerson.name + " is not in the list.\n");
   		else
   			System.out.println(thisPerson.name + " is in the list at index "+index+".\n");
   		
   		studentArray.compareTop3();
   		studentArray.removeAll();
   		studentArray.checkIfEmpty();
    }
    
    public static Person getPerson()
    {
    	Scanner input = new Scanner(System.in);
    	System.out.print("\nEnter name: --> ");
    	String name = input.nextLine();
    	System.out.print("Enter id:	--> ");
    	int id = input.nextInt();
    	System.out.print("Enter age:	-->	");
    	int age = input.nextInt();
    	System.out.print("Enter gpa:		--> ");
    	double gpa = input.nextDouble();
    	return new Person(name,id,age,gpa);
    }
}
    
class Person
{
		public String name;
		public int id;
		public int age;
		public double gpa;
		
		Person(String n, int ID, int a, double g)
		{
			name = n;
			id = ID;
			age = a;
			gpa = g;
		}
		
}

class List
{
		private ArrayList student;// stores array elements
		
		public List()
		{
			student = new ArrayList();
		}
		
		public void getList() throws IOException
		{
			//This methods is mostly finished. As it is, it will read in the information from the file,
			//but it will not put the information into the ArrayList. you need to add that part.
			
			FileReader inFile = new FileReader("students20.dat");
			BufferedReader inStream = new BufferedReader(inFile);
			String s1,s2,s3,s4;
			int age, id;
			double gpa;
			while( ((s1 = inStream.readLine()) != null) &&
				   ((s2 = inStream.readLine()) != null) &&
				   ((s3 = inStream.readLine()) != null) &&
				   ((s4 = inStream.readLine()) != null) )
				   {
				   	String name = s1;
				   	id = Integer.parseInt(s2);
				   	age = Integer.parseInt(s3);
				   	gpa= Double.parseDouble(s4);
				   	
				   	student.add(new Person(name,id,age,gpa));
				   }
				   inStream.close();
		}
		
		public void display(String listInfo)
		{
			// This method requires that the toString method of the person class is written
			System.out.println("\nDISPLAYING "+ listInfo);
			System.out.println();
			
			for (int k = 0; k < student.size(); k++)
				System.out.println(student.get(k));
				
				
		}
		
		public void pause()
		{
			Scanner input = new Scanner(System.in);
			String dummy;
			System.out.println("\nPress <Enter> to continue.");
			dummy = input.nextLine();
		}
		
		private void swap(int x, int y)
		{
			Person temp = (Person)student.get(x);
			student.set(x,student.get(y));
			student.set(y,temp);
		}
		
		public void gpaSort()
		{
			// NOTE: This method is provided for you,
			// but it will not work if you have not written the swap method
			
			for (int p =1; p < student.size(); p++)
				for (int q = 0; q < student.size()-p; q++)
				{
					Person thisOne = (Person) student.get(q);
					Person nextOne = (Person) student.get(q+1);
					if (thisOne.gpa < nextOne.gpa)
							swap(q,q+1);
				}
		}
		
		public int search(Person thisPerson)
		{
			return student.indexOf(thisPerson);
		}
		
		public void insert(Person newStudent)
		{
			
			student.add(0,newStudent);
			
		}
		
		public void removeFailing()
		{
			// Hint: Remember, the list will be sorted in DESCENDING order.
		}
		
		public void removeAll()
		{
			
		}
		
		public void compareTop3()
		{
			// NOTE: This method is provided for you,
			//		 but it will not work if you have not written the equals method of ther Person class.
			
			Person first, second, third;
			first  = (Person) student.get(0);
			second = (Person) student.get(1);
			third  = (Person) student.get(2);
			
			if (first.equals(second))
				System.out.println(first.name+" and "+second.name+" are equal.\n");
			if (first.equals(third))
				System.out.println(first.name+" and "+third.name+" are equal.\n");
			if (third.equals(second))
				System.out.println(third.name+" and "+second.name+" are equal. \n");
		}
		
		public void checkIfEmpty()
		{
			if(student.isEmpty())
			{
				System.out.println("This List is not empty");
			}
			else
			{
				System.out.println("This List IS empty");
			}
		}
}
Thanks in advance.

Edited by: apfroggy0408 on May 8, 2008 5:37 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 6 2008
Added on May 8 2008
17 comments
9,990 views