Answer to Question #318072 in Java | JSP | JSF for ankitha

Question #318072

developer needs to input the following information from the console using programming to register passenger:passenger id:a random 7 digit number for passenger id with a default value;....passenger name:a string field for passenger name(maximum 50 characters);....email:a string field to capture the email;....password:a string field for password(maximum 30 characters);....Address:a string field to capture street,city details(maximum 100 characters);...Contact number:text field(maximum 10 characters);....once all fields are taken as input,passenger details need to be inserted in array/list/appropiate collection.after successful registration,a registration acknowledgment message need to be displayed on the console as "passenger registration is successfull".


1
Expert's answer
2022-03-25T12:10:42-0400
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;


class Person{

    String passengerID, passengerName, email, password, address, contactNumber;

    public Person(String passengerID, String passengerName, String email, String password, String address, String contactNumber) {
        this.passengerID = passengerID;
        this.passengerName = passengerName;
        this.email = email;
        this.password = password;
        this.address = address;
        this.contactNumber = contactNumber;
    }
}

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        List<Person> list = new ArrayList<>();
        Random rand = new Random();

        String passengerID = "";
        for(int i = 0; i<7; i++){
            int a = rand.nextInt(10);
            String k = Integer.toString(a);
            passengerID += k;

        }

        System.out.print("Enter passenger's name: ");
        String passengerName = in.nextLine();

        System.out.print("Enter passenger's email: ");
        String email = in.next();

        System.out.print("Enter passenger's password: ");
        String password = in.next();

        System.out.print("Enter passenger's address: ");
        String noob = in.nextLine();
        String address = in.nextLine();

        System.out.print("Enter passenger's contact number: ");
        String contactNumber = in.nextLine();

        list.add(new Person(passengerID, passengerName, email, password, address, contactNumber));

        if(!list.isEmpty()){
            System.out.print("Passenger registration is successfull");
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS