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
TALKSHOW_NEW.dat file
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.
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...
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 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 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 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...