Posted: Tue Dec 02, 2008 8:58 pm Post subject: Grade 11 Mid-Term ISU
Well, This is my mid-term CPT,
Completed in Approx. 1Hrs30Mins,
My CPT /ISU is to create a quiz, with 15 questions on any appropiate topic you want.
I chose Mario(Nintendo). I completed it, but i'm wondering if anyone has any suggestions for improvement,
or to find any flaws. I think my Program, Is error proof, May not be the best error proofed program, But I think it'll be fine.
Suggestions, Bad & Constructive Criticism welcome
Sorry for the indentation, My teacher wants it to be like that; He says it's a good habit + the commenting.
Java:
package cpt;
import java.util.*;//Imports all util libraries. publicclass cpt
{ publicstaticvoid main(String[] args) { //Variables And Scanner class.
Scanner scan = new Scanner(System.in);//Allows Input/Output use String InputAnswer = " ";//Variable to hold users answer. String GameLoop = " ";//Variable to hold users game loop answer. String Username = " ";//Varaible to hold Username Answer. int ScoreCounter = 0;//Varaible to hold the users score.
//Intro to game. System.out.println(":---------------------------------------------:");
System.out.println("|Welcome to the Mario Quiz; Created by duyzee!|");
System.out.println(":---------------------------------------------:");
//Name Input System.out.println("\nPlease Enter Your Name. : ");//Asks user a question.
Username = scan.nextLine();;//Stores user input to "Username" for future references. if(Username.isEmpty())//The condition to check if the username is empty. {//The Brace to hold all of this "If" Code. System.out.println("Invalid Name.\nYour name is now duyzee :).");//Displays to screen; Username invalid, Default name assigned.
Username = "duyzee:)";//Sets the username to duyzee:)
} //GameStart. System.out.println("\nHit Enter to start.");//Sets the user to hit enter to start; Or Enter in any key to begin.
GameLoop = scan.nextLine();//Scan next line //Load Section. System.out.println("Loading Quiz, Please wait..");//False-like load, Displaying a load set. try {//starts try Thread.currentThread().sleep(5000);//sets the delay to be 5000 milliseconds. }//ends try catch(InterruptedException e)//No idea what this does {//starts catch
e.printStackTrace();//No idea what this does. }//ends catch //Start. System.out.println("---------------------------------");
System.out.println("Begin.");//Displays to screen text.
//Game Loop. while(true)//Sets the loop to be true, til' the end. {//Starts the loop.
//Question 1 System.out.println("\nQuestion 1.");
System.out.println("What is Mario's last name ? : ");//Question System.out.println("a. Diaz ");//1 of 4 possible ansers System.out.println("b. Mario ");//1 of 4 possible ansers System.out.println("c. Jumper");//1 of 4 possible ansers System.out.println("d. Toadstool\n");//1 of 4 possible ansers
InputAnswer = scan.nextLine();//Scans user input, Stores it.
if(InputAnswer.equalsIgnoreCase("b"))//The condition to check if the answer is correct or incorrect. {//Starts if System.out.println("\n:--------:");
System.out.println("|Correct.|");//Display correct System.out.println(":--------:");
ScoreCounter++;//Iterates score count +1 }//Ends if else//default condition, if answer is correct/invalid. {//starts else System.out.println("\n:----------:");
System.out.println("|Incorrect.|");//displays in correct System.out.println(":----------:");
}//ends else
//Question 2 //Reference commenting to question 1. System.out.println("\nQuestion 2.");
System.out.println("What is Mario's original name ? : ");
System.out.println("a. Marioman ");
System.out.println("b. BarrelJumper");
System.out.println("c. Jumper");
System.out.println("d. Jumpman\n");
InputAnswer = scan.nextLine();
//Question 3 //Reference commenting to question 1. System.out.println("\nQuestion 3.");
System.out.println("Who is Mario named after ? : ");
System.out.println("a. Mario Luigi");
System.out.println("b. Mario Sir Jumper");
System.out.println("c. Mario Arakawa");
System.out.println("d. Mario Segali\n");
InputAnswer = scan.nextLine();
//Question 5 //Reference commenting to question 1. System.out.println("\nQuestion 5.");
System.out.println("In the Super Mario series Are Lakitus' good guys ? : ");
System.out.println("a. Sometimes");
System.out.println("b. Yes");
System.out.println("c. No");
System.out.println("d. Lakitus' don't exist.\n");
InputAnswer = scan.nextLine();
//Question 12 //Reference commenting to question 1. System.out.println("\nQuestion 12.");
System.out.println("What is the Princess's full name ? : ");
System.out.println("a. Peach Apricot");
System.out.println("b. Lady Peach");
System.out.println("c. Peach Toadstool");
System.out.println("d. Lady Toadstool\n");
InputAnswer = scan.nextLine();
//Question 14 //Reference commenting to question 1. System.out.println("\nQuestion 14.");
System.out.println("How many enemy types are there in Super Mario Bros. ? : ");
System.out.println("a. 23");
System.out.println("b. 19");
System.out.println("c. 18");
System.out.println("d. 15\n");
InputAnswer = scan.nextLine();
//Question 15 //Reference commenting to question 1. System.out.println("\nQuestion 15.");
System.out.println("Who does the voice of Mario presently ? : ");
System.out.println("a. Mark Graue");
System.out.println("b. Mario Segial");
System.out.println("c. Ronald B. Ruben");
System.out.println("d. Charles Martinet\n");
InputAnswer = scan.nextLine();
//Score Comments. if(ScoreCounter == 15)//The condition to check if the user scored perfect. {//Starts if System.out.println("\n\nExcellent, you got perfect " + Username);//Displays username; Saying they got perfect System.out.println("You answered:"+ ScoreCounter +" out of 15 correct.");//Displays amount of correctanswers out of total System.out.println("Your Score is:"+(ScoreCounter*100)/15+"%");//Converts score to % System.out.println("Would you like to play the game again " + Username + " ? (y/n): ");//Asks the user to play again
GameLoop = scan.nextLine();//Stores user data; Checked at the bottom. }//Ends If.
elseif(ScoreCounter > 7 && ScoreCounter < 11)//Condition to check if score is greater than 7, lesss than 11 {//Starts else if System.out.println("\n\nNot bad, you're average");//Displays comment depending on score. System.out.println("You answered:"+ ScoreCounter +" out of 15 correct");//Displays amount of correctanswers out of total System.out.println("Your Score is: "+(ScoreCounter*100)/15+"%");//Converts score to % System.out.println("Would you like to play the game again " + Username + " ? (y/n): ");//Asks the user to play again
GameLoop = scan.nextLine();//Stores user data; Checked at the bottom. }//Ends else if
elseif(ScoreCounter > 11 && ScoreCounter < 15)//Condition to check if score is greater than 11, lesss than 15 {//Starts else if System.out.println("\n\nGood job, you did pretty well.");//Displays comment depending on score. System.out.println("You answered:"+ ScoreCounter +" out of 15 correct");//Displays amount of correctanswers out of total System.out.println("Your Score is: "+(ScoreCounter*100)/15+"%");//Converts score to % System.out.println("Would you like to play the game again " + Username + " ? (y/n): ");//Asks the user to play again
GameLoop = scan.nextLine();//Stores user data; Checked at the bottom. }//Ends else if
else//Default condition, showing that score is a fail less than 7. {//Starts Else System.out.println("\n\nFailure, Please leave town..");//Displays comment depending on score. System.out.println("You answered:"+ ScoreCounter +" out of 15 correct");//Displays amount of correctanswers out of total System.out.println("Your Score is: "+(ScoreCounter*100)/15+"%");//Converts score to % System.out.println("Would you like to play the game again " + Username + " ? (y/n): ");//Asks the user to play again
GameLoop = scan.nextLine();//Stores user data; Checked at the bottom. }//Ends else
if(GameLoop.equalsIgnoreCase("n"))break;//Checks the userinput, from the Score comments, if input is n/N, program is forced to jump put of the loop ending it. //Not the best way to end a game/program, but should work fine for a small code like this.
ScoreCounter = 0;//Resets to score.
}//ends gameloop
System.out.println("\nThank you for playing, Good-bye!");//Display goodbye comment.
}//ends program
}//ends class
Sponsor Sponsor
syntax_error
Posted: Tue Dec 02, 2008 9:36 pm Post subject: RE:Grade 11 Mid-Term ISU
Using break is a horrible habit to get into, try not to, simple check if the condition of the original loop is meet or not in this case if Gameloop is n set it to false why have a while loop in the being if you don't use it?
btw, no one really likes the whole idea of fake loading screens; the latter is my $0.02; the former however, should be fixed.
andrew.
Posted: Tue Dec 02, 2008 9:47 pm Post subject: RE:Grade 11 Mid-Term ISU
It's cool, but it's pretty procedural and isn't the whole point of Java in grade 11 to learn object-oriented concepts?
syntax_error
Posted: Tue Dec 02, 2008 9:50 pm Post subject: Re: RE:Grade 11 Mid-Term ISU
andrew. @ Tue Dec 02, 2008 9:47 pm wrote:
It's cool, but it's pretty procedural and isn't the whole point of Java in grade 11 to learn object-oriented concepts?
I doubt they are even taught what an object is. Yet. Hopefully.
andrew.
Posted: Tue Dec 02, 2008 9:51 pm Post subject: RE:Grade 11 Mid-Term ISU
It's halfway through the course so they should know what an object is. It's fairly important in Java and it took me a while to wrap my head around the concept.
NegativeAzn
Posted: Tue Dec 02, 2008 10:56 pm Post subject: Re: RE:Grade 11 Mid-Term ISU
syntax_error @ Tue Dec 02, 2008 9:36 pm wrote:
Using break is a horrible habit to get into, try not to, simple check if the condition of the original loop is meet or not in this case if Gameloop is n set it to false why have a while loop in the being if you don't use it?
btw, no one really likes the whole idea of fake loading screens; the latter is my $0.02; the former however, should be fixed.
I guess I should delete the whole false-load thing.
I don't really understand what you're trying to say, yes I already know break is a really bad thing to use, since the whole AT&T network disaster.
I tried doing a simple check if condition, but i'm not sure , this is what I tried, But can't really figure to work it.
At the end, it doesn't loop, anyone mind suggesting what to do?
code:
while (GameLoop.equals("n") && !GameLoop.equals("y")); < replace while(true)
>quiz crap here <
>Ending@Score comments.Question : would you like to quit?
if(quit.equals("y"))
{
System.out.println("Thanks for playing, Good-bye.");
}
else
{
System.out.println("Restarting..");
ScoreCounter = 0;//Resets to score.
wtd
Posted: Wed Dec 03, 2008 12:32 am Post subject: RE:Grade 11 Mid-Term ISU
The following kind of comment would cost you points in wtd's classroom.
code:
//ends class
Okapi
Posted: Wed Dec 03, 2008 4:24 am Post subject: Re: RE:Grade 11 Mid-Term ISU
wtd @ Wed 03 Dec, 05:32 wrote:
The following kind of comment would cost you points in wtd's classroom.
code:
//ends class
Why?
Sponsor Sponsor
wtd
Posted: Wed Dec 03, 2008 12:02 pm Post subject: RE:Grade 11 Mid-Term ISU
Comments are meant to shed light on the reasoning behind a piece of code above and beyond the information the code itself provides.
That type of comment does not do so. It is just extra visual clutter and makes the code harder to read for no benefit.
S_Grimm
Posted: Wed Dec 03, 2008 12:32 pm Post subject: Re: RE:Grade 11 Mid-Term ISU
wtd @ Wed Dec 03, 2008 12:02 pm wrote:
Comments are meant to shed light on the reasoning behind a piece of code above and beyond the information the code itself provides.
That type of comment does not do so. It is just extra visual clutter and makes the code harder to read for no benefit.
How is it visual clutter? I use this type of comment to easily identify where the block of code starts and ends and where the classes end. When my code is 1000+ lines of code, I need to be able to see my procedures.
wtd
Posted: Thu Dec 04, 2008 12:25 am Post subject: RE:Grade 11 Mid-Term ISU
It's extra.... stuff to look at. And it doesn't say anything useful that the code itself shouldn't already be telling you.
syntax_error
Posted: Thu Dec 04, 2008 1:05 am Post subject: Re: RE:Grade 11 Mid-Term ISU
NegativeAzn @ Tue Dec 02, 2008 10:56 pm wrote:
syntax_error @ Tue Dec 02, 2008 9:36 pm wrote:
Using break is a horrible habit to get into, try not to, simple check if the condition of the original loop is meet or not in this case if Gameloop is n set it to false why have a while loop in the being if you don't use it?
btw, no one really likes the whole idea of fake loading screens; the latter is my $0.02; the former however, should be fixed.
I guess I should delete the whole false-load thing.
I don't really understand what you're trying to say, yes I already know break is a really bad thing to use, since the whole AT&T network disaster.
I tried doing a simple check if condition, but i'm not sure , this is what I tried, But can't really figure to work it.
At the end, it doesn't loop, anyone mind suggesting what to do?
code:
while (GameLoop.equals("n") && !GameLoop.equals("y")); < replace while(true)
>quiz crap here <
>Ending@Score comments.Question : would you like to quit?
if(quit.equals("y"))
{
System.out.println("Thanks for playing, Good-bye.");
}
else
{
System.out.println("Restarting..");
ScoreCounter = 0;//Resets to score.
play with the true condition of the while loop. You should get it now.
rto
Posted: Thu Dec 04, 2008 10:09 am Post subject: Re: Grade 11 Mid-Term ISU
I've been working with java for about a year and (correct me if i'm wrong please wtd, AV or somebody else who knows), but I would suggest putting the correct / Incorrect statements into their own methods to clean up a couple of lines of text
again, i could be wrong so i would suggest waiting on another post to tell you whether this is a good idea or not azn
S_Grimm
Posted: Thu Dec 04, 2008 11:35 am Post subject: RE:Grade 11 Mid-Term ISU
putting the questions in there own procedures is helpful, but checking if the answer is right is just a couple of if statements and boolean variables.
HeavenAgain
Posted: Thu Dec 04, 2008 3:46 pm Post subject: Re: Grade 11 Mid-Term ISU
rto @ Thu Dec 04, 2008 11:09 am wrote:
I've been working with java for about a year and (correct me if i'm wrong please wtd, AV or somebody else who knows), but I would suggest putting the correct / Incorrect statements into their own methods to clean up a couple of lines of text
again, i could be wrong so i would suggest waiting on another post to tell you whether this is a good idea or not azn
A general rule in programming is when you need to copy/paste codes, then you are doing something wrong...