So I have three classes because I am trying to practice how to use custom type object and I ran into a problem. In my Auto class I made a method called showFeature() and I want the method to take in one parameter which would be the custom type Feature and it would print out the name and cost of the feature (Ex: The feature pants costs: 3000.0). But when I made the method it keep saying expected on the last quotation of Feature. Can anyone help me with this problem
public class Feature
{
public String name;
public double cost;
public Feature(String s, double d){
//step 1
name = s;
cost = d;
}
//step 4
}
public class TestAuto
{
public static void main(String args[]){
//instantiate an Auto object
Auto at = new Auto("AMG", 73.5);
//instantiate a Feature object
Feature fe = new Feature("Leather Seat", 3000);
//execute method addFeature with Feature object
at.showFeature(fe);
//prepare a new Feature object for receving information
Feature fe1 = new Feature("", 0);
//Run method discountValue with a feature and a new value
fe1 = at.discountValue("GPS", 15000, 0.2);
//print out the object
System.out.println(fe1);
}
}
public class Auto
{
public String name;
public double size;
public Auto(String s, double sz){
name = s;
size = sz;
}
//step 2: method showFeature()
public Feature showFeature(Feature){
System.out.println("The feature " +s+" costs: "+d);
}
public Feature discountValue(String s, double c, double d){
//Step 3: method to give discount on cost
double f = c - d;
return f;
}
}
Right now you have it taking in a Feature with no variable attached. You have a feature class which creates a feature object that takes in a String and a Double, which is probably why there is an expected note, because you haven't supplied the feature with any inputs.
//step 2: method showFeature()
public Feature showFeature(Feature f){
System.out.println("The feature " + f +" costs: "+ f.cost);
}