Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Description: You will be developing a phone record analysis program as described

ID: 3603793 • Letter: D

Question

Description: You will be developing a phone record analysis program as described below.

Your program reads phone call information from a text file name “phoneCalls.txt”. (the info from the text file can be found at the end). Each record in the file has the following format 480-678-1234/10/10-08-2017/Josh William/2.45 (Destination number/ Duration Call/ Date/ Callee Name/ Cost). Program reads record at a time from the file and generates an array list of phone call objects. The phone call object has the destination phone number, duration, call date, callee name (person who called by the caller), and the cost of the call. You can add required methods phone call object based on your design.

Once the object is created, it will be placed in an array list called phone calls. Then, your program can perform following operations

A) Search a call based on the destination number

B) Display the longest call information

C) Display the shortest call information

D) Sort the phone calls array list based on the call duration and display calls in the sorted order (display the destination phone number and the duration)

E) Prepare a phone bill and store the phone bill in the “phone bill.txt” file. Format of the “phone_bills.txt” is given below.

F) Exit the program

Text File format-----------

phone_bills.txt

Destination Number Duration (m) Cost ($)

480-678-1234 10 2.50

602-578-1000 12 3.15 . . .

Total: $

textFile information---------------------------------------------

Explanation / Answer

package deepak;

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

public class PhoneRecord {

public record Add(record head,String dstNum,int durCall,String date,String calName,double cost)

{

if(head == null)

{

head = new record(dstNum, durCall, date, calName, cost, null);

}

else

{

record temp = head;

while(temp.next != null)

{

temp = temp.next;

}

temp.next = new record(dstNum, durCall, date, calName, cost, null);

}

return head;

}

// Part A

public void SearchCallBasedonDestination(record head,String dst)

{

int flag = 0;

record temp = head;

while(temp != null)

{

if(temp.dstNum.equals(dst))

{

System.out.println("Call details: "+temp.dstNum+"/"+temp.durCall+"/"+temp.date+"/"+temp.calName+"/"+temp.cost);

flag = 1;

}

temp = temp.next;

}

if(flag ==0)

{

System.out.println("No calls with destination: "+dst);

}

}

// Part B

public void DisplayLongestCall(record head)

{

record temp = head;

int max = 0;

record maxRecord = head;

while(temp != null)

{

if(temp.durCall > max)

{

max = temp.durCall;

maxRecord = temp;

}

temp = temp.next;

}

System.out.println("Call details with longest: "+maxRecord.dstNum+"/"+maxRecord.durCall+"/"+maxRecord.date+"/"+maxRecord.calName+"/"+maxRecord.cost);

}

// PartC

public void DisplayShortestCall(record head)

{

record temp = head;

int min = Integer.MAX_VALUE;

record minRecord = head;

while(temp != null)

{

if(temp.durCall < min)

{

min = temp.durCall;

minRecord = temp;

}

temp = temp.next;

}

System.out.println("Call details with shortest: "+minRecord.dstNum+"/"+minRecord.durCall+"/"+minRecord.date+"/"+minRecord.calName+"/"+minRecord.cost);

}

// Part D

public void sortAndDisplay(record head)

{

record temp1 = head;

record temp2 = head;

while(temp1 != null)

{

int minDur = temp1.durCall;

temp2 = temp1.next;

while(temp2 != null)

{

if(temp2.durCall < minDur)

{

String dstNum = temp2.dstNum;

int durCall = temp2.durCall;

String date = temp2.date;

String calName = temp2.calName;

double cost = temp2.cost;

temp2.dstNum = temp1.dstNum;

temp2.durCall = temp1.durCall;

temp2.date = temp1.date;

temp2.calName = temp1.calName;

temp2.cost = temp1.cost;

temp1.dstNum = dstNum;

temp1.durCall = durCall;

temp1.date = date;

temp1.calName = calName;

temp1.cost = cost;

minDur = temp2.durCall;

}

temp2 = temp2.next;

}

temp1 = temp1.next;

}

temp1 = head;

while(temp1 != null)

{

System.out.println("Call details: "+temp1.dstNum+"/"+temp1.durCall+"/"+temp1.date+"/"+temp1.calName+"/"+temp1.cost);

temp1 = temp1.next;

}

}

public static void main(String[] args) throws IOException {

// TODO Auto-generated method stub

PhoneRecord obj = new PhoneRecord();

BufferedReader br = new BufferedReader(new FileReader("C:\Users\Deepak\Desktop\data.txt"));

String line;

record head = null;

while((line = br.readLine()) != null)

{

String [] splits = line.split("/");

head = obj.Add(head,splits[0],Integer.parseInt(splits[1]), splits[2], splits[3], Double.parseDouble(splits[4]));

}

br.close();

//Part A

System.out.println("Part A");

obj.SearchCallBasedonDestination(head, "480-378-1235");

// Part B

System.out.println("Part B");

obj.DisplayLongestCall(head);

// Part C

System.out.println("Part C");

obj.DisplayShortestCall(head);

// Part D

System.out.println("Part D");

obj.sortAndDisplay(head);

}

}

class record

{

String dstNum;

int durCall;

String date;

String calName;

double cost;

record next;

public record(String dstNum,int durCall,String date,String calName,double cost,record next)

{

this.dstNum = dstNum;

this.durCall = durCall;

this.date = date;

this.calName = calName;

this.cost = cost;

this.next = next;

}

}