1. Welcome to TRD Forums! A community for Toyota, Lexus, and Scion Enthusiasts. To enjoy all the benefits of the site, we invite you to signup.

Tech Any good java programmers out there?

Discussion in 'Off Topic' started by Silver_Nitrate, Jul 11, 2005.

  1. Offline

    Silver_Nitrate New Member

    Message Count:
    765
    Likes Received:
    0
    Trophy Points:
    0
    Any good java programmers out there?

    I need some help with my homework, my professor is such a dusch when it comes to helping us with the homework. I've sent him an e-mail since last thusrday and I have not heared from his ass. Anyways here's the intructions.

    7.10 Use the Question class from Chapter 6 to define a Quiz class. A quiz can be composed of up to 25 questions. Define the add method of the Quiz class to add a question to a quiz. Define the giveQuiz method of the Quiz class to present each question in tuurn to the user, accept an answer for each one, and keep track of the results. Define a class called QuizTime with a main method that populates a quiz, presents it and prints the final results.

    7.11 Modify your answer to Programming Project 7.10 so that the complexity level of the questions given in the quiz is taken into account. Overload the giveQuiz method so that it accepts two integer parameters that specify the minimum and maximum complexity levels for the quiz questions and only presents questions in that complexity range. Modify the main method to demonstrate this feature.

    Here's the Quiz class from chapter 6

    import java.util.Scanner;
    public class Question implements Complexity

    {

    private String question, answer;
    private int complexityLevel;

    public Question (String query, String result)
    {
    question = query;
    answer = result;
    complexityLevel = 1;
    }

    public void setComplexity (int level)
    {
    complexityLevel = level;
    }

    public int getComplexity()
    {
    return complexityLevel;
    }

    public String getQuestion()
    {
    return question;
    }

    public String getAnswer()
    {
    return answer;
    }

    public boolean answerCorrect (String candidateAnswer)
    {
    return answer.equals(candidateAnswer);
    }

    public String toString()
    {
    return question + "\n" + answer;
    }

    }

    thanks for the help
  2. Offline

    Cuztomrollaz98 MAD VLAD!

    Message Count:
    6,665
    Likes Received:
    0
    Trophy Points:
    38
    Location:
    Littleton, CO.
  3. Offline

    Silver_Nitrate New Member

    Message Count:
    765
    Likes Received:
    0
    Trophy Points:
    0
    bump anybody? let's make this interesting, there will be a reward for it. here is the rest of the working codes, just once section needs to be modified (which I don't know how to) to make it perform as specified. The one italized is the one that needs to be modified.
    ========================================================
    public interface Complexity

    {

    public void setComplexity (int complexity);
    public int getComplexity();

    }
    =========================================================

    import java.util.Scanner;
    public class Question implements Complexity

    {

    private String question, answer;
    private int complexityLevel;

    public Question (String query, String result)
    {
    question = query;
    answer = result;
    complexityLevel = 1;
    }

    public void setComplexity (int level)
    {

    complexityLevel = level;
    }

    public int getComplexity()
    {
    return complexityLevel;
    }

    public String getQuestion()
    {
    return question;
    }

    public String getAnswer()
    {
    return answer;
    }

    public boolean answerCorrect (String candidateAnswer)
    {
    return answer.equals(candidateAnswer);
    }

    public String toString()
    {
    return question + "\n" + answer;
    }

    }

    ================================================================

    import java.util.Scanner;
    public class Quiz

    {
    private int score;
    private Question[] questionHolder = new Question[25];
    private int numQuestions;
    private int complexity;


    public Quiz()
    {
    this.score = 0;
    this.numQuestions = 0;
    this.complexity = 0;
    }

    public void addQuestion (Question Q)
    {
    this.questionHolder[numQuestions++] = Q;
    }





    public int giveQuiz()

    {

    Scanner scan = new Scanner (System.in);


    String candidateAnswer;

    System.out.println ("Enter complexity level from 1-5:");
    scan.nextInt();
    scan.nextLine();


    for (int i = 0; i < numQuestions; i++)
    {

    System.out.println(questionHolder.getQuestion());
    candidateAnswer = scan.nextLine();

    if (questionHolder.answerCorrect(candidateAnswer))

    score++;
    }
    return getscore();
    }



    public int getscore()
    {
    return score;
    }

    public String toString()
    {
    return getscore()+ "";
    }


    }

    ==============================================================

    public class QuizTime

    {
    public static void main (String[] args)

    {
    //--------------------------------------------------------------------------
    //Initializes the variables.
    //--------------------------------------------------------------------------
    Question Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10, Q11, Q12, Q13, Q14, Q15, Q16, Q17, Q18, Q19,
    Q20, Q21, Q22, Q23, Q24, Q25;

    Quiz T1;

    //--------------------------------------------------------------------------
    //Creates the question and answer and also sets its complexity value.
    //--------------------------------------------------------------------------
    Q1 = new Question ("What is the capital of Virginia?", "Richmond");
    Q1.setComplexity (1);
    Q2 = new Question ("What is the capital of North Carolina?", "Raleigh");
    Q2.setComplexity (2);
    Q3 = new Question ("What is the capital of West Virginia?", "Charleston");
    Q3.setComplexity (3);
    Q4 = new Question ("What is the capital of Tenessee?", "Nashville");
    Q4.setComplexity (4);
    Q5 = new Question ("What is the capital of North Dakota?", "Bismarck");
    Q5.setComplexity (5);
    Q6 = new Question ("What is the capital of Arizona?", "Phoenix");
    Q6.setComplexity (1);
    Q7 = new Question ("What is the capital of California?", "Sacramento");
    Q7.setComplexity (2);
    Q8 = new Question ("What is the capital of Alabama?", "Montgomery");
    Q8.setComplexity (3);
    Q9 = new Question ("What is the capital of Rhode Island?", "Providence");
    Q9.setComplexity (4);
    Q10 = new Question ("What is the capital of Oregon?", "Salem");
    Q10.setComplexity (5);
    Q11 = new Question ("What is the capital of Texas?", "Austin");
    Q11.setComplexity (1);
    Q12 = new Question ("What is the capital of Oklahoma?", "Oklahoma City");
    Q12.setComplexity (2);
    Q13 = new Question ("What is the capital of Ohio?", "Columbus");
    Q13.setComplexity (3);
    Q14 = new Question ("What is the capital of Kentucky?", "Frankfort");
    Q14.setComplexity (4);
    Q15 = new Question ("What is the capital of Missouri?", "Jefferson City");
    Q15.setComplexity (5);
    Q16 = new Question ("What is the capital of Denver?", "Colorado");
    Q16.setComplexity (1);
    Q17 = new Question ("What is the capital of Utah?", "Salt Lake");
    Q17.setComplexity (2);
    Q18 = new Question ("What is the capital of Idaho?", "Boise");
    Q18.setComplexity (3);
    Q19 = new Question ("What is the capital of Louisiana?", "Baton Rouge");
    Q19.setComplexity (4);
    Q20 = new Question ("What is the capital of San Diego?", "Pierre");
    Q20.setComplexity (5);
    Q21 = new Question ("What is the capital of Maryland?", "Annapolis");
    Q21.setComplexity (1);
    Q22 = new Question ("What is the capital of Connecticut?", "Hartford");
    Q22.setComplexity (2);
    Q23 = new Question ("What is the capital of New Hampshire?", "Concord");
    Q23.setComplexity (3);
    Q24 = new Question ("What is the capital of Alaska?", "Juneau");
    Q24.setComplexity (4);
    Q25 = new Question ("What is the capital of Hawaii?", "Honolulu");
    Q25.setComplexity (5);

    //--------------------------------------------------------------
    //Adds the questions into quiz.
    //--------------------------------------------------------------
    T1= new Quiz();
    T1.addQuestion(Q1);
    T1.addQuestion(Q2);
    T1.addQuestion(Q3);
    T1.addQuestion(Q4);
    T1.addQuestion(Q5);
    T1.addQuestion(Q6);
    T1.addQuestion(Q7);
    T1.addQuestion(Q8);
    T1.addQuestion(Q9);
    T1.addQuestion(Q10);
    T1.addQuestion(Q11);
    T1.addQuestion(Q12);
    T1.addQuestion(Q13);
    T1.addQuestion(Q14);
    T1.addQuestion(Q15);
    T1.addQuestion(Q16);
    T1.addQuestion(Q17);
    T1.addQuestion(Q18);
    T1.addQuestion(Q19);
    T1.addQuestion(Q20);
    T1.addQuestion(Q21);
    T1.addQuestion(Q22);
    T1.addQuestion(Q23);
    T1.addQuestion(Q24);
    T1.addQuestion(Q25);

    //--------------------------------------------------------------
    //Prints out the quizes.
    //--------------------------------------------------------------
    System.out.print(T1.giveQuiz());


    }
    }
  4. Offline

    Toxinate New Member

    Message Count:
    74
    Likes Received:
    0
    Trophy Points:
    0
    public int giveQuiz(int lowComplex, int highComplex)

    {

    Scanner scan = new Scanner (System.in);


    String candidateAnswer;

    //System.out.println ("Enter complexity level from 1-5:");
    //scan.nextInt();
    //scan.nextLine();


    for (int i = 0; i < numQuestions; i++)
    {

    if questionHolder.getComplexity >= lowComplex & questionHolder.getComplexity <= highComplex
    {
    System.out.println(questionHolder.getQuestion());
    candidateAnswer = scan.nextLine();
    }

    if (questionHolder.answerCorrect(candidateAnswer))

    score++;
    }
    return getscore();
    }

    Just add this method/function under the regular giveQuiz method... This is an example of overloading. Simply changing the parameters the class accepts. If you want to make it even more interesting. Add a counter to how many questions it actually asks. Instantiate a new public variable named totalQuestions so at the end, the score will be in the format:
    getScore() + "/" + totalQuestions

    What's my prize? (Nothing like incentive to get things moving)
  5. Offline

    Silver_Nitrate New Member

    Message Count:
    765
    Likes Received:
    0
    Trophy Points:
    0
    have you tried to compile this? I tried to get it to work on my program, but it will not compile. Oh the prize is 20 bucks to be exact.
  6. Offline

    Toxinate New Member

    Message Count:
    74
    Likes Received:
    0
    Trophy Points:
    0
    What is the error msg? As I don't have a java compiler on this machine.
  7. Offline

    Silver_Nitrate New Member

    Message Count:
    765
    Likes Received:
    0
    Trophy Points:
    0
    I:meh:Java\Quiz1\Quiz.java:43: cannot find symbol
    symbol : variable getComplexity
    location: class Question
    if (questionHolder.getComplexity >= lowComplex && questionHolder.getComplexity <= highComplex)
    ^
    I:meh:Java\Quiz1\Quiz.java:43: cannot find symbol
    symbol : variable getComplexity
    location: class Question
    if (questionHolder.getComplexity >= lowComplex && questionHolder.getComplexity <= highComplex)
    ^
    2 errors

    Tool completed with exit code 1
  8. Offline

    Toxinate New Member

    Message Count:
    74
    Likes Received:
    0
    Trophy Points:
    0
    Nothing like leaving a couple simple symbols out. Heh:

    public int giveQuiz(int lowComplex, int highComplex)

    {

    Scanner scan = new Scanner (System.in);


    String candidateAnswer;

    //System.out.println ("Enter complexity level from 1-5:");
    //scan.nextInt();
    //scan.nextLine();


    for (int i = 0; i < numQuestions; i++)
    {

    if (questionHolder.getComplexity() >= lowComplex && questionHolder.getComplexity() <= highComplex)
    {
    System.out.println(questionHolder.getQuestion());
    candidateAnswer = scan.nextLine();
    }

    if (questionHolder.answerCorrect(candidateAnswer))

    score++;
    }
    return getscore();
    }

    //Replace questionHolder.getComplexity with questionHolder.getComplexity()
  9. Offline

    Silver_Nitrate New Member

    Message Count:
    765
    Likes Received:
    0
    Trophy Points:
    0
    man I thought you had it, but now it pose another problem. It compiled just fine but the error now is due to public int giveQuiz(int lowComplex, int highComplex)

    here's the new error
    I:meh:Java\Quiz1\QuizTime.java:102: giveQuiz(int,int) in Quiz cannot be applied to ()
    System.out.print(T1.giveQuiz());
    ^
    1 error

    Tool completed with exit code 1

    oh yeah another thing, I played with it and deleted the int on the public int giveQuiz, instead I initialized it on the very top:

    private int score;
    private Question[] questionHolder = new Question[25];
    private int numQuestions;
    private int Complexity;
    private int lowComplex, highComplex;

    now everything compiled, but when you run the program, it asks you for the complexity level you want but it does not display any questions.
  10. Offline

    Toxinate New Member

    Message Count:
    74
    Likes Received:
    0
    Trophy Points:
    0
    Replace T1.giveQuiz() with T1.giveQuiz(1, 3)

    This will display questions between complexities 1 and 3.

    Change the 1 and 3 numbers with any number between 1 and 5...
    Just make sure the first number is smaller than the second.

    Leave the int on the giveQuiz... that returns your score to the print line method.
  11. Offline

    Silver_Nitrate New Member

    Message Count:
    765
    Likes Received:
    0
    Trophy Points:
    0
    ok now I understand what you did, but the instructions asked that let's say, you wanted complexity 3, it will display all the question that have the complexity 3 and not 1-3. Is there a way to change that to make it respond only to the entered complexity?

    Here is the program as it is:

    import java.util.Scanner;
    public class Quiz

    {
    private int score;
    private Question[] questionHolder = new Question[25];
    private int numQuestions;



    public Quiz()
    {
    this.score = 0;
    this.numQuestions = 0;

    }

    public void addQuestion (Question Q)
    {
    this.questionHolder[numQuestions++] = Q;
    }

    public int giveQuiz(int lowComplex, int highComplex)

    {

    Scanner scan = new Scanner (System.in);

    String candidateAnswer;

    System.out.println ("Enter complexity level from 1-5:");
    scan.nextInt();
    scan.nextLine();


    for (int i = 0; i < numQuestions; i++)
    {
    if (questionHolder.getComplexity() >= lowComplex && questionHolder.getComplexity() <= highComplex)
    System.out.println(questionHolder.getQuestion());
    candidateAnswer = scan.nextLine();
    if (questionHolder.answerCorrect(candidateAnswer))
    score++;
    }
    return getscore();
    }
    public int getscore()
    {
    return score;
    }
    public String toString()
    {
    return getscore() + "\n";
    }

    }
  12. Offline

    Toxinate New Member

    Message Count:
    74
    Likes Received:
    0
    Trophy Points:
    0
    where is your

    public int giveQuiz()
    {
    ...
    }

    method defined?

    Show that to me and I will show you what to change...

    --------

    What I would do.

    Define a new method named startQuiz:

    public startQuiz()
    {
    private int answer;
    private int complexity;
    private int lowComplexity, highComplexity;

    System.out.println("Would you like 1 complexity level or multiple complexity levels? (1: 1 Level | 2: Multiple Levels) ");
    answer = scan.nextInt();
    System.out.println();

    if answer = 1
    {
    System.out.println("Enter Complexity Level (1-5:( ");
    complexity = scan.nextInt();
    System.out.println();

    System.out.println(giveQuiz(complexity, complexity));

    } else {

    System.out.println("Enter Min Complexity Level (1-5:( ");
    lowComplexity = scan.nextInt();
    System.out.println("Enter Max Complexity level (" + lowComplexity + "-5:( ");
    highComplexity = scan.nextInt();
    system.out.println();

    system.out.println(giveQuiz(lowComplexity, highComplexity));
    }

    instead of the giveQuiz(...) method in the main execution block, place just a single startQuiz() method
  13. Offline

    Silver_Nitrate New Member

    Message Count:
    765
    Likes Received:
    0
    Trophy Points:
    0
    I'm not sure what you are asking. the giveQuiz method that I have was the one you changed to public int giveQuiz(int lowComplex, int highComplex) then the rest as you saw in my previous post.

    Here is the direction I have to follow:

    7.11 Modify your answer to Programming Project 7.10 so that the complexity level of the questions given in the quiz is taken into account. Overload the giveQuiz method so that it accepts two integer parameters that specify the minimum and maximum complexity levels for the quiz questions and only presents questions in that complexity range. Modify the main method to demonstrate this feature.
  14. Offline

    Toxinate New Member

    Message Count:
    74
    Likes Received:
    0
    Trophy Points:
    0
    leave the original giveQuiz() method.

    The point of overloading is having the same method just with different parameter you can to it.

    Follow my previous post and that should do what you want of it.

    you got AIM? IM me at Toxinate

Share This Page