Arrays

Arrays

Create a program to mark and grade a set of multiple choice test results.This is a console programm that uses JOptionPane dialog boxes as well.

Read a set of 10 correct answers,using a JOptionPane dialog box and store the entire answer as one string in one variable.There are no spaces between the letters and the user may enter capital or small letters.

Extract each letter from this and fill an array with the 10 letter answers.This is done in a method Load Answers after above .When the answers have been written to the array,display the confirmation box displaying The information has been saved.

The programm must then ask the user for the number of students to process .

Thereafter the program must prompt the user for the student name and thereafter for the student's 10 answers.Use Input Dialog boxes to achieve this.The 10 answers for the student must be saved in another array.

Please ensure the wording of your dialog boxes are shown

After successful capture of the marks ,show another success confirmation dialog box .Thereafter compare the student's answers with the answers in an array.Keep count of the number of answers in the answer array.Keep a count of the number of answers from the student's record that match the answers in the answer key.

Store the student's name and the number of correct answers in another array(s). Calculate the symbol based on the results below

Score Letter Grade

9-10 A 8 B 7 C 6 D 5 E 0-4 F

For each student ,display the student's name ,the number of correct answers and a symbol(letter grade).Calculate the average number of correct answers for the class and report it in the format similar to the one below

Jean 10 A Above Average

Jack 7 C Above Average

George 9 A Above Average

Paul 5 E Below Average

Steven 7 C Above Average

Jackie 6 D Below Average

lucky 0 F Below Average

lan 8 B Above Average

Matr 8 B Above Average

And 9 A Above Average

The class average is :

Using the array of student records ,display a list for all students.Report if a student had an average, above average or below average number of correct answers as shown above

To end the program display a dialog box asking the user for confirmation of exit :

View Answers

May 26, 2011 at 3:05 PM

import java.util.*;
import javax.swing.*;

class Student {

    String name;
    int total;

    Student(String name, int total) {
        this.name = name;
        this.total = total;
    }

    public String getName() {
        return name;
    }

    public int getTotal() {
        return total;
    }
}

public class StudentTest {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<Student>();
        String finalResult = "";
        String finalSymbol = "";
        String st = JOptionPane
                .showInputDialog("Please enter the answers to the ten multiple choice questions \nno spaces and all in Capital letters e.g. ABCDEABCDE");
        String answers[] = st.split("");
        int count = 0;
        int numOfStudents = Integer.parseInt(JOptionPane
                .showInputDialog("Please enter the number of students :"));
        String studentanswers[] = new String[10];
        for (int j = 1; j <= numOfStudents; j++) {
            String name = JOptionPane
                    .showInputDialog("Please enter the student name:");
            for (int i = 0; i < 10; i++) {
                String ans = JOptionPane.showInputDialog("Please enter " + name
                        + "'s answer for Question " + (i + 1));
                studentanswers[i] = ans;
            }
            for (int i = 0; i < studentanswers.length; i++) {
                if (studentanswers[i].equals(answers[i + 1])) {
                    count++;
                }
            }
            list.add(new Student(name, count));
            count = 0;
        }
        int sum = 0;
        for (Student s : list) {
            int tt = s.getTotal();
            if (tt == 0 || tt == 1 || tt == 2 || tt == 3 || tt == 4) {
                finalSymbol = "F";
            } else if (tt == 5) {
                finalSymbol = "E";
            } else if (tt == 6) {
                finalSymbol = "D";
            } else if (tt == 7) {
                finalSymbol = "C";
            } else if (tt == 8) {
                finalSymbol = "B";
            } else if (tt == 9 || tt == 10) {
                finalSymbol = "A";
            }
            if (tt >= 5) {
                finalResult = "Above Average";
            } else if (tt < 5) {
                finalResult = "Below Average";
            }
            sum += tt;
            System.out.println(s.getName() + "\t" + tt + "\t" + finalSymbol
                    + "\t" + finalResult);
        }
        double averageOfClass = sum / numOfStudents;
        System.out.println("The class average is: " + averageOfClass);
    }
}









Related Tutorials/Questions & Answers:
arrays
arrays  using arrays in methods   Java use arrays in methods import java.util.*; class ArrayExample{ public static int getMaxValue(int[] arr){ int maxValue = arr[0]; for(int i=1;i < arr.length;i
arrays
Store a table with students and information (name, ID, password, crypted password, etc) in a multi-dimensional array "stud"  Arrays and Strings: Store a table with students and information (name, ID, password, crypted password
Advertisements
Arrays
Arrays   Hi I need help with the following exercises. Exercise 1: Write a Java application in which the user is prompted for the total number of integer values to be stored in an array. Initialize the array with random values
Arrays
called Rebel.java; 2.Create two arrays. One of them must store integer numbers... the numbers in the second array by 3; 7.Print out the contents of both arrays. 8.Swap
Arrays in java
Arrays in java  what is param array in java
java arrays
java arrays  can i know how can we intilize the three dimentional arrays in java? and how can we assign thae values to that array
java arrays
java arrays  i need a java program to store student details like id,name,addr,marks,average,total..using arrays..input data using scanner class and by using class, object and constructor
Java with Arrays
Java with Arrays  I was given the assignment to create two parallel arrays; both of size 50 (declares 50 as a constant) One is an array of strings... and store it in the arrays. The input for the problem should be provided in a text
arrays
Arrays
Arrays
arrays
arrays
Arrays
arrays
arrays
arrays
Arrays
arrays
arrays
arrays
Comparing arrays not working correctly?
Comparing arrays not working correctly?  Comparing arrays not working correctly
create arrays in JavaScript
create arrays in JavaScript  How to create arrays in JavaScript
How to create arrays in JavaScript?
How to create arrays in JavaScript?  How to create arrays in JavaScript
Compare two Byte Arrays?
Compare two Byte Arrays?  Compare two Byte Arrays
java arrays
java arrays  how do you write the code for multipliying 2 double arrays to be in a 3rd double array? here is my code: package employeepay; /** * * @author Owner */ public class Main {ADS_TO_REPLACE_1 /** * @param args
ModuleNotFoundError: No module named 'Arrays'
ModuleNotFoundError: No module named 'Arrays'  Hi, My Python... 'Arrays' How to remove the ModuleNotFoundError: No module named 'Arrays'... to install padas library. You can install Arrays python with following command
arrays in java - Java Beginners
arrays in java  Hi All, I have two arrays. in this two array some name are same. I want to merge those arrays into single. But while merging I want to delete duplicate entries. How merge those arrays. Thanks, mln15584
java; arrays - Java Beginners
java arrays example  How can you create a program, by using arrays and the output would be X. by using char or string.Thank you
What is javascript Arrays?
What is javascript Arrays?   Hi, I am learner of JavaScript. My question is that What is JavaScript Arrays ? How to Define the JavaScript arrays in you program. Please give an example show that i will try my self. Thanks
Are arrays primitive data types?
Are arrays primitive data types?   Hi, Are arrays primitive data types? thanks   Hi, In Java, Arrays are objects. Identifier are some simple variable names which is defined as the value container. The type of value
combine two arrays in php
combine two arrays in php  combine two arrays in php   $newArray = array_combine($diff, $pages_name['data']); foreach ($newArray as $data) { var_dump($data); exit('zzzzz'); echo $data . '<br>
Arrays in java 7
This tutorial describes the concept of Arrays in java 7
swap two integer arrays
swap two integer arrays  int [] array1 = {1,2,3,4,5} int [] array2 = {6,7,8,9,10} how can we swap the values of bith integer arrays results like this array1 = {6,7,8,9,10} array2 = {1,2,3,4,5
swap two integer arrays
swap two integer arrays  int [] array1 = {1,2,3,4,5} int [] array2 = {6,7,8,9,10} how can we swap the values of bith integer arrays results like this array1 = {6,7,8,9,10} array2 = {1,2,3,4,5
reverse arrays in java
reverse arrays in java  how do i make a code that can be used to reverse the elements of an array in two dimension such that the last element of an array becomes the first element of the array and the first element of an array
reverse arrays in java
reverse arrays in java  how do i write a program in array of size n*m where both n and m are greater than 20 such that the 1st element of an array becomes the last and vice verse
swap two integer arrays
swap two integer arrays  int [] array1 = {1,2,3,4,5} int [] array2 = {6,7,8,9,10} how can we swap the values of bith integer arrays results like this array1 = {6,7,8,9,10} array2 = {1,2,3,4,5
How to concatenate two arrays in Java?
How to concatenate two arrays in Java?  How to concatenate two arrays in Java
intersection of two java arrays
intersection of two java arrays  I am trying to figure out how to compare two arrays and get the intersection and put this into a third array of the correct size. I know how to copy the two arrays into the third array but am
Java Arrays Tutorials
The java.util.Arrays class helps the programmers to manipulating the arrays. It provides the methods to easily manipulate the arrays. Methods provided...(). Browse the following code to Learn Java Arrays in detail
Arrays in java
Arrays in java Arrays are the data structure of java , we use array where we need contiguous memory allocation. Array stores same type of data structure. Array type is checked at compile time. An array has a fixed length. Declaration
Variable length arrays?
Variable length arrays?  Hi: I enjoy reading from your site especially the example seem to speak louder than the description. Thanks for your... of arrays or if there is a smart way to handle this. Thanks for your help. Varma
Arrays - Java Interview Questions
a program that take arrays A & B as input and find missing element in B array
Introduction to java arrays
Introduction to java arrays   ... of Arrays in Java Programming language. You will learn how the Array class... arrays. To meet this feature java has provided an Array class which abstracts
ModuleNotFoundError: No module named 'match-arrays'
ModuleNotFoundError: No module named 'match-arrays'  Hi, My Python... 'match-arrays' How to remove the ModuleNotFoundError: No module named 'match-arrays' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'stats-arrays'
ModuleNotFoundError: No module named 'stats-arrays'  Hi, My Python... 'stats-arrays' How to remove the ModuleNotFoundError: No module named 'stats-arrays' error? Thanks   Hi, In your python
Printing 2 arrays
Printing 2 arrays  Hi, I have 2 arrays: String [] head = {"Name", "Date of birth", "PPS number"}; String [] personal= {value1, value2, value3}; I want this 2 arrays to be printed out in the following manner: head[0] tab
Comparing Arrays
Comparing Arrays : Java Util       This section show you how to determine the given arrays are same or not. The given program illustrates you how to compare arrays according
Associative Arrays
Associative Arrays In this section, you will learn about associative arrays and it 's implementation. In an associative array, a key is associated with a value. We can use values as key and assign value to them. Given below

Ads