Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Solve the following problem on the provided paper. This test has 1 page and a to

ID: 646121 • Letter: S

Question

Solve the following problem on the provided paper. This test has 1 page and a total of 100 points. 1. Write a Java program to: (a) Prompt the user for the number of people in their family. (b) Read the first name, the gender, and the age of every family member. (c) Output the average age of people in that family. (d) Output the first name of the oldest person in that family. (e) Output whether that family that more females or more males. 2. Using a while-loop, count the number of input values until an odd value is input. For example, if the laser inputs 2 8 6 1 then the program will output 3 because three values were input before an odd value was input.

Explanation / Answer

(1) package demo;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class demo2 {
public static void main(String[] args) {
System.out.println("Enter the numbers of family members ");
        Scanner input = new Scanner(System.in);
        int count = input.nextInt();
Map<Integer,Map<String,String>> details=new HashMap<>();

for (int i = 0; i <count ; i++) {
Map<String,String> a1=new HashMap<>();

System.out.println("Enter the fname ");
        Scanner input1 = new Scanner(System.in);
       String fname = input1.next();
        System.out.println("Enter the gender ");
        Scanner input2 = new Scanner(System.in);
       String gender = input2.next();
        System.out.println("Enter the age ");
        Scanner input3 = new Scanner(System.in);
        String age = input3.next();
        a1.put("fname", fname);
        a1.put("gender", gender);
        a1.put("age", age);
        details.put(count,a1);
       
}


System.out.println("average age of people");

List<Integer> a2=new ArrayList<>();
List<String> a3=new ArrayList<>();
List<String> a4=new ArrayList<>();
for (int i = 0; i < details.size(); i++) {
Map<String,String> a1=new HashMap<>();

a1=details.get(i);

a2.add(Integer.parseInt(a1.get("age")));
a3.add(a1.get("fname"));
a4.add(a1.get("gender"));


}
int average=0;
for (int i = 0; i <a2.size(); i++) {

average=average+a2.get(i);

}
System.out.println(average/a2.size());


int maxage=Collections.max(a2);

String familymaxage="";
for (int i = 0; i < a2.size(); i++) {

if(a2.get(i)==maxage)
familymaxage=a3.get(i);

}
System.out.println("family member with more age is "+ familymaxage);

int mc=0,fc=0;

for (int i = 0; i < a4.size(); i++) {
if("m".equals(a4.get(i)))
{
mc=mc+1;
}
else{
fc=fc+1;
}
}

if(mc>fc)
{
System.out.println("males are more than female with "+ mc);
}
else
{
System.out.println("females are more than males with "+ fc);
}

}




}

(2) package demo;

import java.util.Scanner;

public class demo3 {
public static void main(String[] args) {
boolean a=true;
int counter=0;
while (a) {
System.out.println("Enter the number ");
    Scanner input = new Scanner(System.in);
    int count = input.nextInt();

    if(count%2!=0)
    {
    a=false;
    }
    else{
    counter++;
    }
}

System.out.println("Number of repetetions is: "+counter );
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote