How do I override a method - java

class TestTax {
public static void main (String[] args){
NJTax t = new NJTax();
t.grossIncome= 50000;
t.dependents= 2;
t.state= "NJ";
double yourTax = t.calcTax();
double totalTax = t.adjustForStudents(yourTax);
System.out.println("Your tax is " + yourTax);
}
}
class tax {
double grossIncome;
String state;
int dependents;
public double calcTax(){
double stateTax = 0;
if(grossIncome < 30000){
stateTax = grossIncome * 0.05;
}
else{
stateTax = grossIncome * 0.06;
}
return stateTax;
}
public void printAnnualTaxReturn(){
// code goes here
}
}
public class NJTax extends tax{
double adjustForStudents (double stateTax){
double adjustedTax = stateTax - 500;
return adjustedTax;
public double calcTax(){
}
}
}
I am having trouble with the Lesson requirement to:
"Change the functionality of calcTax( ) by overriding it in NJTax. The new version of calcTax( ) should lower the tax by $500 before returning the value."
How is this accomplished. I just have safaribooksonline and no videos for the solution.

http://download.oracle.com/javase/tutorial/java/IandI/override.html
Class names should start with a capital letter as well. Since I'm not exactly sure what you wanted regarding functionality, here's just an example. Super refers to the parent class, in this case being tax. Thus, NJTax's calcTax() method returns tax.calcTax() - 500. You also may want to look into using the #Override annotation as a way of making it clear that a method is being overridden and to provide a compile-time check.
public class NJTax extends tax {
public double adjustForStudents (double stateTax) {
double adjustedTax = stateTax - 500;
return adjustedTax;
}
public double calcTax() {
return super.calcTax() - 500;
}
}

public class NJTax extends tax{
double adjustForStudents (double stateTax){
double adjustedTax = stateTax - 500;
return adjustedTax;
}
public double calcTax(){
double stateTax = super.calcTax();
return this.adjustforStudents(stateTax);
}
}

hint: return the same value as tax.calcTax() minus $500.

For overriding you base class (Tax) implementation of calcTax, just add your own implementation of calcTax in NJTax. This could be as simple as
public double calcTax(){
return super.calcTax() -500;
}

Related

Trouble with Method undefined for a type Java

