Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    14
    ReputationRep:
    Code:
    import java.util.Scanner;
    public class Newtable {
        public static int x;
        public static Person[] customer= new Person[100];
        
    	public static void main(String[] args){
            int countP = 0;
        	Scanner input=new Scanner(System.in);
    		while(x==0){
        		System.out.print("Enter person's name: ");
        		String name = input.nextLine();
        		System.out.print("Enter person's nationality: ");
        		String nationality =  input.nextLine();
        		Person.customer[countP]=new Person(name, nationality);
        		countP++;
        		System.out.println("\nBook another seat? (Y/N):");
        		String item=input.nextLine();
        		if(item.equals("n")||item.equals("N")){
        			x=1;
        		}
        		if(item.equals("y")||item.equals("Y")){
        			x=0;
        		}
        	}
    		for(int a=0;a<100;++a){ 	
    			if(Person.customer[a]!=null){
    				System.out.println("Name: " +Person.customer[a].getName() +", Nationality: " +Person.customer[a].getNationality());	
    			}
    		}
    	}
    }

    Code:
    public class Person {
    	public static String name;
    	public static String nationality;
    	
    	public Person(String name, String nationality){
    		this.name = name;
    		this.nationality = nationality;
    	}
    	
    	public static String getName(){
    		return name;
    	}
    	
    	public static String getNationality(){
    		return nationality;
    	}
    }
    typing in:
    joe
    american
    y
    smith
    british
    n

    should give the end output (for the for loop):

    Name:joe, Nationality: american
    Name:smith, Nationality: british
    • Thread Starter
    Offline

    14
    ReputationRep:
    managed to fix it

    Code:
    public class Person {
    	public String name;
    	public String nationality;
    	
    	public Person(String name, String nationality){
    		this.name = name;
    		this.nationality = nationality;
    	}
    	
    	
    	
    	public String getName(){
    		return this.name;
    	}
    	
    	
    	
    	public  String getNationality(){
    		return this.nationality;
    	}
 
 
 
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    Would you like to hibernate through the winter months?
    Useful resources
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Quick reply
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.