/* 6. Write a Java program to read name, register number, date of birth, address, phone number a student.Concatenate these to frame a single content by delimiting each detail with a special symbol, pass it to a method which should separate and display the details of the student. Declare a class containing the following methods:
void getInformation() – to read student information. It should call concatenate(,,,,) by passing relevant information. void concatenate(String name, string regNo, String dob, String address, String phoneNo) to join the information to frame a single content. It should call extractInformation(…) by passing the concatenated information. void extractInformation(String joinedInfo) to extracted concatenated contents and to display the information. Declare another class to contain main () method which calls void
getInformation( ).
Sample output:
Student Name: Venkata Krishna
Register Number: BC171128
Date of Birth: 10/05/1996
Address: No. 5, First Cross, Nehru Nagar, Sagar.
Phone Number: 9900990099
Concatenated content:
Venkata Krishna%BC171128%10/05/1996%No. 5, First Cross, Nehru Nagar, Sagar.%9900990099
(Application: This is the way using which collection of information is communicated between
client and server in networked environment)*/
import java.io.*;
class add
{
String name, regno, dob, address, phone;
public void getInformation()throws IOException
{
DataInputStream in=new DataInputStream(System.in);
System.out.println("Enter your name:");
name=in.readLine();
System.out.println("Enter your regno:");
regno=in.readLine();
System.out.println("Enter your dob:");
dob=in.readLine();
System.out.println("Enter your address:");
address=in.readLine();
System.out.println("Enter your phone number:");
phone=in.readLine();
concatenate(name,regno,dob,address,phone);
}
public void concatenate(String name, String regno, String dob,
String address, String phone)
{
String joinedInfo=name+"%"+regno+"%"+dob+"%"+address+"%"+phone;
extractinformation(joinedInfo);
}
public void extractinformation(String joinedInfo)
{
int len=joinedInfo.length();
int index1=joinedInfo.indexOf("%");
String name=joinedInfo.substring(0,index1);
System.out.println("name="+name);
int index2=joinedInfo.indexOf("%",index1+1);
String regno=joinedInfo.substring(index1+1,index2);
int index3=joinedInfo.indexOf("%",index2+1);
String dob=joinedInfo.substring(index2+1,index3);
int index4=joinedInfo.indexOf("%",index3+1);
String address=joinedInfo.substring(index3+1,index4);
String phone=joinedInfo.substring(index4+1,len);
System.out.println("\nDetails of Student:");
System.out.println("Student Name: "+name);
System.out.println("Register Number: "+regno);
System.out.println("Date of Birth: "+dob);
System.out.println("Address: "+address);
System.out.println("Phone Number: "+phone);
}
}
class Prog61
{
public static void main(String args[])throws IOException
{
add obj=new add();
obj.getInformation();
}
}
Search This Blog
Monday, 25 July 2022
6. Java Program to read Student Information and concatenate the same using delimiter.
Labels:
New_Java_Programs
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment