Thursday, January 3, 2019

DAA 02 B - CUSTOMER CLASS (USE OF STRINGTOKENIZER)

2 B - Write a Java class called Customer to store their name and date_of_birth. The date_of_birth format should be dd/mm/yyyy. Write methods to read customer data as <name, dd/mm/yyyy> and display as <name, dd, mm, yyyy> using StringTokenizer class considering the delimiter character as “/”.

import java.util.Scanner;
import java.util.StringTokenizer;
class Customer
{
private String name;
private String date_of_birth;
public Customer(String name, String date_of_birth)
{
super();
this.name = name;
this.date_of_birth = date_of_birth;
}
public Customer ()
{
}

public void readData(String name, String date_of_birth)
{
this.name = name;
this.date_of_birth = date_of_birth;
}
public void displayData()
{
StringTokenizer st=new StringTokenizer(this.date_of_birth,"/");
System.out.print(this.name+",");
while(st.hasMoreTokens())
{
System.out.print(st.nextToken()+",");
}
}
}

public class lab2b
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
System.out.println("Enter Name :-");
String name=in.nextLine();
System.out.println("Enter Date of birth:-");
String date=in.next();
Customer customer=new Customer();
customer.readData(name, date);
customer.displayData();
}

}

OUTPUT : (click on image to zoom)


No comments:

Post a Comment