![]() |
| ||
| Homework Help I am doing a project where I have the find the smallest value and the smallest object. In this project, you will write two methods. The first will take an array of int and will return the smallest value in the array. It will have a declaration as follows: int findSmallest(int[] array); This method should walk through the array, find the smallest element in the array, and return the value of that element. You should then create a main that creates and initializes an array of primitives as part of the declaration of the array, call the method, and print out the value of the smallest element in the array. The second method should also find the smallest element, but should use an array of UMUC_Comparables and the compareTo method to find the smallest object. It will have a definition as follows: UMUC_Comparable findSmallest(UMUC_Comparable[] array); Create a main that creates an array of Student objects, as in section III of module 5's commentary. You do not have to rewrite the compareTo method; you can simply use the one defined in module 5. Create and initialize an array of the Student objects and find the smallest object using this method. You should then print out the Student object returned. Note that the return from the method is a UMUC_Comparables, not a Student object, so you will need to cast the returned object to a Student object before printing it out. You can do so as follows: Student[] students ....; // Fill in the declaration of the student array. Student s = (Student)findSmallest(UMUC_Comparable[] array); Well I keep getting the in my output null 0 for my comparables when it should be a name and a student's average. Here is my code: Smallest.java
UMUC_Comparable.java
Student.java public class Student implements UMUC_Comparable {Can anyone help? |
| ||
| Re: Homework Help Well I hope someone will help me........ |
| ||
| Re: Homework Help Exception in thread "main" java.lang.Error: Unresolved compilation problem: The operator < is undefined for the argument type(s) Student, Student at Student.main(Student.java:63) That is the error i got.........SOME PLEASE HELP I AM BEGGING |
| ||
| Re: Homework Help Quote:
|
| ||
| Re: Homework Help Quote:
|
| ||
| Re: Homework Help 1) the result of your comparison is thrown away as soon as you exit your findSmallest method, so you might as well not have run that method in the first place. 2) Java doesn't have operator overloading so you can't use mathematical operators on class instances. Your class is obviously longer than the bit you posted and the error in another part you didn't show. |
| ||
| Re: Homework Help Quote:
|
| All times are GMT -4. The time now is 12:12 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC