Marathon Registration in java

Question:

To participate in a marathon competition we need to register ourself by providing the following details.

Name

Age

Gender

Contact no

After obtaining all the details, display the message as “Registered Successfully”, if any of the input is incorrect handle the exception (InputMismatchException) and display as “Invalid Input”.

Partial Code is given to do the above task.

Sample Input and Output1:

Enter name: john

Enter age: 64

Enter Gender: m

Enter Contact no: 6547891230

Registered Successfully

Sample Input and Output2:

Enter name: john

Enter age: ten

Invalid Input

Sample Input and Output3:

Enter name: john

Enter age: 64

Enter Gender: 77

Invalid Input

CODE:

Main.java

import java.util.Scanner;

 public class Main {
  public static void main(String[] args) {
 		Scanner sc=new Scanner(System.in);
 		String date=sc.next();
  	    //FILL CODE
 		Birthday a= new Birthday();
 	System.out.println(a.findDay(date));
 	
 	}
   }

marathon.java

public class Marathon {
	
	private String name;
	private int age;
	private char gender;
	private long contactNo;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public char getGender() {
		return gender;
	}
	public void setGender(char gender) {
		this.gender = gender;
	}
	public long getContactNo() {
		return contactNo;
	}
	public void setContactNo(long contactNo) {
		this.contactNo = contactNo;
	}
	
	public Marathon(){}

}
  1. Array Manipulation – Use try with multi catch

Leave a Comment

Scroll to Top