For this lab, you will implement your own version of the cat systems program, a
ID: 3600112 • Letter: F
Question
For this lab, you will implement your own version of the cat systems program, a standard Unix utility that reads files sequentially, writing them to standard output. The name is derived from its function to concatenate files. The Single Unix Specification defines the operation of cat to read files in the sequence given in its arguments, writing their contents to the standard output in the same sequence. If one of the input filenames is specified as a single hyphen (-), then cat reads from standard input at that point in the sequence. If no files are specified, cat reads from standard input only. The command-syntax is:
You are NOT allowed to use the exec, system, popen, and pclose system calls or functions in your implementation. You are not allowed to call the existing cat implementation. You must supply your own implementation that uses low-level I/O. Low-level file I/O (APUE Ch. 3) is a requirement for this breakout lab.
Some Nonfunctional Requirements:
Libraries: You are allowed to use any of the C or C++ standard libraries. When reading or writing to a file are concerned, you need to use low-level calls to read(2) and write(2) and related functions. You are NOT allowed to use the following system calls in any of your implementations: fork(2), execve(2), exec(3), popen(3), and system(3) (or related functions).
Unbuffered Output: Whenever possible, program output should be unbuffered. The best way to guarantee that output is unbuffered (i.e., characters at the destination as soon as possible) is to directly call write(2). If you are using printf(3), you should disable output buffering using setvbuf(3). If you are using C++ output streams (e.g., cout), then you should disable output buffering using setf and unitbuf .
Explanation / Answer
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class CarDataNode {
private long serialVersionUID;
private String licensePlateNumber;
private Date checkIn;
private Date checkOut;
public CarDataNode(String cdn){
licensePlateNumber = cdn;
checkIn = new Date();
checkOut = new Date();
}
public String getLPN(){
return licensePlateNumber;
}
public CarDataNode getNext(){
CarDataNode cdn = new CarDataNode("");
return cdn;
}
public void checkIn(){
checkIn = new Date();
}
public void checkOut(){
checkOut = new Date();
}
public Date getCheckIn(){
return checkIn;
}
public Date getCheckOut(){
return checkOut;
}
public void addNodeAfter(CarDataNode addCar){
//iterate for loop through LinkedList
for(int i = 0; i < cdnList.size(); i++){
//check position of the given node by using equals
if(cdnList.get(i).equals(addCar)){
//create new Node and add it to list at
//next index
CarDataNode addCarNext = new CarDataNode("");
cdnList.add(i+1, addCarNext);}}}
public void removeNodeAfter(CarDataNode reCar){
//iterate through loop through linked list
for(int i = 0; i <cdnList.size(); i++){
//check position of node
if(cdnList.get(i).equals(reCar)){
cdnList.remove(i);
}}}
public boolean equals(CarDataNode eqCar){
if(this.licensePlateNumber.equals(eqCar.licensePlateNumber)){
return true;
}
else
return false;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.