I am trying to create code to create a specific object if it matches the values that the user enters.
For instance:
Suppose I have a Person class and a Car class
public class Person
{
private int x, y ,z;
private String str;
}
public class Car
{
private int x,y,z;
private double doub;
}
The user is prompted to enter 4 different values. The first three fields Person and Car are the same, but if the fourth value is a String or double, the program must create the corresponding object.
public class Input
{
public static void main (String args[])
{
int x,y,z;
?? other;
Scanner input = new SCanner(System.in);
x = input.nextInt();
other = input.???
}
}
How can i do this?
source
share