Você está na página 1de 6

import java.util.

Random;
import java.util.Scanner;
public class QuizMaker {
public static void main(String[] args) {
//Scanner scnr = new Scanner(System.in);
// Declare a Scanner attached to System.in. This should be the
only
//Scanner created in the entire program.
int a = 3;
if(a<0){
System.out.println("Number of questions cannot be
Negative.");
}
int b = 1;
int c = 10;
String d = "+";
String f = "-";
String g = "*";
String h = "/";
int e = 25;
double j = 8.0;
//int z = 100;
int s = 0;
int questions = 0;
//String x ="6";
// Declare constants and variables that will be used throughout
// your program
int r = 7;
int q = 7;
int fine = 4;
int menu = 0;
System.out.println ("Welcome to the Quiz Maker 3000!");
//Welcome Message
while (true){
Scanner scnr = new Scanner(System.in);
e = 0;
while (e == 0) {
// MAIN PROGRAM LOOP
System.out.println("Quiz Settings:");
System.out.println("Number of questions: "+a);
System.out.println("Min Operand: "+b);
System.out.println("Max Operand: "+c);
System.out.println("Operator: "+d);
System.out.println(" ");
// PRINT QUIZ SETTINGS

System.out.println("Main Menu");
System.out.println("1) Set Number of Questions");
System.out.println("2) Set Minimum Operand Value");
System.out.println("3) Set Maximum Operand Value");
System.out.println("4) Set Operator");
System.out.println("5) Take Quiz");
System.out.println("6) Quit");
System.out.println("What would you like to do?");
//DISPLAY MENU
//e = scnr.nextInt();

//System.out.println("Enter a length for the quiz.");


if (scnr.hasNextInt() ) {
//prompt
int cc = scnr.nextInt();
if(cc>0 && cc<7)
e = cc;
else
System.out.println("Error: Invalid command.");
}
else{
System.out.println("Error: Invalid command.");
scnr.next();
}
}
//
//
negative value.");
//

if (e<0){
System.out.println("Cannot enter a
}

if(e == 1) {
a = 0;
while (a == 0) {
System.out.println("Enter a length for the quiz.");
if (scnr.hasNextInt() ) {
int bb = scnr.nextInt();
if(bb>0)
a = bb;
else
System.out.println("Number of questions

must be a positive integer.");


}
else{
System.out.println("Number of questions must
be a positive integer.");
scnr.next();
}
}
}
// Number of Questions
if(e == 2) {
b = 0;
while (b == 0) {
System.out.println("Enter a value for the minimum
possible operand.");
if (scnr.hasNextInt() ) {
int dd = scnr.nextInt();
if(dd<c)
b = dd;
else
System.out.println("Error: Minimum
operand must be strictly less than the maximum operand.");
}
else{
System.out.println("Error: Minimum operand
must be an integer.");
scnr.next();
}
}
}
//
//Minimum operand value
if(e == 3) {
c = 0;
while (c == 0) {
System.out.println("Enter a value for the maximum
possible operand.");
if (scnr.hasNextInt() ) {
int ee = scnr.nextInt();
if(ee>b)
c = ee;
else
System.out.println("The maximum operand

must be strictly greater than the minimum operand.");


}
else{
System.out.println("Error: Maximum operand
must be an integer.");
scnr.next();
}
}
}
//Maximum operand value

if(e == 4) {
while (fine == 4) {
System.out.println("Select an operator: (+,-,*,/,
%)");
d = scnr.next();
if(d.charAt(0)=='+') {
//
System.out.println("has been changed to
+");
fine=6;
}
else if(d.charAt(0)=='-') {
//
System.out.println("has been changed to
-");
fine=6;
}
else if(d.charAt(0)=='*') {
//
System.out.println("has been changed to
*");
fine=6;
}
else if(d.charAt(0)=='/') {
//System.out.println("has been changed to /");
fine=6;
}
else if(d.charAt(0)=='%') {
//
System.out.println("has been changed to
%");
fine=6;
}
else {
fine=4;
System.out.println("Error: Invalid operator
choice.");
}

}
}
//Operator
questions = 0;
s=0;
while (questions < a){
questions = questions +1;
if(e == 5) {
r = (int) (Math.random() * c) +b;
q = (int) (Math.random() * c) +b;
if (q ==0) {
while(q == 0) {
q = (int) (Math.random() * c) +b;
}
}

//questions++;
//question loop
System.out.println("What is " +r + d + +q +"?" );
//Prompt the user with the problem
j = scnr.nextDouble();
//Process their response
if (d.charAt(0) == '+') {
if (j== (r+q)) {
System.out.println("Correct!");
System.out.println(" ");
s++;
}
else {
System.out.println("Incorrect.");
System.out.println(" ");
}
}
if (d.charAt(0)== '-') {
if (j== (r-q)) {
System.out.println("Correct!");
System.out.println(" ");
s++;
}
else {
System.out.println("Incorrect.");
System.out.println(" ");
}
}
if (d.charAt(0)== '*') {
if (j==(r*q)) {

System.out.println("Correct!");
System.out.println(" ");
s++;
}
else {
System.out.println("Incorrect.");
System.out.println(" ");
}
}
if (d.charAt(0)== '/') {
if (j==((double)r/q)) {
System.out.println("Correct!");
System.out.println(" ");
s++;
}
//if (r == 0) {
//}
else {
System.out.println("Incorrect.");
System.out.println(" ");
}
}
if (d.charAt(0)=='%'){
if (j==(r%q)) {
System.out.println("Correct!");
s++;
}
else{
System.out.println("Incorrect.");
}
}
}
if(e == 6) {
// USER CHOSE TO QUIT PROGRAM
System.out.println("Goodbye!");
//PRINT END MESSAGE
System.exit(0);
}
}
if(e==5) {
System.out.println("Quiz complete! Your score: " +s +"
out of " + a +".");

}
}
}
}

Você também pode gostar