I want a bit of help regarding the code I have written just as a sample. And I am currently using Atom Notepad for my codes.
Problem Statement:
Take user input for Plane Details.
Expected Output:
Print the user entered data.
Problem:
I am able to successfully take input from the user but while printing, all the values are shown as NULL
.
CODE:
import java.util.*;
class Planes{
String Name;
int Number_of_Pylons;
String Type;
void EnterValues()
{
Scanner s=new Scanner(System.in);
System.out.println("NAME: ");
String Name=s.nextLine();
System.out.println("PYLONS: ");
int Number_of_Pylons=s.nextInt();
s.nextLine();
System.out.print("TYPE OF CRAFT: ");
String Type=s.nextLine();
}
};
class Base{
public static void main(String args[]){
Planes air[]=new Planes[2];//DID NOT CREATE OBJECTS, REFERENCE ARRAY!!!!!!!!!
for(int j=0;j<2;j++){
air[j]=new Planes();
}// CREATED OBJECTS OF CLASS PLANE!!!!!!!!!
int i=0;
for(i=0;i<2;i++)
{
System.out.println("Enter values for the planes:");
air[i].EnterValues();
}
System.out.println(air[0].Name);//Test for Print, prints NULL idk why :(
for(i=0;i<2;i++)//Display the Entered Details
{
System.out.println("Name: "+air[i].Name+"Number of Pylons: "+air[i].Number_of_Pylons+"Type: "+air[i].Type);
}
}
};
It is a fairly simple code but i cant seem to be able to get it to work. Also I apologise for my English. Its not my first language.