Question

Must be done in Java.

20 points! PROBLEM 3: EXTENDED FAMILY Complete this and the whole village will be celebrating! You will have a list of villag

Scanner is a class in the java.util package used for obtaining the input of both integers and strings (amongst other types).

Provide the rest of the code with full comments and explanation and with proper indentation.

Use simple methods for better understanding.

Must compile.

CODE PROVIDED:

import java.util.ArrayList;
import java.util.Scanner;

public class Problem3 {

   public static void main( String [] args ) {

       Scanner in = new Scanner( System.in );

       //PLEASE START YOUR WORK HERE
       //**********************************************************


      
      
      
      
      
      

       //**********************************************************
       // PLEASE END YOUR WORK HERE

       System.out.print("END OF OUTPUT");
   }
}

20 points! PROBLEM 3: EXTENDED FAMILY Complete this and the whole village will be celebrating! You will have a list of village people similar to the previous problems. This time, we want to identify which family (or families) within the village have the most family members. After identifying the largest family (or families), we want you to output their family name(s) in the order that they first appear. INPUT: u coneists hos man Input consists a list of name. On each line, there is a first name followed by a last name (their family name) how man larte Sample input: Eric Siegel Alex Warren Angela Siegel James Fleming Marika Warren de c PROCESSING: Your program must keep track of each family as well as the number of members in each family. It must then identify the largest family size. OUTPUT: Sample Output: The output of the program is a list of all of the largest families (1 or more) in the form of one family name per line in the order that they first appear. Siegel Warren
Scanner is a class in the java.util package used for obtaining the input of both integers and strings (amongst other types). To create an object of the Scanner class that uses the standard input stream, we use the following: Scanner stdin -new Scanner (System.in)i To output a value in Java followed by a new line use the statement: System.out.println (value)i Where value is a string, or an integer, or any expression resulting in a value. To output a value without a new line use the With the Scanner class objects, we can use the following methods: statement: System.out.print (value); Method Description Returns true if there is a token ready in the scanner's input. (1+ nonwhitespace characters) stdin.hasNext() To instantiate an array of n integers int [] values-new int[n]; Returns true if the next token Note: n can either be an integer variable or an integer variable, e.g., 6. stdin.hasNextInt) in the scanner's input can be interpreted as an int value For loop: Finds and returns the next stdin.next() To iterate over values O token from this scanner n for (int i0; i
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.ArrayList;
import java.util.Scanner;
public class Problem3 {
public static void main( String [] args ) {
Scanner in = new Scanner( System.in );
//PLEASE START YOUR WORK HERE
//**********************************************************
//read number of names
int numberOfNames=in.nextInt();
//declare array of full names
String[] fullNames=new String[numberOfNames];
//declare a arraylist variable which is used for storing unique last names
ArrayList<String> uniqueLastNames=new ArrayList<String>();
int i,j;
in.nextLine();
//loop through numberOfNames
for(i=0;i<numberOfNames;++i)
{
fullNames[i]=in.nextLine();
//get first and last name using split() method present in String class
String[] name=fullNames[i].split("\\s+");
String lastName=name[1]; //where name[0] is first name and name[1] is last name
//if last name is not present in ArrayList add it to given list
if(!uniqueLastNames.contains(lastName))
uniqueLastNames.add(lastName);
}
//store occurences of last names
int[] occurences=new int[uniqueLastNames.size()];
// declare count variable which keeps track of number of occurences
int count;
for(i=0;i<uniqueLastNames.size();++i)
{
count=0;
for(j=0;j<numberOfNames;++j)
{
if(uniqueLastNames.get(i).equals(fullNames[j].split("\\s+")[1]))
++count;
}
occurences[i]=count; //store count
}
// get max occurence value
int max=occurences[0];
for(i=1;i<occurences.length;++i)
{
if(max<occurences[i])
max=occurences[i];
}
for(i=0;i<occurences.length;++i)
{
if(max==occurences[i] && max>1)
System.out.println(uniqueLastNames.get(i));
}
//**********************************************************
// PLEASE END YOUR WORK HERE
System.out.print("END OF OUTPUT");
}
}
Output

koushikhp@koushikhpnew: koushikhp@koushikhpnew: $ java Problen3 Eric Siegel Alex Warren Angela Siegel James Fleming Marika Wa

koushikhp@koushikhpnew: koushikhp@koushikhpnew: $ java Problen3 Eric Siegel Alex Warren Angela Siegel James Fleming Marika Warren Siegel Warren END OF OUTPUTkoushikhp@koushikhpnew:- java Problem3 Eric Siegel Alex Warren Angela Siegel James Fleming Marika Siegel Siegel E-END OF OUTPUTkoushikhpakoushikhpnew:~$ 478

Add a comment
Know the answer?
Add Answer to:
Must be done in Java. Provide the rest of the code with full comments and explanation and with proper indentation. Use...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Must be in Java. Please show step by step process with proper explanation and comments. Please...

    Must be in Java. Please show step by step process with proper explanation and comments. Please maintain proper indentation. CODE PROVIDED: Doctor.java HospitalDoctor.java Q1Runner.java import java.util.Scanner; public class Q1Runner { public static void main(String[] args) { Scanner kb = new Scanner(System.in);               // Do your work here        } } You are asked to create the starting point of a system to represent several types of medical doctors. You decided to implement two classes: a superclass...

  • This Java program reads an integer from a keyboard and prints it out with other comments....

    This Java program reads an integer from a keyboard and prints it out with other comments. Modify the comments at the top of the program to reflect your personal information. Submit Assignment1.java for Assignment #1 using Gradescope->Assignemnt1 on canvas.asu.edu site. You will see that the program has a problem with our submission. Your program is tested with 4 testcases (4 sets of input and output files). In order to pass all test cases, your program needs to produce the same...

  • Solve it by JAVA please. Now, write a class named InputSplitter. This class will take input...

    Solve it by JAVA please. Now, write a class named InputSplitter. This class will take input from the keyboard (using a Scanner) and split the incoming tokens into integers, floating point numbers, and strings. The incoming tokens will be added to one of three accumulators which start out at zero, and which keep a running total. Thus, the class will have an accumulator for integers. It starts out with the value zero. Every time another integer is read in, it...

  • JAVA

    Write a Java class (program) which inputs a simple integer and outputs a list of values from the input variable down to 0 (not including 0). You should only show every other value in the output, starting with the input value. You must use a for loop.For example, if the input is 23, the output should be:The input value was 2323 21191715131197531Code given:import java.util.Scanner;/**  * This program counts down from the input number down to (but not including)   * 0, skipping...

  • Please USE JAVA only Write a class named InputSplitter. This class will take input from the...

    Please USE JAVA only Write a class named InputSplitter. This class will take input from the keyboard (using a Scanner) and split the incoming tokens into integers, floating point numbers, and strings. The incoming tokens will be added to one of three accumulators which start out at zero, and which keep a running total. Thus, the class will have an accumulator for integers. It starts out with the value zero. Every time another integer is read in, it is added...

  • The following code uses a Scanner object to read a text file called dogYears.txt. Notice that...

    The following code uses a Scanner object to read a text file called dogYears.txt. Notice that each line of this file contains a dog's name followed by an age. The program then outputs this data to the console. The output looks like this: Tippy 2 Rex 7 Desdemona 5 1. Your task is to use the Scanner methods that will initialize the variables name1, name2, name3, age1, age2, age3 so that the execution of the three println statements below will...

  • in java coorect this code & screenshoot your output ---------------------------------------------------------------------- public class UNOGame {     /**...

    in java coorect this code & screenshoot your output ---------------------------------------------------------------------- public class UNOGame {     /**      * @param args the command line arguments      */         public static void main(String[] args) {       Scanner input=new Scanner(System.in);          Scanner input2=new Scanner(System.in);                             UNOCard c=new UNOCard ();                UNOCard D=new UNOCard ();                 Queue Q=new Queue();                           listplayer ll=new listplayer();                           System.out.println("Enter Players Name :\n Click STOP To Start Game..");        String Name = input.nextLine();...

  • Must be done in Java. PROBLEM 1 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL....

    Must be done in Java. PROBLEM 1 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL. Provide the rest of the code with full comments and explanation and with proper indentation. Use simple methods for better understanding. Must compile. At the end, show the exact Output that's shown in Problem 2. CODE PROVIDED FOR PROBLEM 1: import java.util.Scanner; public class Problem1 {    public static void main( String [] args )    {        //N denoting the size of the board        int n;       ...

  • Must be done in Java. PROBLEM 1 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL....

    Must be done in Java. PROBLEM 1 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL. Provide the rest of the code with full comments and explanation and with proper indentation. Use simple methods for better understanding. Must compile. At the end show the exact Output that's shown in the Problem 2. CODE PROVIDED FOR PROBLEM 1: import java.util.Scanner; public class Problem1 {    public static void main( String [] args )    {        //N denoting the size of the board        int...

  • I need to create a code for this prompt: In this project we will build a...

    I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT