Currently I'm stuck with Java. its for my assignment, tuesday due and I can only meet my tutor tomorrow but I'm afraid that it may be too late.
here is the question:
I have a CarMart class and a CarMartApp. now I'm doing the case for adding a car to a category type.
at first when my user selects that option, it will:
Prompt user for category number
Prompt user for car number, brand and price
Create a new car object
Add car object to category
Display if the adding was successful or unsuccessful
BELOW IS MY addCarToCategory Method in the class file
public boolean addCarToCategory (Car car, int categoryNumber)
{
boolean result = false;
for (int i = 0; i < categoryListArray.length; i++)
if ((categoryListArray[i] != null)&&(categoryListArray[i].getCategoryNumber() == categoryNumber))
{
if ( categoryListArray[i].addItem(car) == 1)
{
result = true;
}
else if ( categoryListArray[i].addItem(car) == -1)
{
result = false;
}
break;
}
return result;
}
BELOW is my MENU OPTION in the DRIVER CLASS
case 2:
System.out.println("Enter Category Number: ");
int categoryNumber = sc.nextInt(); sc.nextLine();
System.out.println("Enter Car Number: ");
String carNum = sc.nextLine();
System.out.println("Enter Car Brand: ");
String carBrand = sc.nextLine();
System.out.println("Enter Car Price: ");
String carPrice = sc.nextLine();
Car car = new Car (carNum, carBrand, carPrice);
boolean resultAddCar = false;
resultAddCar = carMart.addCarToCategory (car, categoryNumber);
if(resultAddCar == true)
{
System.out.println("Car Added!");
}
else if(resultAddCar == false)
{
System.out.println("Unable to add Car!");
}
break;