Add OOP/Java/Lab/Week6/Account/AccountManagement.java
This commit is contained in:
parent
b883874dee
commit
cdeced26a8
76
OOP/Java/Lab/Week6/Account/AccountManagement.java
Normal file
76
OOP/Java/Lab/Week6/Account/AccountManagement.java
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
interface Sports {
|
||||||
|
int getNumberOfGoals();
|
||||||
|
String dispTeam();
|
||||||
|
}
|
||||||
|
|
||||||
|
class Hockey implements Sports {
|
||||||
|
|
||||||
|
private int goals;
|
||||||
|
private String team;
|
||||||
|
|
||||||
|
public Hockey(int goals, String team) {
|
||||||
|
this.goals = goals;
|
||||||
|
this.team = team;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumberOfGoals() {
|
||||||
|
return goals;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String dispTeam() {
|
||||||
|
return team;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Football implements Sports {
|
||||||
|
|
||||||
|
private int goals;
|
||||||
|
private String team;
|
||||||
|
|
||||||
|
public Football(int goals, String team) {
|
||||||
|
this.goals = goals;
|
||||||
|
this.team = team;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumberOfGoals() {
|
||||||
|
return goals;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String dispTeam() {
|
||||||
|
return team;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SportsMatch {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Hockey team1 = new Hockey(3, "India");
|
||||||
|
Hockey team2 = new Hockey(2, "England");
|
||||||
|
|
||||||
|
Football team3 = new Football(2, "AFC Richmond");
|
||||||
|
Football team4 = new Football(1, "West Ham United");
|
||||||
|
|
||||||
|
System.out.println("Hockey Match:");
|
||||||
|
displayWinner(team1, team2);
|
||||||
|
|
||||||
|
System.out.println("\nFootball Match:");
|
||||||
|
displayWinner(team3, team4);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void displayWinner(Sports team1, Sports team2) {
|
||||||
|
System.out.println(
|
||||||
|
team1.dispTeam() + " goals: " + team1.getNumberOfGoals()
|
||||||
|
);
|
||||||
|
System.out.println(
|
||||||
|
team2.dispTeam() + " goals: " + team2.getNumberOfGoals()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (team1.getNumberOfGoals() > team2.getNumberOfGoals()) {
|
||||||
|
System.out.println("Winner: " + team1.dispTeam());
|
||||||
|
} else if (team2.getNumberOfGoals() > team1.getNumberOfGoals()) {
|
||||||
|
System.out.println("Winner: " + team2.dispTeam());
|
||||||
|
} else {
|
||||||
|
System.out.println("It's a tie!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user