Error: no suitable constructor found for Car(int)
constructor car.Car.Car() is not applicable
(actual and formal argument lists differ in length)
constructor car.Car.Car(int,float) is not applicable
(actual and formal argument lists differ in length)
I'm posting all three projects in case there's something wrong with one of the two classes. The first is the Car.
package car;
import java.text.*;
import java.io.*;
public class Car {
int idNumber;
float dealerCost;
//Direct constructor
public Car(int newIdNumber, float newDealerCost)
{
idNumber = newIdNumber;
dealerCost = newDealerCost;
}
//Default constructor
public Car()
{
idNumber = 0000000;
dealerCost = 0;
}
//Observers
public int getIdNumber()
{
return idNumber;
}
public float getDealerCost()
{
return dealerCost;
}
public String toString()
{
return
"Vehicle ID Number: " + idNumber + "\n"
+ "Dealer cost: $" + dealerCost + "\n";
}
}
The second is the sold car:
package car;
public class SoldCar extends Car
{
//New fields
float soldPrice;
String customerName;
public SoldCar()
{
super(); //Superclass sets new fields
soldPrice = 0;
customerName = "";
}
public SoldCar(float newDealerCost, int newIdNumber, String customer, float price)
{
super(newIdNumber, newDealerCost); //Superclass constructor sets inherited fields
soldPrice = price;
customerName = customer;
}
//Observer method to return new fields
public String getCustomerName()
{
return customerName;
}
public float getSoldPrice()
{
return soldPrice;
}
public String toString()
{
String str = super.toString();
return (str + customerName + soldPrice); //Appends new field
}
}
And finally the driver, but I'm only testing it on the car at this point:
// Class TestBook is a driver to test class Book
package car;
import java.io.*;
import java.util.Scanner;
public class CarSales
{
public static void main(String[] args)
{
Car idNumber;
Car dealerCost;
Scanner inData = new Scanner(System.in);
idNumber = new Car(1245632);
dealerCost = new Car(14000);
System.out.println("Vehicle ID " + idNumber + "was purchased for " + dealerCost + " on October 11, 2001.");
}
}

New Topic/Question
Reply



MultiQuote




|