0% found this document useful (0 votes)
14 views15 pages

Uti

The document contains a Java class named 'Uti' that implements a simple quiz system with multiple-choice and fill-in-the-blank questions. It tracks the user's score and total possible score, providing feedback on answers and calculating a grade based on performance. The class includes methods for creating questions, accepting user input, and displaying results.

Uploaded by

godadhu1212
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views15 pages

Uti

The document contains a Java class named 'Uti' that implements a simple quiz system with multiple-choice and fill-in-the-blank questions. It tracks the user's score and total possible score, providing feedback on answers and calculating a grade based on performance. The class includes methods for creating questions, accepting user input, and displaying results.

Uploaded by

godadhu1212
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import [Link].

Scanner;

public class Uti {


Scanner in = new Scanner([Link]); //initiate scanner

//initiate score and total


public double score = 0;
public double total = 0;

public void create_mcq(String name, String op1, String op2, String


op3, String op4, int CO) {
total += 1; //increase total by marks awarded for the question

//print
[Link]("Q: "+name + ": \n");
[Link]("Option 1: " + op1);
[Link]("Option 2: " + op2);
[Link]("Option 3: " + op3);
[Link]("Option 4: " + op4+"\n");

//accept
[Link]("Enter choice(number only): ");
int choice = [Link]();

//checking
if (choice == CO){
[Link]("Correct!");
score+=1;
}
else{
[Link]("Wrong answer, (correct: "+CO+") (u might
have also entered choice out of valid range.)");
}

public void create_fib(String q, String ans){


total += 2; //add marks awarded to score

//print and accept


[Link]("Q: "+q);
[Link]("Enter answer: ");
String ua = [Link]();
//ignore case is good for most questions
//planning to create new function which is case-sensitive
if ([Link](ua)){
[Link]("Correct!!");
score += 2;
}
else{
[Link]("Wrong!!");
score -= 0.5;
}
}

//just a failsafe for no particular reason


public void setScore(double score) {
[Link] = score;
}

//useful in future or in other functions like grade()


public double getScore() {
return score;
}

//display score and grade


public void print_score(){
[Link](score+"\n");
[Link](grade());
}
//determine grade
// if full marks then A, if between total and total/2 ; B
//below
public String grade(){
double marks = getScore();
return ((marks ==total)? "Grade: A" : (marks < total && marks
>total/2.0) ? "Grade: B": "Grade: C" );
}
} import [Link];

public class Uti {


Scanner in = new Scanner([Link]); //initiate scanner

//initiate score and total


public double score = 0;
public double total = 0;

public void create_mcq(String name, String op1, String op2, String


op3, String op4, int CO) {
total += 1; //increase total by marks awarded for the question

//print
[Link]("Q: "+name + ": \n");
[Link]("Option 1: " + op1);
[Link]("Option 2: " + op2);
[Link]("Option 3: " + op3);
[Link]("Option 4: " + op4+"\n");

//accept
[Link]("Enter choice(number only): ");
int choice = [Link]();

//checking
if (choice == CO){
[Link]("Correct!");
score+=1;
}
else{
[Link]("Wrong answer, (correct: "+CO+") (u might
have also entered choice out of valid range.)");
}

public void create_fib(String q, String ans){


total += 2; //add marks awarded to score
//print and accept
[Link]("Q: "+q);
[Link]("Enter answer: ");
String ua = [Link]();
//ignore case is good for most questions
//planning to create new function which is case-sensitive
if ([Link](ua)){
[Link]("Correct!!");
score += 2;
}
else{
[Link]("Wrong!!");
score -= 0.5;
}
}

//just a failsafe for no particular reason


public void setScore(double score) {
[Link] = score;
}

//useful in future or in other functions like grade()


public double getScore() {
return score;
}

//display score and grade


public void print_score(){
[Link](score+"\n");
[Link](grade());
}
//determine grade
// if full marks then A, if between total and total/2 ; B
//below
public String grade(){
double marks = getScore();
return ((marks ==total)? "Grade: A" : (marks < total && marks
>total/2.0) ? "Grade: B": "Grade: C" );
}
}
import [Link];

public class Uti {


Scanner in = new Scanner([Link]); //initiate scanner

//initiate score and total


public double score = 0;
public double total = 0;

public void create_mcq(String name, String op1, String op2, String


op3, String op4, int CO) {
total += 1; //increase total by marks awarded for the question

//print
[Link]("Q: "+name + ": \n");
[Link]("Option 1: " + op1);
[Link]("Option 2: " + op2);
[Link]("Option 3: " + op3);
[Link]("Option 4: " + op4+"\n");

//accept
[Link]("Enter choice(number only): ");
int choice = [Link]();

//checking
if (choice == CO){
[Link]("Correct!");
score+=1;
}
else{
[Link]("Wrong answer, (correct: "+CO+") (u might
have also entered choice out of valid range.)");
}

public void create_fib(String q, String ans){


total += 2; //add marks awarded to score

//print and accept


[Link]("Q: "+q);
[Link]("Enter answer: ");
String ua = [Link]();
//ignore case is good for most questions
//planning to create new function which is case-sensitive
if ([Link](ua)){
[Link]("Correct!!");
score += 2;
}
else{
[Link]("Wrong!!");
score -= 0.5;
}
}

//just a failsafe for no particular reason


public void setScore(double score) {
[Link] = score;
}

//useful in future or in other functions like grade()


public double getScore() {
return score;
}

//display score and grade


public void print_score(){
[Link](score+"\n");
[Link](grade());
}
//determine grade
// if full marks then A, if between total and total/2 ; B
//below
public String grade(){
double marks = getScore();
return ((marks ==total)? "Grade: A" : (marks < total && marks
>total/2.0) ? "Grade: B": "Grade: C" );
}
}
import [Link];

public class Uti {


Scanner in = new Scanner([Link]); //initiate scanner

//initiate score and total


public double score = 0;
public double total = 0;

public void create_mcq(String name, String op1, String op2, String


op3, String op4, int CO) {
total += 1; //increase total by marks awarded for the question

//print
[Link]("Q: "+name + ": \n");
[Link]("Option 1: " + op1);
[Link]("Option 2: " + op2);
[Link]("Option 3: " + op3);
[Link]("Option 4: " + op4+"\n");

//accept
[Link]("Enter choice(number only): ");
int choice = [Link]();

//checking
if (choice == CO){
[Link]("Correct!");
score+=1;
}
else{
[Link]("Wrong answer, (correct: "+CO+") (u might
have also entered choice out of valid range.)");
}

public void create_fib(String q, String ans){


total += 2; //add marks awarded to score

//print and accept


[Link]("Q: "+q);
[Link]("Enter answer: ");
String ua = [Link]();
//ignore case is good for most questions
//planning to create new function which is case-sensitive
if ([Link](ua)){
[Link]("Correct!!");
score += 2;
}
else{
[Link]("Wrong!!");
score -= 0.5;
}
}
//just a failsafe for no particular reason
public void setScore(double score) {
[Link] = score;
}

//useful in future or in other functions like grade()


public double getScore() {
return score;
}

//display score and grade


public void print_score(){
[Link](score+"\n");
[Link](grade());
}
//determine grade
// if full marks then A, if between total and total/2 ; B
//below
public String grade(){
double marks = getScore();
return ((marks ==total)? "Grade: A" : (marks < total && marks
>total/2.0) ? "Grade: B": "Grade: C" );
}
}
import [Link];

public class Uti {


Scanner in = new Scanner([Link]); //initiate scanner

//initiate score and total


public double score = 0;
public double total = 0;

public void create_mcq(String name, String op1, String op2, String


op3, String op4, int CO) {
total += 1; //increase total by marks awarded for the question

//print
[Link]("Q: "+name + ": \n");
[Link]("Option 1: " + op1);
[Link]("Option 2: " + op2);
[Link]("Option 3: " + op3);
[Link]("Option 4: " + op4+"\n");

//accept
[Link]("Enter choice(number only): ");
int choice = [Link]();

//checking
if (choice == CO){
[Link]("Correct!");
score+=1;
}
else{
[Link]("Wrong answer, (correct: "+CO+") (u might
have also entered choice out of valid range.)");
}
}

public void create_fib(String q, String ans){


total += 2; //add marks awarded to score

//print and accept


[Link]("Q: "+q);
[Link]("Enter answer: ");
String ua = [Link]();
//ignore case is good for most questions
//planning to create new function which is case-sensitive
if ([Link](ua)){
[Link]("Correct!!");
score += 2;
}
else{
[Link]("Wrong!!");
score -= 0.5;
}
}

//just a failsafe for no particular reason


public void setScore(double score) {
[Link] = score;
}

//useful in future or in other functions like grade()


public double getScore() {
return score;
}

//display score and grade


public void print_score(){
[Link](score+"\n");
[Link](grade());
}
//determine grade
// if full marks then A, if between total and total/2 ; B
//below
public String grade(){
double marks = getScore();
return ((marks ==total)? "Grade: A" : (marks < total && marks
>total/2.0) ? "Grade: B": "Grade: C" );
}
}
import [Link];

public class Uti {


Scanner in = new Scanner([Link]); //initiate scanner

//initiate score and total


public double score = 0;
public double total = 0;

public void create_mcq(String name, String op1, String op2, String


op3, String op4, int CO) {
total += 1; //increase total by marks awarded for the question
//print
[Link]("Q: "+name + ": \n");
[Link]("Option 1: " + op1);
[Link]("Option 2: " + op2);
[Link]("Option 3: " + op3);
[Link]("Option 4: " + op4+"\n");

//accept
[Link]("Enter choice(number only): ");
int choice = [Link]();

//checking
if (choice == CO){
[Link]("Correct!");
score+=1;
}
else{
[Link]("Wrong answer, (correct: "+CO+") (u might
have also entered choice out of valid range.)");
}

public void create_fib(String q, String ans){


total += 2; //add marks awarded to score

//print and accept


[Link]("Q: "+q);
[Link]("Enter answer: ");
String ua = [Link]();
//ignore case is good for most questions
//planning to create new function which is case-sensitive
if ([Link](ua)){
[Link]("Correct!!");
score += 2;
}
else{
[Link]("Wrong!!");
score -= 0.5;
}
}

//just a failsafe for no particular reason


public void setScore(double score) {
[Link] = score;
}

//useful in future or in other functions like grade()


public double getScore() {
return score;
}

//display score and grade


public void print_score(){
[Link](score+"\n");
[Link](grade());
}
//determine grade
// if full marks then A, if between total and total/2 ; B
//below
public String grade(){
double marks = getScore();
return ((marks ==total)? "Grade: A" : (marks < total && marks
>total/2.0) ? "Grade: B": "Grade: C" );
}
}
import [Link];

public class Uti {


Scanner in = new Scanner([Link]); //initiate scanner

//initiate score and total


public double score = 0;
public double total = 0;

public void create_mcq(String name, String op1, String op2, String


op3, String op4, int CO) {
total += 1; //increase total by marks awarded for the question

//print
[Link]("Q: "+name + ": \n");
[Link]("Option 1: " + op1);
[Link]("Option 2: " + op2);
[Link]("Option 3: " + op3);
[Link]("Option 4: " + op4+"\n");

//accept
[Link]("Enter choice(number only): ");
int choice = [Link]();

//checking
if (choice == CO){
[Link]("Correct!");
score+=1;
}
else{
[Link]("Wrong answer, (correct: "+CO+") (u might
have also entered choice out of valid range.)");
}

public void create_fib(String q, String ans){


total += 2; //add marks awarded to score

//print and accept


[Link]("Q: "+q);
[Link]("Enter answer: ");
String ua = [Link]();
//ignore case is good for most questions
//planning to create new function which is case-sensitive
if ([Link](ua)){
[Link]("Correct!!");
score += 2;
}
else{
[Link]("Wrong!!");
score -= 0.5;
}
}

//just a failsafe for no particular reason


public void setScore(double score) {
[Link] = score;
}

//useful in future or in other functions like grade()


public double getScore() {
return score;
}

//display score and grade


public void print_score(){
[Link](score+"\n");
[Link](grade());
}
//determine grade
// if full marks then A, if between total and total/2 ; B
//below
public String grade(){
double marks = getScore();
return ((marks ==total)? "Grade: A" : (marks < total && marks
>total/2.0) ? "Grade: B": "Grade: C" );
}
}
import [Link];

public class Uti {


Scanner in = new Scanner([Link]); //initiate scanner

//initiate score and total


public double score = 0;
public double total = 0;

public void create_mcq(String name, String op1, String op2, String


op3, String op4, int CO) {
total += 1; //increase total by marks awarded for the question

//print
[Link]("Q: "+name + ": \n");
[Link]("Option 1: " + op1);
[Link]("Option 2: " + op2);
[Link]("Option 3: " + op3);
[Link]("Option 4: " + op4+"\n");

//accept
[Link]("Enter choice(number only): ");
int choice = [Link]();

//checking
if (choice == CO){
[Link]("Correct!");
score+=1;
}
else{
[Link]("Wrong answer, (correct: "+CO+") (u might
have also entered choice out of valid range.)");
}

public void create_fib(String q, String ans){


total += 2; //add marks awarded to score

//print and accept


[Link]("Q: "+q);
[Link]("Enter answer: ");
String ua = [Link]();
//ignore case is good for most questions
//planning to create new function which is case-sensitive
if ([Link](ua)){
[Link]("Correct!!");
score += 2;
}
else{
[Link]("Wrong!!");
score -= 0.5;
}
}

//just a failsafe for no particular reason


public void setScore(double score) {
[Link] = score;
}

//useful in future or in other functions like grade()


public double getScore() {
return score;
}

//display score and grade


public void print_score(){
[Link](score+"\n");
[Link](grade());
}
//determine grade
// if full marks then A, if between total and total/2 ; B
//below
public String grade(){
double marks = getScore();
return ((marks ==total)? "Grade: A" : (marks < total && marks
>total/2.0) ? "Grade: B": "Grade: C" );
}
}
import [Link];

public class Uti {


Scanner in = new Scanner([Link]); //initiate scanner

//initiate score and total


public double score = 0;
public double total = 0;

public void create_mcq(String name, String op1, String op2, String


op3, String op4, int CO) {
total += 1; //increase total by marks awarded for the question

//print
[Link]("Q: "+name + ": \n");
[Link]("Option 1: " + op1);
[Link]("Option 2: " + op2);
[Link]("Option 3: " + op3);
[Link]("Option 4: " + op4+"\n");

//accept
[Link]("Enter choice(number only): ");
int choice = [Link]();

//checking
if (choice == CO){
[Link]("Correct!");
score+=1;
}
else{
[Link]("Wrong answer, (correct: "+CO+") (u might
have also entered choice out of valid range.)");
}

public void create_fib(String q, String ans){


total += 2; //add marks awarded to score

//print and accept


[Link]("Q: "+q);
[Link]("Enter answer: ");
String ua = [Link]();
//ignore case is good for most questions
//planning to create new function which is case-sensitive
if ([Link](ua)){
[Link]("Correct!!");
score += 2;
}
else{
[Link]("Wrong!!");
score -= 0.5;
}
}

//just a failsafe for no particular reason


public void setScore(double score) {
[Link] = score;
}

//useful in future or in other functions like grade()


public double getScore() {
return score;
}
//display score and grade
public void print_score(){
[Link](score+"\n");
[Link](grade());
}
//determine grade
// if full marks then A, if between total and total/2 ; B
//below
public String grade(){
double marks = getScore();
return ((marks ==total)? "Grade: A" : (marks < total && marks
>total/2.0) ? "Grade: B": "Grade: C" );
}
}
import [Link];

public class Uti {


Scanner in = new Scanner([Link]); //initiate scanner

//initiate score and total


public double score = 0;
public double total = 0;

public void create_mcq(String name, String op1, String op2, String


op3, String op4, int CO) {
total += 1; //increase total by marks awarded for the question

//print
[Link]("Q: "+name + ": \n");
[Link]("Option 1: " + op1);
[Link]("Option 2: " + op2);
[Link]("Option 3: " + op3);
[Link]("Option 4: " + op4+"\n");

//accept
[Link]("Enter choice(number only): ");
int choice = [Link]();

//checking
if (choice == CO){
[Link]("Correct!");
score+=1;
}
else{
[Link]("Wrong answer, (correct: "+CO+") (u might
have also entered choice out of valid range.)");
}

public void create_fib(String q, String ans){


total += 2; //add marks awarded to score

//print and accept


[Link]("Q: "+q);
[Link]("Enter answer: ");
String ua = [Link]();
//ignore case is good for most questions
//planning to create new function which is case-sensitive
if ([Link](ua)){
[Link]("Correct!!");
score += 2;
}
else{
[Link]("Wrong!!");
score -= 0.5;
}
}

//just a failsafe for no particular reason


public void setScore(double score) {
[Link] = score;
}

//useful in future or in other functions like grade()


public double getScore() {
return score;
}

//display score and grade


public void print_score(){
[Link](score+"\n");
[Link](grade());
}
//determine grade
// if full marks then A, if between total and total/2 ; B
//below
public String grade(){
double marks = getScore();
return ((marks ==total)? "Grade: A" : (marks < total && marks
>total/2.0) ? "Grade: B": "Grade: C" );
}
}
import [Link];

public class Uti {


Scanner in = new Scanner([Link]); //initiate scanner

//initiate score and total


public double score = 0;
public double total = 0;

public void create_mcq(String name, String op1, String op2, String


op3, String op4, int CO) {
total += 1; //increase total by marks awarded for the question

//print
[Link]("Q: "+name + ": \n");
[Link]("Option 1: " + op1);
[Link]("Option 2: " + op2);
[Link]("Option 3: " + op3);
[Link]("Option 4: " + op4+"\n");

//accept
[Link]("Enter choice(number only): ");
int choice = [Link]();
//checking
if (choice == CO){
[Link]("Correct!");
score+=1;
}
else{
[Link]("Wrong answer, (correct: "+CO+") (u might
have also entered choice out of valid range.)");
}

public void create_fib(String q, String ans){


total += 2; //add marks awarded to score

//print and accept


[Link]("Q: "+q);
[Link]("Enter answer: ");
String ua = [Link]();
//ignore case is good for most questions
//planning to create new function which is case-sensitive
if ([Link](ua)){
[Link]("Correct!!");
score += 2;
}
else{
[Link]("Wrong!!");
score -= 0.5;
}
}

//just a failsafe for no particular reason


public void setScore(double score) {
[Link] = score;
}

//useful in future or in other functions like grade()


public double getScore() {
return score;
}

//display score and grade


public void print_score(){
[Link](score+"\n");
[Link](grade());
}
//determine grade
// if full marks then A, if between total and total/2 ; B
//below
public String grade(){
double marks = getScore();
return ((marks ==total)? "Grade: A" : (marks < total && marks
>total/2.0) ? "Grade: B": "Grade: C" );
}
}

You might also like