Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 12 of 12

Thread: Father of CompSci HS student needs help

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Father of CompSci HS student needs help

    My first post. Trying to help my daughter with her AP CompSci course in HS. She has some labs to do and I have been doing them as well but I am stumped on one for three days now. She may be able to do it when she gets to it but I want to be able to do it to, plus if she runs into issues I can point her in the right direction. I don't want to be spoon feed or give her the answer she needs to think about it. I have done about 6 labs now. The one I am stumped on is creating a multiple choice test with 10 questions. I have searched for examples but the solutions all seem outside of the teacher provided notes for this chapter. I need a solution that works for a beginner with 3 weeks instruction.

    Here is what I have:

     
    import java.util.Scanner;
    public class multiChoiceTest
    {
    	public static void main(String[] args)
    	{
    		Scanner keyboard=new Scanner(System.in);
    		System.out.print("---Multiple Choice Test. CHEATERS WILL GET AN 'F'---\n\n");
    		System.out.print("---Choose the best answer---\n\n");
    		System.out.print("1.) What is the state capitol of California?\n\n");
    		System.out.print("A. San Diego\n");
    		System.out.print("B. San Francisco\n");
    		System.out.print("C. Sacramento\n");
    		System.out.print("D. Vista\n");
    		System.out.print("E. Oceanside\n\n");
    		System.out.print ("Enter your selection: ");
    	//I think the next line should be a "string" instead of "int" so I can accept a "C" input from the user.  The correct line below is what I am struggling with.  So I can match it to an if statement
    		int question1=keyboard.nextByte();	
     
    			if(question1==C)   //been having issues getting an if statement to match the question1 input.  Don't think I care if they got the wrong answer.
     
    		{
    		int q1points=10;
    		}
    	//then I will figure out how to make it go to the next question.  Assume next question goes under closing brace of the if statement.
    	//at the end I will add up the points and provide a grade result.  I got that part covered.  Previous labs
    	}
    }


    My challenge in finding help is I have only been given the teachers notes and examples in the forum here and on the net are to complicated for where we are at. So I assume the labs must be related to what was taught. I completed the other labs this way. So I was hoping someone could spot what is wrong and point me in the right direction based on his notes.

    Unit 3 notes include basic int and double labs
    Unit 4 Notes included:

    Comparison operators
    Comparing Objects
    Conjunction Operators (&& ||)
    De Morgans Law
    Yoda Notation
    Selection Statements (if and else if)
    Nesting Selection Statements
    and Random numbers

    Any help appreciated. Thank you in advance.

    --- Update ---

    More specific question. How would you store the users response (hopefully a single character and capitalized) and then match it on an if statement. Do I use a string, char, int, something else? I might be able to figure out the if statement if I know I was storing the input from the user correctly. I did a lab like this one but it was matching numbers not letters. If I store the input as a char or string then I have issues matching it on the if statement.


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: Father of CompSci HS student needs help

    I'd use a String for the input and use equalsIgnoreCase() to check the answer. You are using C which is an undeclared variable.
    Basically it works like this:
    System.out.print ("Enter your selection: ");
    String answer1=keyboard.nextLine();
    int points = 0;
    if(answer1.equalsIgnoreCase("C")){
        points = points +10;
    }
    By using a String you accept any type of user input and don't have to worry about exceptions, i.e. you use nextInt() and user types 'A'.

    You haven't mentioned Arrays in the list of notes. Normally you'd use a loop and execute the same code 10 times. You'd need one array for 10 questions, another array for the 10 correct answers and another array for the 50 possible answers (which could also be a 2 dimensional array [10][5]).

    Hope this helps.

  3. The Following User Says Thank You to PhHein For This Useful Post:

    sco78840 (September 24th, 2014)

  4. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Father of CompSci HS student needs help

    Without arrays and loops, the solution to this problem is very tedious. Hopefully, it's purpose is to impress upon the students how much better their lives will be once those tools are available.

  5. #4
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: Father of CompSci HS student needs help

    Just noticed, don't
    System.out.print("A. San Diego\n");
    but
    System.out.println("A. San Diego");
    System.out.println(); //   <------------- empty line aka line feed

  6. The Following User Says Thank You to PhHein For This Useful Post:

    sco78840 (September 24th, 2014)

  7. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Father of CompSci HS student needs help

    This probably isn't the advice you're looking for, but the best thing I can tell you to do is to *let her do her own work*. You said you aren't spoonfeeding her solutions or anything, but it does seem like you might be offering hints that you find from your own research.

    Doing that research is part of learning programming. It's a HUGE part of programming. By doing the googling for her, sifting through the results, and boiling it down to some helpful hints, you're taking away a huge part of the assignment from her: breaking a problem down into smaller steps, then figuring out how to do each small step one at a time. You do this by googling, reading tutorials, the API, etc. So *she* needs to be the one doing the googling, NOT YOU.

    If she isn't comfortable googling or reading through the tutorials, then next time she asks you a question, why don't you say "how about we figure it out together" and you show her the types of searches you're doing, the types of sites you're visiting. Show her how to make a forum post, if for some reason she can't figure it out. She should be the one posting here.

    Think about it this way: if she goes to college for computer science (or anything, really), should she really still be relying on you to do her googling for her?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #6
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Father of CompSci HS student needs help

    Quote Originally Posted by PhHein View Post
    I'd use a String for the input and use equalsIgnoreCase() to check the answer. You are using C which is an undeclared variable.
    Basically it works like this:
    System.out.print ("Enter your selection: ");
    String answer1=keyboard.nextLine();
    int points = 0;
    if(answer1.equalsIgnoreCase("C")){
        points = points +10;
    }
    By using a String you accept any type of user input and don't have to worry about exceptions, i.e. you use nextInt() and user types 'A'.

    You haven't mentioned Arrays in the list of notes. Normally you'd use a loop and execute the same code 10 times. You'd need one array for 10 questions, another array for the 10 correct answers and another array for the 50 possible answers (which could also be a 2 dimensional array [10][5]).

    Hope this helps.
    Sorry for the late reply, but I owe you a thank you and everyone else that replied. Your suggestion worked and now I can move on. I appreciate it.

    --- Update ---

    Quote Originally Posted by KevinWorkman View Post
    This probably isn't the advice you're looking for, but the best thing I can tell you to do is to *let her do her own work*. You said you aren't spoonfeeding her solutions or anything, but it does seem like you might be offering hints that you find from your own research.

    Doing that research is part of learning programming. It's a HUGE part of programming. By doing the googling for her, sifting through the results, and boiling it down to some helpful hints, you're taking away a huge part of the assignment from her: breaking a problem down into smaller steps, then figuring out how to do each small step one at a time. You do this by googling, reading tutorials, the API, etc. So *she* needs to be the one doing the googling, NOT YOU.

    If she isn't comfortable googling or reading through the tutorials, then next time she asks you a question, why don't you say "how about we figure it out together" and you show her the types of searches you're doing, the types of sites you're visiting. Show her how to make a forum post, if for some reason she can't figure it out. She should be the one posting here.

    Think about it this way: if she goes to college for computer science (or anything, really), should she really still be relying on you to do her googling for her?
    I understand Kevin and thank you for the concern you make a valid point. She asked for a little help the first week and during that time I got hooked and decided I wanted to try the labs to. I do not have the work load she does so this past week I was able to pull a few labs ahead. But in all honesty she is a smart kid and hasn't needed my help at all on this weeks 7 labs. She has 5 complete and not one question yet. I have just done a QA for her as some have not worked correctly and were not ready to turn in but all I have done was to tell her the assignment was not done correctly. I joined the forum because she is getting instruction in class. All I get is her notes and the book.

    Long story short I'm having fun, shes doing her own thing and I enjoy comparing the differences in code. Here was her last one:

    import java.util.Scanner;
    public class leapyearkallee
    {
    	public static void main(String[] args)
    	{
    		Scanner keyboard=new Scanner(System.in);
    		System.out.print("Enter a year:");
    		int year=keyboard.nextInt();
     
    		if(year%400==0)
    		{
    			System.out.printf("%d is a leap year.",year);
    		}
     
    		else if(year%100==0)
    		{
    			System.out.printf("%d is not a leap year.",year);
    		}
     
    		else if(year%4==0)
    		{
    			System.out.printf("%d is a leap year.",year);
    		}
     
    		else if(year%4!=0)
    		{
    			System.out.printf("%d is not a leap year.",year);
    		}
    	}
    }


    and then my code which is a little different.

    import java.util.Scanner;
    public class leapyear
    {
    	public static void main(String[] args)
    	{
    		Scanner keyboard=new Scanner (System.in);
    		System.out.println("---Leap Year Program---\n");
    		System.out.print("Enter a year in the format of yyyy: ");
    		int year=keyboard.nextInt();
     
    			if(year%4==0 && year%100==0 && year%400==0)
    		{
    			System.out.printf("The year %d is a leap year",year);	
    		}
     
    			else if(year%4==0 && year%100==0 && year%400!=0)
    		{
    			System.out.printf("The year %d is NOT a leap year",year);	
    		}	
     
    				else if(year%4==0)
    		{
    			System.out.printf("The year %d is a leap year",year);	
    		}
     
    					else if(year%4!=0)
    		{
    			System.out.printf("The year %d is NOT a leap year",year);
    		}		
    	}
    }



    I certainly am going to need more help here on the forums from time to time and don't want to get on anyone's list as a cheat. Hopefully I convinced you a little that she is doing this on her own but she has me as a source if needed to guide her in finding her mistakes. Thanks again.

  9. #7
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: Father of CompSci HS student needs help

    No problems. And even if you were doing her assignments, she's likely to fail sooner or later. Anyway, have fun coding and feel free to ask questions.

  10. #8
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Father of CompSci HS student needs help

    . . . she's likely to fail sooner or later.
    Our resident optimist.

  11. #9
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: Father of CompSci HS student needs help

    Quote Originally Posted by GregBrannon View Post
    Our resident optimist.

  12. #10
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Father of CompSci HS student needs help

    Quote Originally Posted by sco78840 View Post
    I understand Kevin and thank you for the concern you make a valid point. She asked for a little help the first week and during that time I got hooked and decided I wanted to try the labs to. I do not have the work load she does so this past week I was able to pull a few labs ahead. But in all honesty she is a smart kid and hasn't needed my help at all on this weeks 7 labs. She has 5 complete and not one question yet. I have just done a QA for her as some have not worked correctly and were not ready to turn in but all I have done was to tell her the assignment was not done correctly. I joined the forum because she is getting instruction in class. All I get is her notes and the book.

    Long story short I'm having fun, shes doing her own thing and I enjoy comparing the differences in code.

    I certainly am going to need more help here on the forums from time to time and don't want to get on anyone's list as a cheat. Hopefully I convinced you a little that she is doing this on her own but she has me as a source if needed to guide her in finding her mistakes. Thanks again.
    That's awesome. Keep up the good work. One of the neat things about programming is that there are about a thousand different ways to do one thing, so no two people code exactly the same.

    My only concern was that she might ask something like "how do arrays work" and you would go off and do the research for her, when what you should tell her is "what did your googling tell you?" and try to steer her by asking her questions instead of providing answers. But it sounds like you're mostly doing this for yourself, which is great, and I don't blame you for. Welcome to programming!

    --- Update ---

    Quote Originally Posted by GregBrannon View Post
    Our resident optimist.
    Hahaha what I think Phil meant was that she'll fail *if* the OP is doing her homework for her, not that she'll fail no matter what...?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  13. #11
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Father of CompSci HS student needs help

    Lab completed 281 lines. 10 multiple choice questions, tells you if you got the correct answer after each question and if you didn't what the correct answer is. Then at the end gives you your total points scored and assigns a letter grade. (Pats self on back) Thanks again for the assistance.

  14. #12
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: Father of CompSci HS student needs help

    Quote Originally Posted by KevinWorkman View Post
    Hahaha what I think Phil meant was that she'll fail *if* the OP is doing her homework for her, not that she'll fail no matter what...?
    Ayup. That's correct.

Similar Threads

  1. New student
    By sevenday in forum Member Introductions
    Replies: 2
    Last Post: June 5th, 2013, 07:12 PM
  2. Replies: 1
    Last Post: May 31st, 2013, 06:21 AM
  3. Student Grading
    By happychild in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 14th, 2011, 12:09 PM
  4. Student.java
    By ruffu054 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 12th, 2011, 02:40 PM
  5. student CGPA
    By adamu adamu in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 8th, 2011, 06:52 AM