Question

Given the follawing tent,TALKSOW DAT um? ?,iLon ㆀ01 09/15/1974 nd te elowing Hot iava class anower she questions that follaw:

buffer.append( BIRTHDAY:birthday) return buffer.toString ) 1. Write a Java class HmWk14. Create the method readTalkshow(lis

Given the follawing tent,TALKSOW DAT um? ?,iLon ㆀ01 09/15/1974 nd te elowing Hot iava class anower she questions that follaw:
buffer.append(" BIRTHDAY:"birthday) return buffer.toString ) 1. Write a Java class HmWk14. Create the method readTalkshow(list) in the HmWk14 class that that reads the file TALKSHOW.DAT. Each line in the data file will be stored into a Host Java class object and added to a list of Host objects. Make a note that the date in the file needs to be converted to a Date object before setting the birthday field in the Host class. Once the file has been read and saved into a list of Host objects, create another method displayTalkshow(list) which iterates the list and display the information for each talk show host. Create the class HmWk14 in the Java package edu.calhoun.cis.java.intro.homework.homework14. 2. Create the method writeTalkshow() to the Hmwk 14 class in Question #1 that that writes the Host objects to a new data file TALKSHOW_NEW.DAT. The birthday must be written in the format MM/DD/YYYY. Before writing the hosts to the new file, add a new Host object to the list by creating the method addHost(List hosts, String lastName, String firstName, String hostNumber, String birthday) and passing it the following values: Last Name: Meyers First Name: Seth Host Number: 0008 Birthday: 12/28/1973 Show the output generated by executing this program and show the contents of the newly created TALKSHOW NEW.DAT
1 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

Host.java


import java.util.Date;


public class Host
{
private String firstName;
private String lastName;
private String hostNumber;
private Date birthDate;

public Host(String firstName, String LasrName, String showNumber, Date birthDate) {
this.firstName = firstName;
this.lastName = LasrName;
this.hostNumber = showNumber;
this.birthDate = birthDate;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLasrName() {
return lastName;
}

public void setLasrName(String LasrName) {
this.lastName = LasrName;
}

public String getHostNumber() {
return hostNumber;
}

public void setHostNumber(String showNumber) {
this.hostNumber = showNumber;
}

public Date getBirthDate() {
return birthDate;
}

public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}

@Override
public String toString() {
StringBuffer buffer =new StringBuffer();
buffer.append("LAST NAME: "+lastName);
buffer.append(" | FIRST NAME: "+firstName);
buffer.append(" | TICKET NUMBER: "+hostNumber);
buffer.append(" | BIRTHDATE "+birthDate);
return buffer.toString();
}
  
  
}

HmWk14.java


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;


public class HmWk14
{

public static void main(String[] args) throws ParseException
{
  
ArrayList<Host> list=new ArrayList<>();
readTalkShow(list);
displayTalkShow(list);
writeTaklShow(list);
  
}

private static void readTalkShow(ArrayList<Host> list) throws ParseException {
try
{
BufferedReader reader;
reader = new BufferedReader(new FileReader("TALKSHOW.dat"));
String line = reader.readLine();
while (line != null)
{
String []values=line.split(" ");
list.add(new Host(values[0], values[1], values[2], new SimpleDateFormat("dd/MM/yyyy").parse(values[3])));
line = reader.readLine();
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}

private static void displayTalkShow(ArrayList<Host> list) {
for(int i=0;i<list.size();i++)
{
System.out.println(list.get(i));
}
}

private static void writeTaklShow(ArrayList<Host> list)
{
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
  
try{
FileWriter fw=new FileWriter("TALKSHOW_NEW.dat");
for(int i=0;i<list.size();i++)
{
String strDate = formatter.format(list.get(i).getBirthDate());
fw.write("Last Name: "+list.get(i).getLasrName()+"\r\n");
fw.write("First Name: "+list.get(i).getFirstName()+"\r\n");
fw.write("Host Number: "+list.get(i).getHostNumber()+"\r\n");
fw.write("Birth Day: "+strDate+"\r\n\n");
}
fw.close();
}catch(Exception e){System.out.println(e);}
}
  
  
}

output

read from the dat file and make class NetBeans IDE 8.0.1 Search (Ctrl+1) File Edit View Navigate Source Refactor Ru Debug Pro

TALKSHOW_NEW.dat file

CAUsersuOSEE Documents NetBeansProject read from the dat file and make class TALKSHOW NEW.dat - Notepad++ File Edit Search Vi

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
Given the follawing tent,TALKSOW DAT um? ?,iLon ㆀ01 09/15/1974 nd te elowing Hot iava class anower she questions that follaw: buffer.append(" BIRTHDAY:"birthday) return buffer.toStrin...
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
  • Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters...

    Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters long encryptedPassword : String key int Must be between 1 and 10(inclusive) accountId - A unique integer that identifies each account nextIDNum – a static int that starts at 1000 and is used to generate the accountID no other instance variables needed. Default constructor – set all instance variables to a default value. Parameterized constructor Takes in clearPassword, key. Calls encrypt method to create...

  • Exercise 1: Adding a Test Harness to the Person class To make it easier to test...

    Exercise 1: Adding a Test Harness to the Person class To make it easier to test code that you have written for a Java class you can add to that class a main method that acts as a "test harness". A test harness is a main method that includes calls to methods that you wish to test. For convention this main method is the last method of the class. If you have a test harness, you do not need to...

  • Activity: Writing Classes Page 1 of 10 Terminology attribute / state behavior class method header class...

    Activity: Writing Classes Page 1 of 10 Terminology attribute / state behavior class method header class header instance variable UML class diagram encapsulation client visibility (or access) modifier accessor method mutator method calling method method declaration method invocation return statement parameters constructor Goals By the end of this activity you should be able to do the following: > Create a class with methods that accept parameters and return a value Understand the constructor and the toString method of a class...

  • Additional code needed: PartA: BurgerOrder class (1 point) Objective: Create a new class that represents an...

    Additional code needed: PartA: BurgerOrder class (1 point) Objective: Create a new class that represents an order at a fast-food burger joint. This class will be used in Part B, when we work with a list of orders. As vou work through this part and Part B, draw a UML diagram of each class in using the UML drawing tool 1) Create a new Lab5TestProject project in Netbeans, right-click on the lab5testproject package and select New>Java Class 2) Call your...

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