Question: I need help with the flowchart, pseudocode, and UML diagram for both programs. InputMismatch.java import java.util.InputMismatchException; import java.util.Scanner; public class InputMismatch { public static void

I need help with the flowchart, pseudocode, and UML diagram for both programs.

InputMismatch.java

import java.util.InputMismatchException; import java.util.Scanner;

public class InputMismatch {

public static void main(String[] args) { Scanner scan = new Scanner(System.in); int firstNum, secondNum=0; while(true){ try{ System.out.println("Enteraninteger: "); firstNum = scan.nextInt(); break; } catch(InputMismatchException e){ System.out.println("Pleaseenteraninteger"); scan.next(); } } while(true){ try{ System.out.println("Enteraninteger: "); secondNum = scan.nextInt(); break; } catch(InputMismatchException e){ System.out.println("Pleaseenteraninteger"); scan.next(); } } int sum = firstNum + secondNum; System.out.println("The sum of two numbers is : "+sum); }

}

NumberFormat.java

import java.util.Scanner;

public class NumberFormat {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

try{

System.out.println("Enter a binary string:");

String s = scan.next();

int integerValue = bin2Dec(Integer.parseInt(s));

System.out.println("The decimal value of "+s+" is "+integerValue);

}

catch(NumberFormatException e){

System.out.println(e);

}

}

public static int bin2Dec(int binaryNumber) throws NumberFormatException{

int decimal = 0;

int p = 0;

try{

while(true){

if(binaryNumber == 0){

break;

} else {

int temp = binaryNumber%10;

decimal += temp*Math.pow(2, p);

binaryNumber = binaryNumber/10;

p++;

}

}

}

catch(NumberFormatException e){

throw new NumberFormatException("Invalid binary number");

}

return decimal;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!