I'm new to Java programming and having a hard time understanding the use of methods and how to use them in the code. I know this is really basic things and I'm trying, it's just hard to grasp at first. So tl;dr I don't quite understand this error or how to fix it.
public class TriangleInfo {
public static void main(String args[]) {
Triangle versuch = createTriangle();
}
public static createTriangle() {
double side1 = 90;
double side2 = 80;
double hypotenuse = getHypotenuse();
Triangle thisTriangle = new Triangle(side1, side2, hypotenuse);
return thisTriangle;
}
public static double getHypotenuse() {
return Math.sqrt(Math.pow(side1, 2) + Math.pow(side2, 2));
}
}
The error I'm getting is:
The method createTriangle() is undefined for the type TriangleInfo
I also have this written in another file:
public class Triangle {
double side1;
double side2;
double hypotenuse;
// Konstrukturen
public Triangle(double sideOne, double sideTwo, double hypotenuse) {
this.sideOne = sideOne;
this.sideTwo = sideTwo;
this.hypotenuse = hypotenuse;
}
}
Could someone please help me understand this error and how to correct it? Thank you!
The error is that your method createTriangle() doesn't have a return type. Since you are returning a Triangle, you need to add that.
public static Triangle createTriangle() {
And continue with your normal code.
Also, a good catch from #JO3-W3B-D3V, the side1 and side2 are not globally accessible in the class, so you need to do:
public static double getHypotenuse(double side1, double side2) {
return Math.sqrt(Math.pow(side1, 2) + Math.pow(side2, 2));
}
So, your complete createTriangle() function becomes:
public static Triangle createTriangle(){
double side1 = 90;
double side2 = 80;
double hypotenuse = getHypotenuse(side1, side2);
Triangle thisTriangle = new Triangle(side1, side2, hypotenuse);
return thisTriangle;
}
Okay, first of all, looking at the code you've provided, the method createTriangle does not have a return type specified, all you need to do here is refactor it like so:
public static Triangle createTriangle() { // Body of the method...
Then there's the matter of the getHypotenuse method, since it has no reference to the values side1 or side2, you need to either alter it such that the these variables are properties within the class, or you can update the method & the caller, like so:
Caller
double hypotenuse = getHypotenuse(side1, side2);
Method
public static double getHypotenuse(double side1, double side2) { // Body of the method...
Finally, in the Triangle class, you have the property names stated as side, but in the constructor of the Triangle class, you try to assign this.sideOne, it should either be side1 in the constructor, or you should change the name(s) of the class properties.
Summary
To be fair, I appreciate that you're a beginner & to be fair, you weren't too far from having a working implementation.
Complete Solution
import java.lang.Math;
public class TriangleInfo {
public static void main(String args[]) {
Triangle versuch = createTriangle();
}
public static Triangle createTriangle() {
double side1 = 90;
double side2 = 80;
double hypotenuse = getHypotenuse(side1, side2);
Triangle thisTriangle = new Triangle(side1, side2, hypotenuse);
return thisTriangle;
}
public static double getHypotenuse(double side1, double side2) {
return Math.sqrt(Math.pow(side1, 2) + Math.pow(side2, 2));
}
}
class Triangle {
double side1;
double side2;
double hypotenuse;
// Konstrukturen
public Triangle(double sideOne, double sideTwo, double hypotenuse) {
this.side1 = sideOne;
this.side2 = sideTwo;
this.hypotenuse = hypotenuse;
}
}

Classes and Objects. Getting 0.0 as answer when calculating price. - JAVA

I'm working out a question from a labsheet but i'm only getting 0.0 as answer when running the program. I can't find out what's wrong please help.
The question:
Implement a class Pizza with attribute diameter (in cm), cost_sq_cm (cost per square cm) and area. Its methods are:
• Constructor to create an object of type Pizza with a given diameter and given price_sq_cm.
• Mutator and accessor methods for diameter and cost_sq_cm.
• calcArea to calculate the area of a given pizza.
• getPrice to calculate and return the price of a pizza.
Write a class TestPizza with a main method that declares an object of type Pizza with a user inputted diameter and user-­‐inputted cost_sq_cm of a circular pizza, and display the price of the pizza.
The Pizza class:
package Number3;
public class Pizza {
private int diameter;
private float cost_sq_cm;
private double area;
private double price;
public Pizza() //default constructor
{
diameter = 0;
cost_sq_cm = 0;
area = 0;
price = 0;
}
public Pizza(int d,float cost,double a,double p) //overloaded constructor
{
d = diameter;
cost = cost_sq_cm;
a = area;
p = price;
}
public void Constructor() //method
{
Pizza P = new Pizza();
}
public void setDiameter(int d) //mutator
{
d = diameter;
}
public int getDiameter() //accessor
{
return diameter;
}
public void setCost(float c)
{
c = cost_sq_cm;
}
public float getCost()
{
return cost_sq_cm;
}
public double calcArea()
{
area = 3.142 * (diameter * diameter);
return area;
}
public double getPrice()
{
price = area * cost_sq_cm;
return price;
}
public void display()
{
System.out.print("The area is: "+this.price);
}
}
TestPizza:
package Number3;
import java.util.Scanner;
public class TestPizza {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
float area = 0;
Pizza P = new Pizza();
int d; float c,a = 0;
System.out.print("Enter a value for the diameter: ");
d = input.nextInt();
P.setDiameter(d);
System.out.print("Enter a value for the cost: ");
c = input.nextFloat();
P.setCost(c);
P.display();
}
}
I'm new to JAVA. Please be lenient.
You should multiply cost per square centimeter times area to get price. You'll get zero if either one is equal to zero. I see where you've set diameter, but not area.
You set diameter, but you don't calculate area when you set it.
public void setDiameter(int d) //mutator; lose this comment. worthless clutter.
{
d = diameter;
area = calcArea();
}
I'd recommend following the Java idiom. Don't write a display() method; better to override toString().
I'd write it this way:
package cruft;
import java.text.DecimalFormat;
import java.text.NumberFormat;
/**
* Pizza
* #author Michael
* #link https://stackoverflow.com/questions/28658669/classes-and-objects-getting-0-0-as-answer-when-calculating-price-java
* #since 2/22/2015 12:27 PM
*/
public class Pizza {
private static final int DEFAULT_DIAMETER = 38;
private static final double DEFAULT_COST = 15.0;
private static final double DEFAULT_COST_PER_AREA = 0.013226; // 15 euro for a 38 cm diameter pizza
private static final NumberFormat DEFAULT_FORMAT = new DecimalFormat("#.####");
private final int diameter;
private final double costPerArea;
private final double price;
public static void main(String[] args) {
int diameter = ((args.length > 0) ? Integer.valueOf(args[0]) : DEFAULT_DIAMETER);
double costPerArea = ((args.length > 1) ? Double.valueOf(args[1]) : DEFAULT_COST_PER_AREA);
Pizza pizza = new Pizza(diameter, costPerArea);
System.out.println(pizza);
}
public Pizza(int diameter, double costPerArea) {
if (diameter <= 0) throw new IllegalArgumentException("diameter must be positive");
if (costPerArea <= 0) throw new IllegalArgumentException("cost per area must be positive");
this.diameter = diameter;
this.costPerArea = costPerArea;
this.price = this.costPerArea*this.calculateArea();
}
public double getPrice() {
return price;
}
private double calculateArea() {
return Math.PI*this.diameter*this.diameter/4.0;
}
#Override
public String toString() {
final StringBuilder sb = new StringBuilder("Pizza{");
sb.append("diameter=").append(diameter);
sb.append(", costPerArea=").append(DEFAULT_FORMAT.format(costPerArea));
sb.append(", price=").append(NumberFormat.getCurrencyInstance().format(getPrice()));
sb.append('}');
return sb.toString();
}
}
For setting a field or another value it is
variable = value;
so
diameter = d;
It looks like your setCost and setDiameter methods need to be changed,
From
d = diameter;
To
this.diameter = d;
Instead of:
System.out.print("The area is: "+this.price);
Use:
System.out.print("The area is: "+this.getPrice());
You need to calculate area as well. So in your main method call it like:
P.calcArea();//to calculate area
You initialised price as 0, when you called new Pizza() and you never called getPrice which is where you calculate the price.
Also change your setter for cost from:
public void setCost(float c) {
c = cost_sq_cm;
}
To
public void setCost(float c) {
cost_sq_cm = c;
}

Java simple commission program, return data based on search (JOptionPane)

I'm creating a simple commission program with the data of the sales people already in the code. I just want to find a way to search for a NAME and return their name total salary. I've hit a roadblock for the past few hours trying to do this.
public class SalesPeople {
String personName;
double annualSalary;
double salesAmount;
double percentComission;
public SalesPeople(String xPersonName, double xAnnualSalary, double xSalesAmount, double xPercentComission) {
personName = xPersonName;
annualSalary = xAnnualSalary;
salesAmount = xSalesAmount;
percentComission = xPercentComission;
}
double totalSalary = annualSalary + (salesAmount * percentComission);
public String getPersonName() {
return personName;
}
public double getAnnualSalary() {
return annualSalary;
}
public double getSalesAmount() {
return salesAmount;
}
public double getPercentComission() {
return percentComission;
}
public double getTotalSalary() {
return totalSalary;
}
}
In the last few lines of the class below are where I'm having trouble.
import java.util.ArrayList;
import javax.swing.JOptionPane;
public class CommissionCalc {
public static void main (String [] args ) {
ArrayList<SalesPeople> salesList = new ArrayList<SalesPeople>();
// PersonName, AnnualSalary, SalesAmount, PercentComission
SalesPeople salesPerson1 = new SalesPeople ("Bob", 30000, 5000, .09);
SalesPeople salesPerson2 = new SalesPeople ("Jane", 40000, 7000, .10);
salesList.add(salesPerson1);
salesList.add(salesPerson2);
String userInput;
userInput = JOptionPane.showInputDialog("Enter the name of a sales person:");
if((salesList.get(0).getPersonName()).equals(userInput)) {
for (int cnt = 0; cnt < salesList.size(); cnt++) {
if((salesList.get(cnt).getPersonName()).equals(userInput)) {
System.out.println(salesList.get(cnt).getPersonName() + salesList.get(cnt).getTotalSalary());
}
}
}
}
}
}
}
The name prints, but I'm getting a return of 0.0 on total salary. I just can't get it to return the Name and TotalSalary. Any help would really be appreciated.
You need to use System.out.println(salesList.get(cnt).getPersonName()); instead of System.out.println(salesList.get(cnt));. For name and total salary use code like this:
System.out.println("Person name: " + salesList.get(cnt).getPersonName() + ", Total salary: " + salesList.get(cnt).getPersonName().getTotalSalary());
For total salary, replace your getTotalSalary() method with this code:
public double getTotalSalary() {
return getAnnualSalary() + (getSalesAmount() * getPercentComission());
}
Try to set totalSalary in SalesPeople constructor. So the code would be:
public class SalesPeople {
String personName;
double annualSalary;
double salesAmount;
double percentComission;
double totalSalary;
public SalesPeople(String xPersonName, double xAnnualSalary, double xSalesAmount, double xPercentComission) {
personName = xPersonName;
annualSalary = xAnnualSalary;
salesAmount = xSalesAmount;
percentComission = xPercentComission;
totalSalary = annualSalary + (salesAmount * percentComission);
}
...
}
Before SalesPeople class initialization, the default value for annualSalary, salesAmount and percentComission are 0 (or null as undefined).If you define totalSalary outside constructor, totalSalary will always be 0.
The alternative solution would be: define a setTotalSalary() method in your SalesPeople class, and call it after you create a SalsePeople instance.
public void setTotalSalary(){
totalSalary = this.annualSalary + (this.salesAmount * this,percentComission);
}
And call setTotalSalary() you define a SalesPeople instance.
SalesPeople salesPerson1 = new SalesPeople ("Bob", 30000, 5000, .09);
salesPerson1.setTotalSalary();

Java while loop conversion.

I have this method that computes taxes due for a person with a filing status of single.
But I'm having trouble trying to convert this to a for loop or using an Array instead of a while loop because this code becomes really long and nasty looking. I want to make it look pretty by simplifying the code. Any suggestions?
public void calculateTax()
{
//The constant fields for the tax rate
final double TAXRATE_10 = 0.1; //10%
//This is the tax rate percent on the tax 15%
final double TAXRATE_15PERCENT = 0.15;
//This is the tax rate percent on the tax 25%
final double TAXRATE_25PERCENT = 0.25;
//This is the tax rate percent on the tax 28%
final double TAXRATE_28PERCENT = 0.28;
//This is the tax rate percent on the tax 33%
final double TAXTRATE_33PERCENT = 0.33;
//This is the tax rate percent on the tax 35%
final double TAXRATE_35PERCENT = 0.35;
//constant numbers for tax boundaries.
final int NOTRICH = 8700;
final int MIDDLECLASS = 35350;
final int SORTOFRICH = 85650;
final int RICH = 178650;
final int FORSURERICH = 388350;
//Variables for taxable income, and tax calculation.
long taxableIncome = income - deduction -(numberOfExemption * VAlUEOFEXEMPTION);
double cumulatedTax = 0;
//Calculate the Tax
while(taxableIncome != 0)
{
if(taxableIncome > FORSURERICH)
{
cumulatedTax += ((taxableIncome-FORSURERICH) * TAXRATE_35PERCENT);
taxableIncome = (long)FORSURERICH;
}
else if(taxableIncome > RICH)
{
cumulatedTax += ((taxableIncome-RICH) * TAXTRATE_33PERCENT);
taxableIncome = (long)RICH;
}
else if(taxableIncome > SORTOFRICH)
{
cumulatedTax += ((taxableIncome-SORTOFRICH) * TAXRATE_28PERCENT);
taxableIncome = (long)SORTOFRICH;
}
else if(taxableIncome > MIDDLECLASS)
{
cumulatedTax += ((taxableIncome-MIDDLECLASS) * TAXRATE_25PERCENT);
taxableIncome = (long)MIDDLECLASS;
}
else if(taxableIncome > NOTRICH)
{
cumulatedTax += ((taxableIncome-NOTRICH) * TAXRATE_15PERCENT);
taxableIncome = (long)NOTRICH;
}
else
{
cumulatedTax += ((taxableIncome) * TAXRATE_10);
taxableIncome = 0;
}
}
How about this? thinking in a more object oriented way. I did it for a few classes but you can add functionality by yourrself if you get the idea ;)
I implement it using the Decorator Pattern.
The common interface.
public interface TaxCalculator {
Double calculate(Double tax);
}
the base calculation for all taxes.
public class TaxCalculatorBase implements TaxCalculator{
#Override
public Double calculate(Double tax) {
return tax * TAXRATE_10;
}
}
The decorator abstract class
public abstract class TaxCalculatorDecorator implements TaxCalculator{
private final TaxCalculator decoratee;
/**
* #param decoratee
*/
public TaxCalculatorDecorator(TaxCalculator decoratee) {
super();
this.decoratee = decoratee;
}
#Override
public Double calculate(Double tax) {
Double returnValue = decoratee.calculate(tax);
return taxCalculate(returnValue);
}
protected abstract Double taxCalculate(Double tax);
}
and the decorators concrete classes. I only did 2 as an example
public class NotRichTaxCalculator extends TaxCalculatorDecorator{
public NotRichTaxCalculator(TaxCalculator taxCalculator) {
super(taxCalculator);
}
#Override
protected Double taxCalculate(Double tax) {
return ((tax-NOTRICH) * TAXRATE_15PERCENT);
}
}
Sort of rich tax calculator
public class SortOfRichTaxCalculator extends TaxCalculatorDecorator{
public SortOfRichTaxCalculator(TaxCalculator decoratee) {
super(decoratee);
}
#Override
protected Double taxCalculate(Double cumulatedTax) {
return ((cumulatedTax-SORTOFRICH) * TAXRATE_28PERCENT);;
}
}
and a simple Factory to create objects
public final class TaxCalculatorFactory {
private TaxCalculatorFactory(){}
public static TaxCalculator create(Double taxableIncome){
TaxCalculator taxCalculator= null;
if(taxableIncome > SORTOFRICH)
{
taxCalculator = new SortOfRichTaxCalculator(new NotRichTaxCalculator(new TaxCalculatorBase()));
}else if(taxableIncome > NOTRICH)
{
taxCalculator = new NotRichTaxCalculator(new TaxCalculatorBase());
}
else
{
taxCalculator =new TaxCalculatorBase();
}
return taxCalculator;
}
}
then in client code you only have to write this.
TaxCalculator taxCalculator= TaxCalculatorFactory.create(tax);
Double acumulatedTaxes = taxCalculator.calculate(tax);
Consider the fact that your tax brackets are 1:1 coupled with your tax rates.
final double[][] BRACKETS = {
{388350.0, 0.35},
{178650.0, 0.33},
{85650.0, 0.28},
{35350.0, 0.25},
{8700.0, 0.15}
};
/* ... */
for (double[] bracket: BRACKETS) {
if(taxableIncome > bracket[0]) {
cumulatedTax += ((taxableIncome-bracket[0]) * bracket[1]);
taxableIncome = (long)bracket[0];
}
}
cumulatedTax += taxableIncome * 0.1;
taxableIncome = 0;
If you really like C-style ALLCAPSCONSTANTS, then feel free to declare them, and just use their names instead of the literals I used in my double[][]. If you want to go native with Java, define a TaxBracket class. :)
Edit: misunderstood the intent of your code. I think my edit should do what you want.
I like the approaches above, but I'd encourage you to investigate using an EnumMap instead of the double[][] in agarrett's example.
How about this?
List<Integer> taxSlabs = new ArrayList<Integer>();
taxSlabs.put(388350);
taxSlabs.put(178650);
taxSlabs.put(85650);
taxSlabs.put(35350);
taxSlabs.put(8700);
List<Double> taxRates = new ArrayList<Double>();
taxRates.put(0.35);
taxRates.put(0.33);
taxRates.put(0.28);
taxRates.put(0.25);
taxRates.put(0.15);
//Variables for taxable income, and tax calculation.
long taxableIncome = income - deduction -(numberOfExemption * VAlUEOFEXEMPTION);
double cumulatedTax = 0.0;
for(int indx = 0; indx < taxSlabs.size(); indx++){
int slabLimit = taxSlabs.get(indx).intValue();
if(taxableIncome >= slabLimit ){
cumulatedTax += ((taxableIncome% slabLimit) * taxRates.get(indx).doubleValue());
taxableIncome = (long)slabLimit;
}
}

