Ask coding questions

← Back to all posts
I have no idea what the error is
12312312312 (1)

I have an assignment due tomorrow and I have NO IDEA if I'm using the right "language" and if this'll work or not-

this is what the program is supposed to do:
1) It's supposed to ask a question for a quote from one of the authors

2) After giving a response, it has to give a quote...

Commentshotnewtop
AllAwesome497 (242)
public class Choose_Author 

{ 

is the error
it should be:

public class Choose_Author(){
<code>
}

on more than one occasion

12312312312 (1)

@AllAwesome497 but it says there's 3 errors now..

AllAwesome497 (242)

@12312312312 the <code> was pseudocode u weren't supposed to put it there

algore (20)

Fixed your code here you go, you had alot of issues first the class name was not the same as the file name this can cause many issues, second you need to ensure you are checking the string based on lowercase otherwise user error is very easy, third you were doing the if statements very wrong, here is the new and improved code please read through it so you can learn how to properly do it for next time, sorry I am a bit late.

class Main {
	public static void main(String[] args){
		String name;
		Scanner scan = new Scanner(System.in);
		System.out.println("Pick one of the authors. (e.g J.K Rowling, William Shakespeare and Mark Twain.)"); 

		name = scan.nextLine(); 

		if (name.toLowerCase().equals("mark twain")){
			System.out.println("If you tell the truth, you don't have to remember anything. - Mark Twain");
		}else if (name.toLowerCase().equals("j.k rowling")){
			System.out.println("Happiness can be found, even in the darkest of times, if one only remembers to turn on the light. -J.K Rowling");
		}else if (name.toLowerCase().equals("william shakespeare")){
			System.out.println("If music be the food of love, play on. - William Shakespeare");
		}
	}
}	



 
 
AllAwesome497 (242)

Also, the file name must be Choose_Author.java
because public class Choose_Author{ choose author must be the file name without extension