Brief discussion on OOP concepts, constructors, and methods.
Discussion of the FishingTrip and FishingApp classes.
public class FishingTrip {
private String location;
private int fishCaught;
private String weather;
public FishingTrip() {
this.location = "Unknown";
this.fishCaught = 0;
*************** insert the correct Code ***********
}
public FishingTrip(String location, int fishCaught) {
this.location = location;
*************** insert the correct Code ***********
}
public FishingTrip(String location, int fishCaught, String weather) {
*************** insert the correct Code ***********
this.weather = weather;
}
public void displayTripDetails() {
*************** insert the correct Code ***********
}
public void catchFish(int newFish) {
this.fishCaught += newFish;
*************** insert the correct Code ***********
}
public void changeWeather(String newWeather) {
this.weather = newWeather;
System.out.println("Weather updated to: " + this.weather);
}
}
public class FishingApp {
public static void main(String[] args) {
FishingTrip trip1 = new FishingTrip();
*************** insert the correct Code ***********
trip3.changeWeather("Rainy");
}
}
Compile and run FishingApp.java. Observe outputs showing different fishing trip scenarios.
We built a Java program with a fishing-related theme using constructors and methods.
Trip 1:
Fishing Trip Location: Unknown
Fish Caught: 0
Weather Condition: Sunny
Trip 2:
Fishing Trip Location: Lake Superior
Fish Caught: 5
Weather Condition: Cloudy
New total fish caught: 8
Trip 3:
Fishing Trip Location: Pacific Ocean
Fish Caught: 10
Weather Condition: Windy
Weather updated to: Rainy
You will drop off 5 files into Google Classroom:
• Your files will be: (Remember the python program is dropped off first.)
• PX_lastname_Fishing.java (Java program that is instantiated)
• PX_lastname_FishingTester.java (Java program that instantiates the object)
• PX_lastname_Fishing.png (Screenshot of class notes)
• PX_lastname_Fishing.png (Screenshot inside Eclipse)
• PX_lastname_Fishing.mp4 (Video running the program)
If you do not understand this assignment,
ask Mr. Cusack and/or attend tutorials.