Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java. I have 3 Java Classes and 1 CSV file . CSV file: LastAndFirstName,DateOfBirth,Age Adams John,3/22/1976,45 years Anderson Tom,3/20/1981,40 years Harris Kathy,11/18/1982,39 years Johnson Mary,10/7/1976,45

Java.

I have 3 Java Classes and 1 CSV file.

CSV file:

LastAndFirstName,DateOfBirth,Age Adams John,3/22/1976,45 years Anderson Tom,3/20/1981,40 years Harris Kathy,11/18/1982,39 years Johnson Mary,10/7/1976,45 years Jones Bill,1/25/1953,68 years Kirby Frank,5/27/1978,43 years Larson Sara,4/29/1979,42 years Smith John,5/1/1962,59 years Smith Mark,9/11/1980,42 years Stewart Nancy,6/6/1984,37 years

Code:

public class People { private String LastAndFirstName; private String DateOfBirth; private String Age;

public People(String LastAndFirstName, String DateOfBirth, String Age) { this.LastAndFirstName = LastAndFirstName; this.DateOfBirth = DateOfBirth; this.Age = Age; }

@Override public String toString() { return "LastAndFirstName: " + LastAndFirstName + ", DateOfBirth: " + DateOfBirth + ", age: " + Age +" "; } }

------------------------------------

import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner;

public class workWithFile{ public static void main(String[] args) { try { Scanner input = new Scanner(new File("Data.csv")); dataBase MyData = new dataBase(); while (input.hasNext()) { String line = input.nextLine(); String dataParts[] = line.split(","); People info = new People(dataParts[0], dataParts[1], dataParts[2]); MyData.add(info); } System.out.println(MyData); } catch (FileNotFoundException e) { System.out.println("File wasn't found."); } } }

--------------------------------------

import java.util.ArrayList;

public class dataBase { private ArrayList db = new ArrayList<>();

public ArrayList getDb() { return db; }

public void setDb(ArrayList db) { this.db = db; }

public void add(People data) { db.add(data); }

@Override public String toString() { return (db.toString()); } }

My output has mistakes:

[LastAndFirstName: LastAndFirstName, DateOfBirth: DateOfBirth, age: Age , LastAndFirstName: Adams John, DateOfBirth: 3/22/1976, age: 45 years , LastAndFirstName: Anderson Tom, DateOfBirth: 3/20/1981, age: 40 years , LastAndFirstName: Harris Kathy, DateOfBirth: 11/18/1982, age: 39 years , LastAndFirstName: Johnson Mary, DateOfBirth: 10/7/1976, age: 45 years , LastAndFirstName: Jones Bill, DateOfBirth: 1/25/1953, age: 68 years , LastAndFirstName: Kirby Frank, DateOfBirth: 5/27/1978, age: 43 years , LastAndFirstName: Larson Sara, DateOfBirth: 4/29/1979, age: 42 years , LastAndFirstName: Smith John, DateOfBirth: 5/1/1962, age: 59 years , LastAndFirstName: Smith Mark, DateOfBirth: 9/11/1980, age: 42 years , LastAndFirstName: Stewart Nancy, DateOfBirth: 6/6/1984, age: 37 years ]

Please, make some changes to the dataBase file here:

@Override public String toString() { return (db.toString()); }

I need to remove brackets from my output and skip the first line from reading (LastAndFirstName: LastAndFirstName, DateOfBirth: DateOfBirth, age: Age).

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

What is the basic cost flow equation?

Answered: 1 week ago

Question

Write a paper about the statement Money cannot buy happiness

Answered: 1 week ago

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago