so I'm redoing my test right now for Programming language concepts because I got a 30% on it. I think my teacher graded it wrong though (unless I completely misunderstood the question) and took off 30 points for these three questions:
- Write a program that can accept a multiline comment in C/Java
- Write a program that can accept a single line comment in C/Java
- Write A program that can accept a string that has your name in it
the feedback just reads that i got -10 points off each
Did I do this wrong/ incorrectly? Here's my code for each:
Question 8
class Main {
public static void main(String[] args) {
/* A multiline comment is a comment
that spans multiple lines in
a program :)
*/
System.out.println("Hello world!");
}
}
Question 9
class Main {
public static void main(String[] args) {
//This is a one line comment
System.out.println("Hello world!");
}
}
Question 10
class Main {
public static void main(String[] args) {
String x = "Kayla";
String y = " Moore";
System.out.println("Hello! My name is: " x y );
}
}
Please help me understand!
CodePudding user response:
I believe your teacher meant for the program to accept strings as an argument.
That's what the 'args' in the main method represents, you would pass an argument, or in this case a comment, when running the program.
The String[] args would be represented as an array of strings. You would simply have to access this in your program like a normal array.
This is all a hunch on what is asked based on your post though, clarify with your teacher on this.
CodePudding user response:
Yes, I think you have missungerstood the questions. The task is to write a program that accepts single/multi line comment/your name. That means it takes an input from somewhere (console, file, network etc.), from eg. the user and probably answers whether it contained the relevant comment/name. What you have done in contrast is written a program that simply contains a comment/name.
CodePudding user response:
"Write a program that can accept a multiline comment in C/Java" means that you should write a program that accepts a String as input, and then checks whether this String follows the rules for Java/C/C multiline comments:
public final class Main
{
public static final void main( final String... args )
{
if( !isValidMultilineComment( args [0] ) throw new IllegalArgumentException();
System.out.println( "Valid comment entered!" );
}
}
So now your task is to implement the function isValidMultilineComment(String)
…
The task for your question #9 is similar, but there you have to implement isValidSingleLineComment(String)
.
And for #10, the check is simply
…
if( !args.contains( "Kayla Moore" ) ) throw new IllegalArgumentException();
…