When it says to make sure that the getDescription method doesn't return any null strings, I went to make a while loop that broke once there was an input such as this.
public static class Idea{
public String getDescription() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String anything = br.readLine();
while(true)
if (anything.equals(null))
System.out.println("Give me an Idea");
else{
break;
}
return anything;
}
}
But it replied that the statement, (anything.equals(null)) would always be false. So now I'm confused as to why it isn't being verified.
Am I just overthinking this right now? I feel like I am.
EDIT: I was just overthinking it.
package com.codegym.task.task06.task0617;
/*
Notepad for new ideas
1. In the Solution class, create the public static Idea class
2. In the Idea class, declare a public String getDescription() method that returns any non-empty string
3. In the Solution class, create a static public void printIdea(Idea idea) method that will display a description of the idea (what the getDescription method returns)
Requirements:
1. In the Solution class, create the public static Idea class.
2. In the Idea class, create the public String getDescription() method.
3. The getDescription method must return any non-empty string.
4. In the Solution class, create a public static void printIdea(Idea idea) method.
5. The printIdea method should display the idea description on the screen.
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Solution {
public static class Idea{
public String getDescription() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String anything = br.readLine();
return anything;
}
}
public static void printIdea(Idea idea) throws IOException{
System.out.println(idea.getDescription());
}
public static void main(String[] args) throws IOException {
printIdea(new Idea());
}
//write your code here
}