Question: Hello, my code that I have for this assignment is below and needs a few adjustments that I have NO idea how to fix. Been
Hello, my code that I have for this assignment is below and needs a few adjustments that I have NO idea how to fix. Been looking all over google but yeah...So here's the assignment (the exceptions were defined in a separate class that I can upload if you want)
Business Feature:
Suppose that you are in charge of customer service for a certain business. As phone calls come in, the name of the caller is recorded and eventually a service representative return the call and handles the request.
Business Requirements:
Write a class ServiceRequests that keeps track of the names of callers. The class should have the following methods:
addName(name)adds a name to the list (array) of names. Throws a ServiceBackUpException if there is no free space in the list.
removeName(name)removes a name from the list. Throws a NoServiceRequestException if the name is not in the list.
getName(i)returns the ith name in the list.
getNumberreturns the current number of service requests.
Write a program (Test/Driver class with main method) that uses an object of type ServiceRequests to keep track of customers that have called. It should have a loop that, in each iteration, attempts to add a name, remove a name, or print all names. Use an array of size 10 as the list of names
--------------------------------------- import java.util.ArrayList; import java.util.Scanner; import java.io.*; import java.util.*; public class ServiceRequests { //for the saze and iterting through array int size = 0; int count=0; Scanner input = new Scanner(System.in); //declare the array outside the constructor to make it available everywhere ArrayList namesArray=new ArrayList(); //before we get to the constructor, we have to add to the array, the argument is the array!!! public void addName(ArrayList namesArray) { int i=0; try { //Array! add to the new one Scanner namesArrayIn= new Scanner(System.in); do { //auto in is a term we use at work when someone takes phone calls System.out.println("Auto In? (y/n"); if(namesArrayIn.next().startsWith( "yes")) {System.out.println("Enter Customer Name: "); namesArray.add(namesArrayIn.next()); count ++;} else break; //HERE YOU GO MEGHAN THIS IS WHERE THE PROBLEM IS!!!!!!!!!!!!!! boolean result = namesArray.isEmpty(); if(result==true) {throw new ServiceBackUpException("There is already a customer with that name!");} } } //NOW TO REMOVE FROM THE LIST!!!!!!!!!!!!!!!! public String removeName(String name) { try {System.out.println("Who did you call?"); Scanner removeNameArray=new Scanner(System.in); removeNameArray = removeName.nextLine(); boolean res = names.contains(name); if(res==true) names.remove(name) else throw new NoServiceRequestException(());} catch(NoServiceRequestException NS) { Stystem.out.println(NS.getMessage()); } System.out.println("Your new list: " + namesArray); return namesArray; } public int getName(int i) { System.out.println("Enter the position of the name to get name"); Scanner gName - new Scanner(Systerm.in); int namePos=gName.nextInt(); int length=names.size(); if(namePosout.println("Name in that position is " + index); } else System.out.println("Entered position " +namePos + " is not in the list"); return namePos; } public int getNumber() { System.out.print("Total Service REquests: "+count); return count; } //MAIN METHOD!!!!!!!! public static void main(String args[]) { ArrayList a=newServiceRequests(); SR.addName(a); SR.getName(b); SR.removeName(rmName); SR.getNumber(); } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
