Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 ) Explain where and why the program went wrong / and or not a good ( use line numbers ) . 2 ) Fix

1) Explain where and why the program went wrong/and or not a good (use line numbers).
2) Fix them to get accurate results and smart program . You don't have to rewrite the whole program, just explain how to fix them (use line numbers).
import java.util.*;
import java.io.*;
class Personinfo {
String type;
String name;
String gender;
int age;
}
public class People {
static ArrayList List = new ArrayList<>();
People (String file) throws FileNotFoundException {
Scanner input = new Scanner (new File ("people.txt");
while (input.hasNext()){
PersonInfo p = new PersonInfo();
p.type = input.next();
p.name = input.next();
p.gender = input.next();
p.age = input.nextInt();
list.add(p);
}
}
public void list(String occupation){
String typeString ="";
if (occupation.equals("s")){
typeString = "student";
}
if(occupation.equals("t")){
typeString = "teacher";
}
System.out.println("List of people");
System.out.printf("Type: %s
, typeString);
for (int i =0; i < list.size(); i++){
if (list.get(i).type.equals(typeString)){
System.out.println(list.get(i);name);
}
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Identify the universal properties of all languages.

Answered: 1 week ago