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

Part#2: Programming (15 pts) Your assignment is to write and submit two java fil

ID: 3567663 • Letter: P

Question

Part#2: Programming (15 pts)
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 (2 pts) Print the name of student and the valid quiz scores in the array as shown below. Note that it prints at most 5 values per line and that the values are separated by three spaces. If the values {3, 6, 7, 4, 1, 4, -1, -1, -1} are in the array, then the output is
James Bond 3 6 7 4 1
4


4. search(int):int (2 pts) 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 once, the method should return the index, first position, where the value was found. If the value is not in the array, then the method should return a -1. There is NO output from this method. (no printing)


5. delete(int):void (2 pts) 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

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