Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your assignment is to write and submit two java files. One is a class definition

ID: 3567521 • Letter: Y

Question

Your assignment is to write and submit two java files. One is a class definition named Quiz
(Quiz.java), and another is the test driver program, Assignment7.java.
1) The Quiz is a class to keep the scores of quiz for students, and it has the three instance
variables: scores, count, and name.
Quiz
- scores : int[]
- count : int
- String : name
+ Quiz(int, String)
+ add(int) : void
+ delete (int) : void
+ print() : void
- search(int) : int
The count is the number of quizzes, 2) scores is an array object storing all scores as
integers, and 3) name is a string object for student name.
The class Quiz must include the constructors and methods in the table: (If your class does
not contain any of the following methods, points will be deducted). The public and private
access modifiers are represented as "+" and "-" respectively.
1. Quiz(int, String): (2 pts)
The constructor is to
a. Create an instance of an int-type array with the length of input parameter. Each
element in the array is initialized as -1.
b. The count is set as 0. It is not the length of array but the number of valid
scores. In other words, the scores is a partially filled array, and the count is
used as an END position of valid scores.
c. Set the name with the second input parameter.
2. add(int):void (2 pts)
If there is room (left in) the array, add the parameter value to the END(count)
position of the array and adjust the count to reflect how many values are in the
array. If the value was added, DO NOT print any output. If the array is full, print
the error message as shown below. This is the output if the value 3 was to be added
and there is no room.
Array is full. The value 3 cannot be added.

3. print(): void

print the name of student and the valid quiz scores in the array as shown below. Not that it prints at most 5 values per line and that the values are separated by three spaces.

4. search(int): int

This method should perform a linear or sequential search. The method is to look at the elements in the array until the value of the parameter is found or all values have been examined. If a value occurs in the array more than onc, the method should return the first position where the value was found. If the value is not in the array, then the method should return -1. There is not output from this method.

5. delete(int): void

Search for the value in the array using the search method. If the value is currently in the array, remove the value from the array by moving the other elements "up" and adjust the count to reflect how many values are in the array. If the value was successfuly removed, do not print any output. Only if the value is not found, then print the error message "The value ___ was not found and cannot be detected"

Write the test driver called Assignment7.java. (5 pts) Assignment7.java contains the main method to create a Quiz instance object and test the methods in the class. The program will ask a user to enter one of the commands. Based on the user's choice, the program needs to perform corresponding operation. This will be done by calling (invoking) one of the methods you defined in the Quiz class. It will terminate when the user enters 'q'. The tester program provided in the last assignments may help. In addition to the main method, the Assignment7 class has a static method, printMenu(), to print out the following commands.

Command Options
-----------------------------------
n: Create a new data

a: Add a score

d: Delete a score

p: Print the information

?: Display the menu again

q: Quit this program

Here is the description for each option:

n: ask and read the size of array and the name of student

a: ask and add a score to the array

d: ask and delete a score in the array

p: print the information of array.

?: displays the menu

q: quits the program

Explanation / Answer

Sorry. please use this. Hope it helps!

//Quiz class
public class Quiz
{
   private int scores[];
   private String name;
   private int count;
  
   public Quiz(int len,String name)
   {
       scores=new int[len];
       count=0;
       for(int i=0;i<this.scores.length;i++)this.scores[i]=-1;
       this.name=name;
   }
  
   public void add(int score)
   {
       if(this.count<this.scores.length)
       {
           this.scores[count]=score;
           this.count++;
       }
       else
       {
           System.out.println("Array is full. The value "+score+" cannot be added.");
       }
   }
  
   public void delete(int score)
   {
       //deletes score at a particular index
       int a=this.search(score);
       if(a!=-1)
       {
           for(int i=a;i<this.count;i++)
           {
               if(i==this.count-1){this.scores[i]=-1;}
               else this.scores[i]=this.scores[i+1];
           }
           this.count--;
       }
       else
       {
           System.out.println("The value "+score+" was not found and cannot be detected");
       }
   }
  
   public void print()
   {
       String s=this.name;
       for(int i=0;i<this.count;i++)
       {
           s+=" "+this.scores[i];
           if(i==4)break;
          
       }
       System.out.println(s);
   }
   private int search(int score)
   {
       //returns i if found else -1
       int ret=-1;
       for(int i=0;i<this.scores.length;i++)
           if(this.scores[i]==score){ ret=i;;break;}
       return ret;
   }
}

//Assignment7 class

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;


public class Assignment7
{
   public static void main(String[] args) throws Exception
   {
       Quiz q=new Quiz(5,"Quiz1");
       BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
       boolean quit=true;
       menu();
       while(quit)
       {
           char input=sc.readLine().charAt(0);
           switch (input)
           {
           case 'n':
           {
               System.out.println("Enter the array size");int len=Integer.parseInt(sc.readLine());
               System.out.println("Enter the student name: ");String name=sc.readLine();
               q=new Quiz(len, name);
               break;
           }
           case 'a':{System.out.println("Enter the score to be added");q.add(Integer.parseInt(sc.readLine()));break;}
           case 'd':{System.out.println("Enter the score to be deleted");q.delete(Integer.parseInt(sc.readLine()));break;}
           case 'p':{q.print();break;}
           case '?':{menu();break;}
           case 'q':{quit=false;break;}
           }
          
       }
   }
   public static void menu()
   {
       System.out.println("Command Options");
       System.out.println("-----------------------------------");
       System.out.println("n: Create a new data");
       System.out.println("a: Add a score");
       System.out.println("d: Delete a score");
       System.out.println("p: Print the information");
       System.out.println("?: Display the menu again");
       System.out.println("q: Quit this program");
   }
   public static void enterData()
   {

   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote