public class TutorialSpace { // slots — the number of available slots in a tutorial class private int slots; // activated — true if the tutorial class has been activated private boolean activated; /** * TutorialSpace(n) — a constructor for a tutorial class with n slots. * * @param n */ public TutorialSpace(int n) { this.slots = n; this.activated = false; } /** * activate() — activates the tutorial class. Throws an exception if the * tutorial class has already been activated. * * @throws NotActivatedException */ public void activate() throws NotActivatedException { if (activated) { throw new NotActivatedException("Already Activated"); } else { activated = true; } } /** * reserveSlot()—enrol a student into the tutorial class by decreasing the * number of slots left for enrolling in the class. Throws an exception if slot * is either completely used or the tutorial class is not active. * * @throws EmptyException */ public void reserveSlot() throws EmptyException { if (!activated || slots == 0) { throw new EmptyException("Tutorial space is empty"); } else { slots--; } } /** * slotsRemaining()—returns the number of slots remaining in the tutorial class. */ public int slotsRemaining() { return slots; } } public class NotActivatedException extends Exception { /** * */ private static final long serialVersionUID = 1L; public NotActivatedException(String msg) { super(msg); } } public class EmptyException extends Exception { /** * */ private static final long serialVersionUID = 1L; public EmptyException(String msg) { super(msg); } }
3. Write a client program, registerClass, to test the use of the TutorialSpace class. Make sure you consider a testing strategy that can test all the methods and exceptions in the TutorialSpace class.
10 have requested this problem solution
The more requests, the faster the answer.
The aims of this lab are: Understand the purpose of exception handlingHow to create your own exception class.Use of assertion1. Create a class TutorialSpace that used to enrol student in a tutorial class. It should have the following private attributes:slots — the number of available slots in a tutorial classactivated — true if the tutorial class has been activated and the following methods:TutorialSpace(n) — a constructor for a tutorial class with n slots. activate() — activates the tutorial class. Throws an exception if...
Write a unit test to test the following class. Using Java : //Test only the debit method in the BankAccount. : import java.util.*; public class BankAccount { private String customerName; private double balance; private boolean frozen = false; private BankAccount() { } public BankAccount(String Name, double balance) { customerName = Name; this.balance = balance; } public String getCustomerName() { return customerName; } public double getBalance() { return balance; } public void setDebit(double amount) throws Exception { if (frozen) { throw...
Im writing a method to evaluate a postfix expression. Using my own stack class. Here is my code but I keep getting a classcastexception where it says java.lang.Character cannot be cast to java.lang,Integer. Im not sure how to fix this. public class Evaluator { public static void evaluatePost(String postFix) { LinkedStack stack2 = new LinkedStack(); int val1; int val2; int result; for(int i = 0; i < postFix.length(); i++) { char m = postFix.charAt(i); if(Character.isDigit(m)) { stack2.push(m); } else { ...
List the unique classes/ADTs in the following code segment: (hint: there are 6) public class LinkedQueueclass protected class QueueNode int info; QueueNode link; private QueueNode queue Front; private QueueNode queue Rear; public class QueueOverflowException extends Queue Exception public QueueOverflowException() super("Queue Overflow"); public QueueOverflowException (String msg) super (msg); System.out.println("An exception occurred");
Need help with this Java. I need help with the "to do" sections.
Theres two parts to this and I added the photos with the entire
question
Lab14 Part 1:
1) change the XXX to a number in the list, and YYY to a
number
// not in the list
2.code a call to linearSearch with the item number
(XXX)
// that is in the list; store the return in the variable
result
3. change both XXX numbers to the...
Need some help on the following problem in java. I have to modify the code I written so far(below) to do the following three things: a). Write a method called diagnostics that occasionally throws any one of the exceptions you have created depending on the values generated by a random-number generator. b). Write a method called display that calls diagnostics and provides exception handlers to display a message when an exception occurs. Otherwise, if an exception does not occur, method...
What is wrong with this code? Please bold the changes that were made so this code runs properly. The Problem is: 11.16 (Catching Exceptions with SuperClasses) Use inheritance to create an exception superclass (called Exception) and exception subclasses ExceptionB and ExceptionC, where ExceptionB inherites from ExceptionA and ExceptionC inherits from ExeptionB. Write a program to demonstrate that the catch block for type ExceptionA catches exceptions of types ExceptionB and ExceptionC. I got this far but I'm still getting a lot...
software testing without making any changes to the java classes provided below, come up with some junit test cases to test the code. To get you started, here are four test cases you must implement: • Use the setString() function in MyCustomStringInterface to set the value to “H3y, l3t'5 put s0me d161ts in this 5tr1n6!11!!”. Then test to see if the CountNumbers() function is equal to the number of sequential digits in the original string (in this case, 9). •...
Please answer the following question with Java Modify the Employee and ProductionWorker classes provided below so they throw exceptions when the following errors occur. - The Employee class should throw an exception named InvalidEmployeeNumber when it receives an employee number that is less than 0 or greater than 9999. - The ProductionWorker class should throw an exception named InvalidShift when it receives an invalid shift. - The ProductionWorker class should thrown anexception named InvalidPayRate when it receives a negative number...
*JAVA* Can somebody take a look at my current challenge? I need to throw a different exception when a)(b is entered. It should throw "Correct number of parenthesis but incorrect syntax" The code is as follows. Stack class: public class ArrayStack<E> { private int top, size; private E arrS[]; private static final int MAX_STACK_SIZE = 10; public ArrayStack() { this.arrS = (E[]) new Object[MAX_STACK_SIZE]; this.top = size; this.size = 0;...