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);
}
}