Hi there, I need help with this assignment. It is for my java programming class.
ID: 3602872 • Letter: H
Question
Hi there, I need help with this assignment. It is for my java programming class. I really don't know where to start. Below I posted all of the info that I have. Thank you in advance
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”. Each record in the file has the following format 480-678-1234/10/10-08-2017/Josh William/2.45
First string of numbers is the destination number, followed by the duration, call date, callee name, and 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
Destination Number 480-678-1234 602-578-1000
. . .
<similarly other records> Total: $
Duration (m) 10
12
Cost ($) 2.50 3.15
Explanation / Answer
class PhRecord{
public static void main(String args[]) {
private Scanner input;
ArrayList<Item> item = new ArrayList<Item>();
Scanner scanner = new Scanner(System. in);
String destNo = scanner. nextLine();
//Scanner in = new Scanner(System.in);
int max=0;
int min=0;
//open text file
public void openFile()
{
try
{
FileReader in = new FileReader("Items.txt");
input = new Scanner(in).useDelimiter("\s\s");
}
catch( FileNotFoundException fileNotFound)
{
System.err.println( "Error opening file.");
System.exit(1);
}
}
//read file
public void readFile()
{
try
{
while ( input.hasNextLine())
{
item.add( new Item(input.next(), input.nextInt(), input.nextInt(), input.next(), input.nextFloat() ));
}
for (Item list : item)
{
System.out.printf("%s %d %d %s %d ", list.getDestNo()+","+ list.getDura()+ ", "+ list.getCallDate()+ "," + list.getCalleeName()+","+list.getCost());
//System.out.println(item);
}
}
catch ( NoSuchElementException elementEx)
{
System.err.println( "Incorrect file format.");
System.exit(1);
}
catch ( IllegalStateException stateEx )
{
System.err.println( "Error reading from file.");
System.exit(1);
}
}
public void closeFile()
{
if (input != null)
input.close();
}
}
while(item.hasNext()){
Object someObject = item.next();
Field field;
for ( field : someObject.getClass().getDestNo()) {
Object value = field.get(someObject);
if (value == destNo) {
System.out.println(field.getCalleeName() + "=" + value);
}
}
for ( field : someObject.getClass().getDura()) {
Object value = field.get(someObject);
if (value<min) {
min=value;
}
else
if(value>max){
max=value;
}
}
System.out.println(min);
System.out.println(max);
for ( field : someObject.getClass().getDura()) {
field.sort();
//Object value = field.get(someObject);
}
System.out.println("%s %d",field.getDestNo()+","+field.getDura());
}
}
}// only first 4 parts are answered
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.