[SOLVED] IT2650 Assignment13

30.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon Assignment_13-cvmbpe.zip (747.3 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
Rate this product

Step 01 – Compile the following code (you can get the file from Blackboard)

I used the online compiler: https://www.jdoodle.com/online-java-compiler/

However, you can use any IDE as long as you submit code that I can compile and execute.

import java.io.*;

import java.util.Scanner;

 

public class Assignment13

{

 

// put class definition here

 

public static void main(String[] args)

{

 

System.out.println(“A13 – Written by Matt Weisfeld”);

 

Scanner console = new Scanner(System.in);

 

// Input Strings

String divisor=null, dividend=null;         int x=0,y=0, counter=1;

 

 

while (true) {

 

System.out.println(“\nPass ” + counter++ +  “\n—————————–\n”);             System.out.print(“Please enter the dividend (or ‘x’ to end): “);             dividend = console.nextLine();

System.out.println(dividend);

 

if (dividend.equals(“x”)) {

System.out.println(“\nProgram Terminated by User”);                  break;

}

 

System.out.print(“\nPlease enter the divisor : “);             divisor = console.nextLine();

System.out.println(divisor + “\n”);

 

x=Integer.parseInt(dividend);             y=Integer.parseInt(divisor);

 

// Put code here

 

}

 

System.out.println(“\nBye”);

}

}

 

 

Step 02 – Run the code (the output should look something like this)

 

 

 

Step 03 – Add the code

 

This code accepts 2 values from the user inside of a loop, one for a dividend and one for a divisor. The loop continues until the dividend equals ‘x’.

 

Each time through the loop, your code must calculate the quotient (quotient =divisor/dividend) and print the result.

You must create a user defined exception called MyException. Here are the constraints:

 

  • Create a user defined exception called MyException.
  • Enclose the division (quotient =divisor/dividend) inside of a try/catch block.
  • Check to see if the divisor (in y inside of the code) is equal to zero.
  • If y is zero, then throw the user defined exception with the message “Attempted to divide by zero!”.
  • In all cases, continue with the loop.

 

My test data will look like this:

 

10

2

10

0

X

 

So you should make sure your code works with this data as well (but not just this data).

 

All that you need to turn in is your final version of A13. So upload that single file to Blackboard.

 

Step 04 – When you run the code you will get something like the following output

 

 

Step 05 – Submit the updated file to A 12.

 

Submit the file to Blackboard.

  • Assignment_13-cvmbpe.zip