Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1420f9f

Browse files
committedJan 16, 2025
Eighth Program
1 parent 5f5c93e commit 1420f9f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
 

‎VotingEligibility.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Student {
2+
private String name;
3+
private int age;
4+
5+
public Student(String name, int age) {
6+
this.name = name;
7+
this.age = age;
8+
}
9+
10+
public boolean isEligibleToVote() {
11+
return age >= 18;
12+
}
13+
14+
public String getName() {
15+
return name;
16+
}
17+
}
18+
19+
public class VotingEligibility {
20+
public static void main(String[] args) {
21+
if (args.length < 2) {
22+
System.out.println("Enter like this in cmd: java VotingEligibility <name> <age>");
23+
return;
24+
}
25+
26+
String name = args[0];
27+
int age = Integer.parseInt(args[1]);
28+
29+
if (age >= 18) {
30+
System.out.println(name + " is eligible to vote.");
31+
} else {
32+
System.out.println(name + " is not eligible to vote.");
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)
Please sign in to comment.