-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFish.java
More file actions
77 lines (69 loc) · 2.24 KB
/
Copy pathFish.java
File metadata and controls
77 lines (69 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
Base class file for Fish objects
Outlines the attributes of Fish the user will catch and gives them a basic method
*/
import java.lang.Math;
import java.util.Random;
public class Fish extends Object{
private String rarity; //will be rare, common, and uncommon
private String name;
private double size;
private int value; //how many coins it gives the user for catching
public int strength; //factors into how hard it is to catch
public Fish(String rarity, String name, double size, int value, int strength) {
this.rarity = rarity;
this.name = name;
this.size = size;
this.value = value;
this.strength = strength;
}
//getters and setters
public String getRarity() {
return rarity;
}
public void setRarity(String rarity) {
this.rarity = rarity;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getSize() {
return size;
}
public void setSize(double size) {
this.size = size;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
public int getStrength() {
return strength;
}
public void setStrength(int strength) {
this.strength = strength;
}
//method that allows the fish to fight against the user while it's on the line
public int fight(){
Random gen = new Random();
int fightChance = gen.nextInt(100);
if (Math.abs(fightChance - this.strength) < 10){ //the fish will not lose as much strength
System.out.println("The fish is fighting harder and not slowing down!");
return 1; //dont decrease fish strength
}
else{ //the fish will lose strength because it's tiring its self out
System.out.println("The fish is fighting hard but losing steam");
return 0; //decrease fish strength
}
}
//basic toString to print out the fish' attributes after catching it
public String toString() {
return "\nFish name: " + name + "\nRarity: " + rarity + "\nSize: " + size + "\nValue: "
+ value;
}
}