Write a complete java program that demonstrates the follolwing concepts: Input a
ID: 3643590 • Letter: W
Question
Write a complete java program that demonstrates the follolwing concepts:Input and Output.
Selection (e.g. if statement).
Arithmetic.
Loops.
Arrays.
Classes/Objects
The program will be called fishing and must include the following;
Is it the right season. If user input is June to September, return go fishing, if not return Do not go fishing its the wrong season.
Is it the right weather. If user input is sunny return go fishing its a good day to fish, if not return its a bad day to fish stay home.
Is the fish caught legal to keep. If user input is trout and 12 inches long or longer return great job you caught a legal fish, if not return throw it back it is not a legal fish.
Explanation / Answer
import java.util.Scanner; public class fishing { public Static void main(String args[]) { System.out.println("Is it the right season?"); Scanner input = new Scanner(System.in); String ans = input.nextLine(); if !(ans == "June" || ans == "July" || ans == "August" || ans == "September") System.out.println("Do not go fishing. It is the wrong season"); else { System.out.println("Go fishing."); System.out.println("Is it the right weather?"); if !(ans == "Sunny") System.out.println("Return. It is a bad day to fish. Stay home."); else { System.out.println("Go fishing. It is a good day to fish."); System.out.println("Is the fish legal to keep?"); if !("Trout 12 inches long") System.out.println("Throw it back. It is not a legal fish."); else System.out.println(" Great job! You caught a legal fish."); } } } } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.