Computer Science, asked by suchi143biswas52, 9 months ago

Write a program to create a class Voter which contains attributes name, date_of_birth and voter_id and voter has a Voter_Card. Provide appropriate constructor to initialize all the attributes of the Voter but voter id must be assigned automatically only when the age of the voter is greater than or equal to 18 years.
VoterCard is a nested class with attributes voter_id and Voter_name. Make sure that voter card is created only when user is a valid voter and if it is already created then must not be assigned the new voter id.
Program in Java.

Answers

Answered by yashyg101
2

Answer:Coding is Below ....

Mark it as a branliest ...

Explanation:class Voter

{

String name;

String dob;

int id;

Integer age;

//boolean card;

Voter(String names , String dobs , int ids , Integer ages)

{

name = names;

dob = dobs;

age = ages;

if(age > = 18)

{

id= ids;

}

// card = cards;

}

class Voter_Card

{

boolean status;

String votername;

int voterid;

Voter_Card(String voternames , int votersid , boolean statuss)

{

votername = voternames ;

voterid = votersid ;

status = statuss;

}

}

public void display()

{

System.out.println(votername+ "\t" + voterid +"\t"+dob+"\t"+age+"\t"+status+"\t");

}

}

class main

{

public static void main(String...rtk)

{

Treeset ts = new Treeset();

Voter obj = new Voter("Raj" , "04/04/1998" , 11605461 , 18);

Voter obj1 = new Voter("Srinjay" , "05/06/1999" , 11605641 , 17);

Voter obj2 = new Voter("Dam" , "06/05/1997" , 11605879 , 19);

ts.add(obj) ; ts. add(obj1) ; ts.add(obj2);

Iterator i = new iterator();

int a=2;

while(i.hasNext())

{

Voter e = e.next();

if(e.age >= 18)

{

namess = e.name;

idss = e.id;

Voter.Voter_Card obj4 = new Voter.Voter_Card(namess , idss, true);

}

e.display();

}

}

}

Similar questions