public class elements { public static void main(String args[]) { Scanner sc = new Scanner(System.in); // Creating two sets Set set1 = new HashSet(); Set set2 = new HashSet(); System.out.println("Enter the element of set A [max-5 elements]: "); for (int i = 0; i < 5; i++) { int num = sc.nextInt(); set1.add(num); } System.out.println("Enter the element of set B [max-5 elements]: "); for (int i = 0; i < 5; i++) { int num1 = sc.nextInt(); set2.add(num1); } // creating a menu of opeartions System.out.println("a. Identify elements of set"); System.out.println("b. Check Union"); System.out.println("c. Check Difference"); System.out.println("d. Check Intersection"); System.out.println("e. Check Subset"); System.out.println("f. If set A and B are empty can't perform opeartion b to e"); System.out.print("Enter you choice: "); // taking choice input int ch = sc.next().charAt(0); while (ch != 'f') { switch (ch) { // finding the set A and B elements case 'a': if (set1.size() == 0 && set2.size() == 0) { System.out.println("Set A and B are empty."); } System.out.println("\nSet A = " + set1); System.out.println("\nSet B = " + set2); break; // finding the Union of set case 'b': Set union_data = new HashSet(set1); union_data.addAll(set2); System.out.println("Union of set A and B is: "); System.out.println(union_data); break; case 'c': // Finding Difference of set1 and set2 Set difference_data = new HashSet(set1); difference_data.removeAll(set2); System.out.println("Difference of set A and B is: "); System.out.println(difference_data); break; case 'd': // Finding Intersection of set1 and set2 Set intersection_data = new HashSet(set1); intersection_data.retainAll(set2); System.out.println("Intersection of set A and B is: "); System.out.println(intersection_data); break; // finding subset case 'e': System.out.print("Enter a number: "); int number = sc.nextInt(); if (set1.contains(number) && set2.contains(number)) { System.out.println(number + " is subset of A and B"); } else { System.out.println(number + " is not subset of A and B"); } break; default: System.out.println("Enter a valid input."); break; } System.out.println("\na. Identify elements of set"); System.out.println("b. Check Union"); System.out.println("c. Check Difference"); System.out.println("d. Check Intersection"); System.out.println("e. Check Subset"); System.out.println("f. If set A and B are empty can't perform opeartion b to e"); System.out.print("Enter you choice: "); ch = sc.next().charAt(0); } if (ch == 'f') { System.out.println("set A and B is empty and you can't perform operation b to e."); } } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

INSTRUCTION: make this a flowchart

 

 

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class elements {
  public static void main(String args[]) {

    Scanner sc = new Scanner(System.in);

    // Creating two sets
    Set<Integer> set1 = new HashSet<Integer>();

    Set<Integer> set2 = new HashSet<Integer>();

    System.out.println("Enter the element of set A [max-5 elements]: ");
    for (int i = 0; i < 5; i++) {
      int num = sc.nextInt();
      set1.add(num);
    }
    System.out.println("Enter the element of set B [max-5 elements]: ");
    for (int i = 0; i < 5; i++) {
      int num1 = sc.nextInt();
      set2.add(num1);
    }
    // creating a menu of opeartions
    System.out.println("a. Identify elements of set");
    System.out.println("b. Check Union");
    System.out.println("c. Check Difference");
    System.out.println("d. Check Intersection");
    System.out.println("e. Check Subset");
    System.out.println("f. If set A and B are empty can't perform opeartion b to e");
    System.out.print("Enter you choice: ");
    // taking choice input
    int ch = sc.next().charAt(0);
    while (ch != 'f') {
      switch (ch) {

      // finding the set A and B elements
      case 'a':
        if (set1.size() == 0 && set2.size() == 0) {
          System.out.println("Set A and B are empty.");
        }
        System.out.println("\nSet A = " + set1);
        System.out.println("\nSet B = " + set2);
        break;

      // finding the Union of set
      case 'b':
        Set<Integer> union_data = new HashSet<Integer>(set1);
        union_data.addAll(set2);
        System.out.println("Union of set A and B is: ");
        System.out.println(union_data);
        break;

      case 'c': // Finding Difference of set1 and set2
        Set<Integer> difference_data = new HashSet<Integer>(set1);
        difference_data.removeAll(set2);
        System.out.println("Difference of set A and B is: ");
        System.out.println(difference_data);
        break;
      case 'd': // Finding Intersection of set1 and set2
        Set<Integer> intersection_data = new HashSet<Integer>(set1);
        intersection_data.retainAll(set2);
        System.out.println("Intersection of set A and B is: ");
        System.out.println(intersection_data);
        break;

      // finding subset
      case 'e':
        System.out.print("Enter a number: ");
        int number = sc.nextInt();
        if (set1.contains(number) && set2.contains(number)) {
          System.out.println(number + " is subset of A and B");
        } else {
          System.out.println(number + " is not subset of A and B");
        }
        break;
      default:
        System.out.println("Enter a valid input.");
        break;
      }

      System.out.println("\na. Identify elements of set");
      System.out.println("b. Check Union");
      System.out.println("c. Check Difference");
      System.out.println("d. Check Intersection");

      System.out.println("e. Check Subset");
      System.out.println("f. If set A and B are empty can't perform opeartion b to e");
      System.out.print("Enter you choice: ");
      ch = sc.next().charAt(0);
    }

    if (ch == 'f') {
      System.out.println("set A and B is empty and you can't perform operation b to e.");
    }

  }
}

Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Concept of memory addresses in pointers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education