Question

In: Computer Science

Design a set of classes that keeps track of demographic information about a set of people,...

Design a set of classes that keeps track of demographic information about a set of people, such as age, nationality, occupation, income, and so on. Design each class to focus on a particular aspect of data collection. Assume the input data is coming from a text file. Create a main driver class to instantiate several of the classes.

Solutions

Expert Solution

Place demographic.txt file in project structure with below details in it:

0001,George,26,NYC,US,123,Engineer,10000,FedEx,Dinklage,Christ
0022,John,22,IL,US,144,Sr. Engineer,15000,Macy's,Boston,Christ
0033,Ram,29,CH,US,567,Engineer,11000,Delloitte,Sharma,Hindu
0056,Bryan,20,NYC,US,67,Worker,8000,Shop,Page,Christ
0011,Thomas,45,MH,US,898,Doctor,30000,Central Hospital,Lewis,Christ

Driver class: Demographic.java

package com.demographic;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;

public class Demographic {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
      
       BufferedReader reader;
       try {
           reader = new BufferedReader(new FileReader("demographic.txt"));
           String line = reader.readLine();
           while(line!=null)
           {
               String[] str = line.split(",");
               Personal p = new Personal();
               Professional pr = new Professional();
               Social s = new Social();
               line = reader.readLine();
               p.setId(Integer.parseInt(str[0]));
               p.setName(str[1]);
               p.setAge(Integer.parseInt(str[2]));
               p.setAddress(str[3]);
               p.setNationality(str[4]);
               pr.setEmpid(Integer.parseInt(str[5]));
               pr.setOccupation(str[6]);
               pr.setIncome(Double.parseDouble(str[7]));
               pr.setOrg(str[8]);
               s.setFamily(str[9]);
               s.setReligon(str[10]);
              
               System.out.println("Demographic details for id "+p.getId()+" is registered!");  
           }
          
       }
       catch (FileNotFoundException e) {
           // TODO Auto-generated catch block
           System.out.println("file not found");
           e.printStackTrace();
       }
       catch (Exception e) {
           // TODO Auto-generated catch block
           System.out.println("Other exception");
           e.printStackTrace();
       }

      
   }

}

Personal.java

package com.demographic;

public class Personal {
private int id;
private String name;
private int age;
private String address;
private String nationality;

public int getId() {
   return id;
}
public void setId(int id) {
   this.id = id;
}
public String getName() {
   return name;
}
public void setName(String name) {
   this.name = name;
}
public int getAge() {
   return age;
}
public void setAge(int age) {
   this.age = age;
}
public String getAddress() {
   return address;
}
public void setAddress(String address) {
   this.address = address;
}
public String getNationality() {
   return nationality;
}
public void setNationality(String nationality) {
   this.nationality = nationality;
}


}

Professional.java

package com.demographic;

public class Professional {
   private int id;
   private int empid;
   private String occupation;
   private double income;
   private String org;
   public int getId() {
       return id;
   }
   public void setId(int id) {
       this.id = id;
   }
   public int getEmpid() {
       return empid;
   }
   public void setEmpid(int empid) {
       this.empid = empid;
   }
   public String getOccupation() {
       return occupation;
   }
   public void setOccupation(String occupation) {
       this.occupation = occupation;
   }
   public double getIncome() {
       return income;
   }
   public void setIncome(double income) {
       this.income = income;
   }
   public String getOrg() {
       return org;
   }
   public void setOrg(String org) {
       this.org = org;
   }
  
  
}

Social.java

package com.demographic;

public class Social {
   private int id;
   private String family;
   private String religon;
   public int getId() {
       return id;
   }
   public void setId(int id) {
       this.id = id;
   }
   public String getFamily() {
       return family;
   }
   public void setFamily(String family) {
       this.family = family;
   }
   public String getReligon() {
       return religon;
   }
   public void setReligon(String religon) {
       this.religon = religon;
   }


  
}

Output:

Demographic details for id 1 is registered!
Demographic details for id 22 is registered!
Demographic details for id 33 is registered!
Demographic details for id 56 is registered!
Demographic details for id 11 is registered!


Related Solutions

Create a program that keeps track of the following information input by the user: First Name,...
Create a program that keeps track of the following information input by the user: First Name, Last Name, Phone Number, Age Now - let's store this in a multidimensional array that will hold 10 of these contacts. So our multidimensional array will need to be 10 rows and 4 columns. You should be able to add, display and remove contacts in the array. In Java
Code an application program that keeps track of student information at your college: names, identification numbers,...
Code an application program that keeps track of student information at your college: names, identification numbers, and grade point averages in a fully encapsulated (homogeneous) Sorted array-based data structure. When launched, the user will be asked to input the maximum size of the data set, the initial number of students, and the initial data set. Once this is complete, the user will be presented with the following menu: Enter: 1 to insert a new student’s information. 2 to fetch and...
Code an application program that keeps track of student information at your college: names, identification numbers,...
Code an application program that keeps track of student information at your college: names, identification numbers, and grade point averages in a fully e ncapsulated (homogeneous) Sorted array- based data structure. When launched, the user will be asked to input the maximum size of the data set, the initial number of students, and the initial data set. Once this is complete, the user will be presented with the following menu: Enter: 1 to insert a new student's information, 2 to...
For this assignment you will design a set of classes that work together to simulate a...
For this assignment you will design a set of classes that work together to simulate a police officer issuing a parking ticket. You should design the following classes: - The ParkedCar Class: This class should simulate a parked car. The class's responsibilities are as follows: - To know the car's make, model, color, license number, and the number of minutes that the car has been parked. - The ParkingMeter Class: This class should simulate a parking meter. The class's only...
Using C++. For this assignment you will design a set of classes that work together to...
Using C++. For this assignment you will design a set of classes that work together to simulate a police officer issuing a parking ticket. The classes you should design are : The ParkedCar class: This class should simulate a parked car. The class's responsibilities are: -to know the car's make, model,color ,license number,and the number of minutes that the car has been parked The ParkingMeter Class: This class should simulate a parking meter. the class's only responsibility is: -To know...
Design a simple database to track people and who they voted for. The database should have...
Design a simple database to track people and who they voted for. The database should have 3 tables: A table of candidates A table of registered voters A table of votes The candidate table should provide a listing of all candidates and information about the candidates. The registered voter table should hold all registered voters and any pertinent information about them The vote table should hold vote records for each candidate made by the voters Requirements: The system should not...
Parking Ticket simulator For this assignment you will design a set of classes that work together...
Parking Ticket simulator For this assignment you will design a set of classes that work together to simulate a police officer issuing a parking ticket. You should design the following classes: • The ParkedCar Class: This class should simulate a parked car. The class’s responsibili-ties are as follows: – To know the car’s make, model, color, license number, and the number of minutes that the car has been parked. • The ParkingMeter Class: This class should simulate a parking meter....
Design a set of classes that work together to simulate a police officer issuing a parking...
Design a set of classes that work together to simulate a police officer issuing a parking ticket. You should design the following classes: The ParkedCar Class: this class should simulate a parked car. The classes' responsibilities are as the following: -to know the make, the model, license number and the number of minutes that the car has been parked. The parkingMeter Class: this class should simulate a parking meter. The class's only responsibility is as follows: -to know the number...
2 – The CPU design team is designing an instruction set with three classes of instructions....
2 – The CPU design team is designing an instruction set with three classes of instructions. Parameters are given in the following table. Consider a program with 65% ALU instructions, 20% memory access instructions, and 15% control instructions. What is the average CPI for this CPU? Clock Rate: 4GHz CPI for ALU Inst.: 4 CPI for Memory Inst.: 8 CPI for Control Inst.: 2
parking Ticket simulator For this assignment you will design a set of classes that work together...
parking Ticket simulator For this assignment you will design a set of classes that work together to simulate a police officer issuing a parking ticket. You should design the following classes: • The ParkedCar Class: This class should simulate a parked car. The class’s responsibili-ties are as follows: – To know the car’s make, model, color, license number, and the number of minutes that the car has been parked. • The ParkingMeter Class: This class should simulate a parking meter....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT