So for an assignment in my programming class, we are supposed to make an ArrayList to store objects of a class created in a previous assignment. My only problem is that i'm not exactly sure how to make an add method for an object in java.
The class that we are making objects from is a class designed to give information about different cars. Here's the code for this class here:
public class NewCar
{
String year;
String make;
String model;
String _year;
String _make;
String _model;
double sticker_price = 0;
double discount = 0;
double sales_tax = 0;
int months = 0;
double final_price = 0;
public NewCar(String _year, String _make, String _model)
{
year = _year;
make = _make;
model = _model;
}
public double calcFinalPrice(double _sticker_price, double _discount, double _sales_tax)
{
return final_price = ((_sticker_price - _discount) + _sales_tax *(_sticker_price - _discount));
}
public double calcZeroPctMonPayt(int _months)
{
return (final_price / 6);
}
}
Our professor expects us to use the calcFinalPrice method on each new object that we enter into the ArrayList as well, but I'm confused as to how to go about this in a singular method. The only ArrayList example we've done in class was a simple String type shopping list so i'm completely confused as to how to make a list of Objects.
Here's what I have so far, if someone could explain to me what's supposed to go into the add method to achieve the professors desired results I'd be super appreciative!
import java.util.*;
import java.util.ArrayList;
public class NewCarList
{
private ArrayList<NewCar> carList = new ArrayList<NewCar>();
public void add()
{
}
}