R
ros
Hello,
I have a class called Car and a main class that implements this class.
Both are pasted below.
I expect the implementation to print out the price of the car but it
is giving me price '0'.
Can anyone please advise as to what I am doing wrong.
Would be extremely thankful.
Ros
package InheritanceHW;
public class Car {
int speed;
int regularPrice;
String colour;
int getSalePrice(){
return regularPrice;
}
/** Creates a new instance of Car */
public Car(int regularPice, int speed, String colour) {
this.regularPrice = regularPrice;
this.colour = colour;
this.speed = speed;
}
}
package InheritanceHW;
public class MyOwnAutoShop {
public static void main(String args[]){
Car car1 = new Car(2003, 134, "Red");
//Sedan sedan1 = new Sedan(2134, 100, "blue", 13);
//Ford ford1 = new Ford(1970, 123, "Green", 1998, 400);
//Ford ford2 = new Ford(1980, 156, "White", 2001, 350);
System.out.println("The price of car1 is " +
car1.getSalePrice());
//System.out.println("The price of sedan1 is " +
sedan1.getSalePrice());
//System.out.println("The price of ford1 is " +
sedan1.getSalePrice());
//System.out.println("The price of ford2 is " +
sedan1.getSalePrice());
}
}
I have a class called Car and a main class that implements this class.
Both are pasted below.
I expect the implementation to print out the price of the car but it
is giving me price '0'.
Can anyone please advise as to what I am doing wrong.
Would be extremely thankful.
Ros
package InheritanceHW;
public class Car {
int speed;
int regularPrice;
String colour;
int getSalePrice(){
return regularPrice;
}
/** Creates a new instance of Car */
public Car(int regularPice, int speed, String colour) {
this.regularPrice = regularPrice;
this.colour = colour;
this.speed = speed;
}
}
package InheritanceHW;
public class MyOwnAutoShop {
public static void main(String args[]){
Car car1 = new Car(2003, 134, "Red");
//Sedan sedan1 = new Sedan(2134, 100, "blue", 13);
//Ford ford1 = new Ford(1970, 123, "Green", 1998, 400);
//Ford ford2 = new Ford(1980, 156, "White", 2001, 350);
System.out.println("The price of car1 is " +
car1.getSalePrice());
//System.out.println("The price of sedan1 is " +
sedan1.getSalePrice());
//System.out.println("The price of ford1 is " +
sedan1.getSalePrice());
//System.out.println("The price of ford2 is " +
sedan1.getSalePrice());
}
}