Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Objective: The purpose of this assignment is to help you understand arrays, sorting and searching Problem Description In the end, the mad titan Thanos is successful: He gets all six Infinity Stones,...

1 answer below »

Objective: The purpose of this assignment is to help you understand arrays, sorting and searching


Problem Description


In the end, the mad titan Thanos is successful: He gets all six Infinity Stones, puts them in the Infinity Gauntlet, snaps his fingers, and causes half the life in the universe to basically turn to dust. Earth's mightiest heroes, the Avengers, have just lost half their team, and are scrambling for re-enforcements. While they are off doing superhero things, they have asked you to build a database of the people who went missing after the snap.

You are given 2 lists, a list of names pre-snap, and a list of names post-snap, your task is to list all the people that were dusted away after Thanos' snap.

Input


1. A number containing the length of the first (pre-snap) list
2. A list of names separated by spaces, each name corresponds to a person (assume each name is unique)
3. A number containing the length of the second (post-snap) list
4. A list of names separated by spaces, each name corresponds to a person (assume each name is unique)

Output


A list of names corresponding to the people who were dusted away, sorted in alphabetical order


Sample Run 1:
Enter length of pre-snap list : 14
Enter names : Tony Widow Peter Thor Strange Pepper Tchalla Bucky Steve Groot Bruce Rocket Drax Carol
Enter length of post-snap list : 7
Enter names : Rocket Thor Pepper Bruce Tony Steve Carol

Output
Bucky Drax Groot Peter Strange Tchalla Widow


Sample Run 2:
Enter length of pre-snap list : 11
Enter names : K C E B D F H G I J A
Enter length of post-snap list : 5
Enter names : K B C A F

Output
D E G H I J

I have provided some template code below. Please use this as your starting point, and make sure you do NOT change the class name.

Download Template Code :Snap.javaPreview the document(I will paste this at the bottom of the description)

Assumptions and Considerations

1. You may assume all names are unique. i.e. Names will not be repeated.

2. The order of the names in both lists may be different. For example, "Tony" appears before "Pepper" in the first list but appears after "Pepper" in the second list

3. Each name is only 1 word long

4. When testing your program, note the length of the post-snap list may be exactly half or off by 1. Please make sure you check these cases.

Approach


Break the problem down into 2 logical steps
1. Find all the missing elements that are in the first list but not in the second list. Store these in a third list.
2. Sort the 3rd list, and we're done.


Submission

1. The Snap.java file containing your solution

2. Screenshot of sample output

Note

1. For the searching part, you will be using linear search with a simple modification for strings. When checking if 2 strings in an array are equal, instead of checking if(arr[i] == arr[j]), like you would do in case of primitive datatypes, check if (arr[i].equals(arr[j)) -- this is the syntax for comparing 2 strings.

2. For the sorting part, you may use either bubble sort or selection sort. You are NOT allowed to use anything else ( will result in a failing grade). When sorting a string array, in the comparison part, instead of checking if(arr[i] > arr[i+1]) like you would do when sorting numbers, you would instead be doing if (arr[i].compareTo(arr[i+1]) > 0)

Answered Same Day Dec 07, 2021

Solution

Yogesh answered on Dec 08 2021
135 Votes
package com.company;
import java.util.A
ays;
import java.util.Scanner;
public class Snap {
public static void main(String[] args)
{

TODO Auto-generated method stu
Scanner input = new Scanner(System.in);
System.out.print("Enter length of pre-snap list : ");
int l1 = input.nextInt();
String s1[] = new String [l1];
System.out.print("Enter names : ");
for(int i=0;i s1[i] = input.next();
System.out.print("Enter length of post-snap list : ");
int l2 = input.nextInt();
if (l2 >= l1){
System.out.println("Length of post-snap list is not Valid...\nIt should be less than length of pre-snap list.");
System.exit(0);
}
String s2[] = new String [l2];
System.out.print("Enter names : ");
for(int i=0;i s2[i] = input.next();
String s3[] =...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here