
. Write a function Model-of-Category for a Tata motor dealers, which accepts category of car customer is looking for and returns the car Model available in that category. the function should accept the following categories "SUV", "SEDAN", "ECONOMY", and "MINI" which in turn returns "TATA SAFARI" , "TATA INDIGO" , "TATA INDICA" and "TATA NANO" respectively.

Hi Friend,
Try the following code:
import java.util.*;
class TataMotors{
String category;
String model;
TataMotors(String category,String model){
this.category=category;
this.model=model;
}
public String getCategory(){
return category;
}
public String getModel(){
return model;
}
public static void ModelOfCategory(ArrayList<TataMotors> list){
Scanner input=new Scanner(System.in);
System.out.print("Enter Category: ");
String category=input.nextLine();
System.out.println();
System.out.print("Model is: ");
for (TataMotors tm : list){
if(tm.getCategory().equals(category)){
System.out.print(tm.getModel());
}
}
}
public static void main(String[] args)
{
ArrayList<TataMotors> list=new ArrayList<TataMotors>();
list.add(new TataMotors("SUV","TATA SAFARI"));
list.add(new TataMotors("SEDAN","TATA INDIGO"));
list.add(new TataMotors("ECONOMY","TATA INDICA"));
list.add(new TataMotors("MINI","TATA NANO"));
ModelOfCategory(list);
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.