Welcome! Log In Create A New Profile

Advanced

Ass4 Question 8

Posted by Duncan 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Ass4 Question 8
July 31, 2006 03:50PM
Time is running out and I am now getting desperate! Can anyone supply me with the car class from Ex 8.2, so that I can just concentrate on Ex 8.3 opposed to having to do 8.2 first (which is not part of the assignment).

Can soemone send me their Customer and Address classes from 6.1, so that I can just concentrate on ex 8.4 opposed to having to go back to chapter 2! I could not do assignment 3 because of work commitments.

Time is not on my side and I am in desperate need to get at least 30 credits for this assignment.

Your help will be greatly appreciated.

Many thanks
Duncan
Re: Ass4 Question 8
August 01, 2006 02:08PM
Hey Duncan,

The basic car class should be something like this:

import java.util.*;

public class Car implements Comparator{
public Car() {}

public Car (final String dstrModel, final int dYear,
final String dManufacturer,
final String dstrColor, final int dHorsepower,
final int dNoOfCylinders
) {
strModel = dstrModel;
Year = dYear;
Manufacturer = dManufacturer;
strColor = dstrColor;
Horsepower = dHorsepower;
NoOfCylinders = dNoOfCylinders;
}

//Accessors ......etc

public String toString() {
return "Model: " + strModel + " Year: " + Year + ", Manufacturer: " + Manufacturer +
", Color: "
+ strColor + ", Horsepower: " + Horsepower + ", NoOfCylinders: " + NoOfCylinders;
}

public int compare(Object o1, Object o2) throws ClassCastException {

//needs to be implemented
}

//mutators .....

protected String strModel, Manufacturer;
protected int Year, Horsepower, NoOfCylinders;
protected String strColor;
}


The next part I am finding tough, need to implement the Comparator method and get it to sort the data.



Anyway, hope that helps,




Chris
Re: Ass4 Question 8
August 01, 2006 03:56PM
Hi Chris,

Very many thanks for your response, I was beggining to think I was being avoided. I thrashed about and came up with something similar to what you have, but then just got lost in the wilderness. I am now trying the next excersise with just as little success.

My problem is that I have only one more evening after today, as I will be going into the field for a few weeks.

many thanks for your help. If you get any more inspiration, I would be grateful for your comments

Cheers
Duncan
Re: Ass4 Question 8
August 02, 2006 02:46PM
Note in 8.2 the Car class should implement the Comparable interface not the Comparator interface. 8.3's Car2 class should extend Car. This one should give the comparators.
Re: Ass4 Question 8
August 04, 2006 01:17AM
You can't have more than one comparator in a class.

This is a dumb question, I quit!
Re: Ass4 Question 8
August 04, 2006 03:44PM
Haha, I interpreted the question in the wrong way. Is actually quite easy.
Anonymous User
Re: Ass4 Question 8
August 04, 2006 07:26PM
Easy how so? what did you do? As I've been stressing about this all day and haven't gotten any brainwaves.
Re: Ass4 Question 8
August 05, 2006 01:45AM
Well, if you have a question I will answer. But "how did you do it?" aint gonna work...
Anonymous User
Re: Ass4 Question 8
August 05, 2006 08:17AM
Well what I don't know is how to write comparators for each item and how to compare them. SO my question is how do you compare them if you can help with that I can do the rest
Anonymous User
Re: Ass4 Question 8
August 05, 2006 08:17AM
Well what I don't know is how to write comparators for each item and how to compare them. SO my question is how do you compare them if you can help with that I can do the rest
Re: Ass4 Question 8
August 05, 2006 01:19PM
Well, you wrote the Comparable... I.e. the compareTo, and you compare them in the same way, with the compare, you only use one parameter (that is a set parameter, because you have one "compare" for each attribute of the car) and not three like in compareTo
Anonymous User
Re: Ass4 Question 8
August 05, 2006 01:52PM
Thanks sleek, I'm such an idiot for not seeing it the first time grinning smiley
Re: Ass4 Question 8
August 05, 2006 01:58PM
Yay for hackers! smiling smiley
Sorry, only registered users may post in this forum.

Click here to login