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 3 of 3

Thread: how to add questions inside the switch statement and then calculate results in java

  1. #1
    Junior Member
    Join Date
    Nov 2021
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to add questions inside the switch statement and then calculate results in java

    In a company an employee has to complete trainings 1- List a menu displaying available trainings - This is Working 2- lets say if the employee selects Training-1 then -display something about the training - This is Working -ask employee if he would like to take quiz associated with the training - Not working -if yes populate question, if no then main menu. Also this should be an infinite loop. - Not working 3- present 2 questions each training 4- After quiz completion ask user to input name and calculate their marks in the end with his name.

    I have written this program in parts but I am not been able to make it in one single program.

    To Display Training lessons I have written following:
    class Training {
    public static void main (String[] args)

    throws java.io.IOException { // this is necessary to handle input errors
    char choice;
    do {
    System.out.println("Chapters Index");
    System.out.println(" 1. Training-1 Change Management");
    System.out.println(" 2. Training-2 The ITIL");
    System.out.println(" 3. Training-3 Problem Management");
    System.out.println("Choose one:");
    choice = (char) System.in.read(); // Reads the character from the keyboard to obtain user's choice
    } while( choice < '1' || choice > '3');
    System.out.println("\n");
    switch(choice) {
    case '1':
    System.out.println(" Training 1 Change Management:\n is a part of ITIL\n");
    System.out.println("Plan, rollback changes with your cloud-based ITIL helpdesk solution");
    System.out.println("and let relevant members evaluate and approve changes.");
    break;
    case '2':
    System.out.println("Training 2 The ITIL:\n");
    System.out.println(" ITIL is a set of detailed practices for IT activities");
    System.out.println(" such as IT service management and IT asset management");
    System.out.println(" The full form of ITIL is:");
    System.out.println(" IT infrastructure Library");
    break;
    case '3':
    System.out.println("Training-3 Problem Management:\n");
    System.out.print("Isolate problems, link it to existing or past incidents,");
    System.out.println(" perform root cause analysis the timeline of events of your SaaS based ITIL helpdesk tool, and minimize disruptions to the business.");
    break;
    }
    }
    }



    Program-2 - But the following is not working
    import java.util.Scanner;

    public class Demo2 {
    String prompt;
    String answer;

    public Demo2 (String prompt, String answer) {
    this.prompt = prompt;
    this.answer = answer;

    }
    }
    class Demo2 {
    public static void main (String[] args) {
    String q1 = "What is the full form of ITIL?\n" + "(a)IT infrastructure Library\n(b)Infrastructure\n(c)Library\n";
    String q2 = "What change management is a part of?\n" + "(a)Stack Overflow\n(b)ITIL\n(c)Demo\n";

    Demo2[] questions = {
    new Question(q1,"a"),
    new Question(q2,"b");
    };
    takeTest(questions);
    }
    public static void takeTest(App [] questions) {
    int score = 0;
    Scanner keyboardInput = new Scanner(System.in);
    for(int i =0; i<question.length; i++) {
    System.out.println(questions[i].prompt);
    String answer = keyboardInput.nextLine();
    if (answer.equals(questions[i].answer)) {
    score++;
    }
    }
    System.out.println("You got " + score +"/" + questions.length);
    }
    }

  2. #2
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    268
    My Mood
    Amused
    Thanks
    8
    Thanked 18 Times in 18 Posts

    Default Re: how to add questions inside the switch statement and then calculate results in java

    Have you fixed?
    Whatever you are, be a good one

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: how to add questions inside the switch statement and then calculate results in java

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. How to Use the Java switch statement
    By JavaPF in forum Java Programming Tutorials
    Replies: 6
    Last Post: April 18th, 2013, 05:19 PM
  2. Switch statement using a String with Java 1.7
    By eloel33 in forum Java Theory & Questions
    Replies: 2
    Last Post: November 23rd, 2012, 05:11 AM
  3. Switch statement inside a for loop need help.
    By TheWhopper858 in forum Loops & Control Statements
    Replies: 1
    Last Post: November 12th, 2011, 11:50 PM
  4. Java Program Help Switch Statement
    By jwill22 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 11th, 2010, 12:31 AM
  5. How to Use the Java switch statement
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 5
    Last Post: October 8th, 2009, 09:00 PM