I am having problems with compareTo

Well, I need to make a project where I have two interfaces and they are both used in two unrelated classes. I managed to get everything else to work out properly except for the compareTo method. The two classes I have made are Car and Horse. What I am trying to do is compare the milesGoal from Horse to the one in Car and return either a 1, 0, or -1.
However when I try doing this I get the error "double could not be dereferenced"
I have been stuck on this for a while trying to find different ways to approach this part of the code. I tried using compareTo in the tester class instead of making a method but I got the same error and I am required to make it into a method.
This is the Horse Class:
public class Horse implements milesInterface , kilometersInterface{
private double currentMile;
private double currentKilo;
private double milesGoal;
private double kilosGoal;
private String horseBreed;
// CONSTRUCTORS
public Horse(){
currentMile = 0;
currentKilo = 0;
milesGoal = 0;
kilosGoal = 0;
horseBreed = "Unspecified";
}
public Horse(double cm, double ck, double mg, double kg, String hb){
currentMile = cm;
currentKilo = ck;
milesGoal = mg;
kilosGoal = kg;
horseBreed = hb;
}
// MILE METHODS
public double remainingMiles(){ // Finds the remaining miles
return milesGoal-currentMile;
}
public void halfMile(){ // Divides the desired goal halfway (Miles)
milesGoal = milesGoal/2;
}
public void setMileGoal(double newMile){ // Allows you to set a new goal
milesGoal = newMile;
}
public double getMileGoal(){
return milesGoal;
}
// KILOMETER METHODS
public double remainingKilos(){ // Finds the remaining Kilos
return kilosGoal-currentKilo;
}
public void halfKilo(){ // Divides the desire goal halfway (Kilos)
kilosGoal = kilosGoal/2;
}
public void setKiloGoal(){ // Allows you to set a new goal
kilosGoal = milesGoal*1.6;
}
public void setCurrentKilo(){ // Allows you to set the current Kilo
currentKilo = currentMile * 1.6;
}
// UNIQUE METHODS
public double getMilesStatus(){
return currentMile;
}
public double getKilosStatus(){
return currentKilo;
}
public String getHorseBreed(){
return horseBreed;
}
public void convertToKilos(){ // Converts current miles to kilometers
double kilos = currentMile * 1.6;
System.out.println("The current miles to kilometers is: " + kilos + "km.");
}
public void convertToMiles(){ // Converts current kilometers to miles
double miles = currentKilo * .6;
System.out.println("The current kilometers to miles is: " + miles + "m.");
}
public void milesPerHour(double hours){ // Calculates the mph to the goal by a time
double answer = milesGoal / hours;
System.out.println("The mph needed to reach the desination in " + hours + " hours: " + answer);
}
public void kilosPerHour(double hours){ // Calculates the kmph to the goal by a time
double answer = kilosGoal / hours;
System.out.println("The kilometers needed to reach the desination in " + hours + " hours: " + answer);
}
public int compareTo(Object Other){
if(milesGoal > (Horse)milesGoal.Other)
return 1;
if(milesGoal < (Horse)milesGoal.Other)
return 0;
return -1;
}
}
The Car class is pretty much the same as the Horse one and I need to find a way to compare both of their milesGoal to see which one is greater. I tried multiple things but it doesn't seem to work
This is the interface I made:
abstract interface milesInterface{
public double remainingMiles();
public void halfMile();
public void setMileGoal(double newMile);
public int compareTo(Object Other);
}
abstract interface kilometersInterface{
public double remainingKilos();
public void halfKilo();
public void setCurrentKilo();
public int compareTo(Object Other);
}
First, you are writting attribute.object. This is what fails. Other.milesGoal is a better option.
Another problema is with the casting. What you are doing is trying to cast milesGoal.other to Horse (you want to cast milesGoal)
You should use
if (milesGoal > ((Horse) other).milesGoal)
Also, use proper capitalization (variables go in lowercase, clases/interfaces in uppercase) and setters and getters.
Additionally, you probably will want to cast to the interface so you can use the methods with other clases that implement it
if (milesGoal > ((MilesInterface) other).milesGoal)
Firstly, (Horse)milesGoal.Other should be ((Horse) Other).milesGoal.
I would suggest overloading compareTo with one method for comparing to Horses and one method for comparing to Cars. Then your code looks like
public int compareTo(Horse horse){
if(milesGoal > horse.milesGoal)
return 1;
if(milesGoal < horse.milesGoal)
return -1;
return 0;
}
public int compareTo(Car car){
if(milesGoal > car.milesGoal)
return 1;
if(milesGoal < car.milesGoal)
return -1;
return 0;
}

Categories

Resources