Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Answers/40230212013/quidditch/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}
18 changes: 18 additions & 0 deletions Answers/40230212013/quidditch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Getting Started

Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.

## Folder Structure

The workspace contains two folders by default, where:

- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies

Meanwhile, the compiled output files will be generated in the `bin` folder by default.

> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management

The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
Binary file added Answers/40230212013/quidditch/bin/beater.class
Binary file not shown.
Binary file added Answers/40230212013/quidditch/bin/chaser.class
Binary file not shown.
Binary file added Answers/40230212013/quidditch/bin/keeper.class
Binary file not shown.
Binary file added Answers/40230212013/quidditch/bin/match.class
Binary file not shown.
Binary file added Answers/40230212013/quidditch/bin/myApp.class
Binary file not shown.
Binary file added Answers/40230212013/quidditch/bin/player.class
Binary file not shown.
Binary file added Answers/40230212013/quidditch/bin/seeker.class
Binary file not shown.
Binary file added Answers/40230212013/quidditch/bin/success.class
Binary file not shown.
Binary file added Answers/40230212013/quidditch/bin/team.class
Binary file not shown.
14 changes: 14 additions & 0 deletions Answers/40230212013/quidditch/src/beater.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class beater extends player implements success{
private static final double stopChance = 0.999999;
public beater(String name, int number)
{
super(name, number);
}
@Override
public boolean isSuccessfull() {
// TODO Auto-generated method stub
return Math.random() < stopChance;
}


}
15 changes: 15 additions & 0 deletions Answers/40230212013/quidditch/src/chaser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class chaser extends player implements success{
private static final double scoreChance = 0.3;
public chaser(String name, int number)
{
super(name, number);
}

@Override
public boolean isSuccessfull() {
// TODO Auto-generated method stub
return Math.random() < scoreChance;
}


}
14 changes: 14 additions & 0 deletions Answers/40230212013/quidditch/src/keeper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class keeper extends player implements success {
private static final double saveCahnce = 0.7;
public keeper(String name, int number)
{
super(name, number);
}
@Override
public boolean isSuccessfull() {
// TODO Auto-generated method stub
return Math.random() < saveCahnce;

}

}
53 changes: 53 additions & 0 deletions Answers/40230212013/quidditch/src/match.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
public class match {
private team team1;
private team team2;
public match(team team1, team team2)
{
this.team1=team1;
this.team2=team2;
}
public void start()
{
for(int round = 1; round<=100; round++)
{
team1.play();
team2.play();
if(team1.getGoals()>=150)
{
System.out.println(team1.getTeamName()+" found the golden snitch! They get 150 Scors.");
System.out.println(team1.getTeamName() + ": " + team1.getGoals());
System.out.println(team1.getTeamName() + " Wins.");

break;
}
else if(team2.getGoals()>=150)
{
System.out.println(team2.getTeamName()+" found the golden snitch! They get 150 Scores.");
System.out.println(team2.getTeamName() + ": " + team2.getGoals());
System.out.println(team2.getTeamName() + " Wins.");
break;

}
System.out.println("Round " + round + ":");
System.out.println(team1.getTeamName() + ": " + team1.getGoals());
System.out.println(team2.getTeamName() + ": " + team2.getGoals());
}
if(team1.getGoals() < 150 && team2.getGoals() < 150)
{
int team1Score = team1.getGoals();
int team2Score = team2.getGoals();

if(team1Score > team2Score)
{
System.out.println(team1.getTeamName() + " Wins.");

}
else if(team2Score > team1Score)
{System.out.println(team2.getTeamName() +" Wins.");}
else
{
System.out.println("Drow.");
}
}
}
}
15 changes: 15 additions & 0 deletions Answers/40230212013/quidditch/src/myApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import java.util.Scanner;

public class myApp {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter your team Name: ");
team team1 = new team(input.nextLine());
System.out.println("Enter the Name of the opponent team: ");
team team2 = new team(input.nextLine());
match match = new match(team1, team2);

match.start();
}

}
16 changes: 16 additions & 0 deletions Answers/40230212013/quidditch/src/player.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public abstract class player {
private String name;
private int number;
public player (String name, int number)
{
this.name=name;
this.number=number;
}
public String getName() {
return name;
}
public int getNumber() {
return number;
}
public abstract boolean isSuccessfull();
}
14 changes: 14 additions & 0 deletions Answers/40230212013/quidditch/src/seeker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class seeker extends player implements success {
private static final double snitchChance = 0.05;
public seeker(String name, int number)
{
super(name, number);
}
@Override
public boolean isSuccessfull() {
// TODO Auto-generated method stub
return Math.random() < snitchChance;
}


}
3 changes: 3 additions & 0 deletions Answers/40230212013/quidditch/src/success.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public interface success {
public boolean isSuccessfull();
}
79 changes: 79 additions & 0 deletions Answers/40230212013/quidditch/src/team.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
public class team {
private player[] players;
private int goals;
private String teamName;

public team(String teamName)
{
this.teamName = teamName;
players = new player[7];
players[0] = new keeper("Keeper", 1);
players[1] = new seeker("Seeker", 2);
for(int i=2 ; i<5 ; i++)
{
players[i] = new chaser("Chaser"+(i-1), i+1);

}
for(int i=5 ; i<7 ; i++)
{
players[i] = new beater("Beater"+(i-4), i+1);
}
goals = 0;
}
public void setGoals()
{
goals++;
}
public void play()
{
int successFullKeepers=0;
int successFullBeaters=0;
int successFullChasers=0;
int successFullSeeker=0;
if(players[1] instanceof seeker && players[1].isSuccessfull())
{
successFullSeeker++;
}
if(players[0] instanceof keeper && players[0].isSuccessfull())
{
successFullKeepers++;
}

for(int i=2 ; i<5 ; i++)
{
if(players[i] instanceof chaser && players[i].isSuccessfull())
{
successFullBeaters++;
}
}
for(int i=5 ; i<7 ; i++)
{
if(players[i] instanceof beater && players[i].isSuccessfull())
{
successFullChasers++;
}
}
if(successFullSeeker==1)
{
successFullSeeker();
}
else if(successFullKeepers>0 && successFullBeaters>=1 && successFullChasers>=2)
{
setGoals();
}
}
public int getGoals()
{
return goals;
}
public void successFullSeeker()
{
this.goals += 150;

}
public String getTeamName() {
return teamName;
}

}