Question

1) Write a Java program that creates a double linked list called Log that keeps track...

1) Write a Java program that creates a double linked list called Log that keeps track of server access:

Date and time

File accessed

Number of hits

2) Write a method that inserts a new element in the list at the end of the list

3) Write a method that return the page that has been access the most (highest number of hits)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*

Program written in netbean 8.0 along with jdk 1.8 on windows operating system

*/

package printerjob;

import java.util.Scanner;

public class DLL {
    Node head; // head of doubly list

    /* Doubly Linked list Node*/
    class Node {
        String datetime;
        String fileaccess;
        int hits;
        Node prev;
        Node next;

       // constrctor
        Node(String datetime,String fileaccess,int hits) {
            this.datetime = datetime;
            this.fileaccess=fileaccess;
            this.hits=hits;
        }
    }

    // Add node at the end of list
    void insertatend(String datetime,String fileaccess,int hits)
    {
        //create node
        Node new_node = new Node(datetime,fileaccess,hits);

        Node last = head;
        new_node.next = null;
        // if lisst is empty
        if (head == null) {
            new_node.prev = null;
            head = new_node;// new node become head
            return;
        }
       // travel till end of list
        while (last.next != null)
            last = last.next;
        // append node and change next and prev
        last.next = new_node;
        new_node.prev = last;
    }

    // get max hits node
    public void FindMaxHitsRecord(Node node)
    {
        Node last = null;
        Node maximum = new Node(null,null,-1);
        while (node != null) {
            if(maximum.hits<node.hits){
             maximum=node;
            }
            last = node;
            node = node.next;
        }
        System.out.println("Record with maximum record is ::::");
        System.out.println("Date Time:"+maximum.datetime);
        System.out.println("File Name:"+maximum.fileaccess);
        System.out.println("Hits :"+maximum.hits);
      
    }

    /* Drier program to test above functions*/
    public static void main(String[] args)
    {
        /* Start with the empty list */
        DLL dll = new DLL();
        Scanner scanner=new Scanner(System.in);
        System.out.println("Enter Number of node for doubly linked list");
        int n=scanner.nextInt();
        for (int i = 0; i < n; i++) {
            System.out.println("Enter DateTime in (DD/MM/YY-hh:mm:ss pattern), access file name and hits");
            String tempdatetime=scanner.next();
            String tempfilename=scanner.next();
            int temphits=scanner.nextInt();
             dll.insertatend(tempdatetime,tempfilename,temphits);
        }
       // function find maximum hit record
        dll.FindMaxHitsRecord(dll.head);
    }
}
/*

run:
Enter Number of node for doubly linked list
2
Enter DateTime in (DD/MM/YY-hh:mm:ss pattern), access file name and hits
5/5/19-05:04:85 abc.txt 85
Enter DateTime in (DD/MM/YY-hh:mm:ss pattern), access file name and hits
6/6/18-07:47:41 data.dat 74
Record with maximum record is ::::
Date Time:5/5/19-05:04:85
File Name:abc.txt
Hits :85
BUILD SUCCESSFUL (total time: 1 minute 10 seconds)

*/

Add a comment
Know the answer?
Add Answer to:
1) Write a Java program that creates a double linked list called Log that keeps track...
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
  • in java eclipse, Create a program “FibonacciFifteen.java” and a method called “double[] getFibonacci()” that creates an...

    in java eclipse, Create a program “FibonacciFifteen.java” and a method called “double[] getFibonacci()” that creates an array with a length of 15 that contains the first 15 numbers in the Fibonacci sequence and returns it. Set the first element to 0 and the second element to 1, then use a for loop to fill out the rest of the array by adding the prior two elements.

  • Write a Java program called EqualSubsets that reads a text file, in.txt, that contains a list...

    Write a Java program called EqualSubsets that reads a text file, in.txt, that contains a list of positive and negative integers (duplicates are possible) separated by spaces and/or line breaks. Zero may be included. After reading the integers, the program saves them in a singly linked list in the same order in which they appear in the input file. Then, without changing the linked list, the program should print whether there exists two subsets of the list whose sums are...

  • Assume you are to write a ledger program that keeps track of each bank transaction as...

    Assume you are to write a ledger program that keeps track of each bank transaction as a struct containing the transaction type (deposit or withdrawal), the transaction amount (double), and the balance after the transaction. Would you use an array or a linked list? Why? (in C++)

  • public static double[] getVolumes(double[] base, double[] height, double[] length) Write a Java program called TriangularPrisms which...

    public static double[] getVolumes(double[] base, double[] height, double[] length) Write a Java program called TriangularPrisms which does the following: In the main method: Use a for loop which repeats three times. Within the loop, a. prompt the user to enter the base of the triangular prism and store the value in a double array called base b. prompt the user to enter the corresponding height and store the value in a double array called height c. prompt the user to...

  • Write a java program that create a 2 dimensional array of type double of size 10...

    Write a java program that create a 2 dimensional array of type double of size 10 by 10. Fill the array with random numbers using a random number generator. Print the array contents. Write a java program that creates a file called data.txt that uses the PrintWriter class. Write the numbers 1 to 42 into the file. Close the file. Attach both files. Thank you in advance

  • Write a java program that creates a file called numbers.txt that uses the PrintWriter class. Write...

    Write a java program that creates a file called numbers.txt that uses the PrintWriter class. Write the odd numbers 1 to 99 into the file. Close the file. Using Scanner, open the numbers.txt file and read in the numbers. Add them all up and print the total. Close the file.

  • Write a Java program that does the following: 1. Creates a string array called firstNames that...

    Write a Java program that does the following: 1. Creates a string array called firstNames that holds these values "John", "Frank", "Nick", "Amanda", "Brittany", "Amy", "Deborah", and "Stirling". 2. Creates another string array called lastNames that holds these values "Thompson", "Smith", "Jones", "Keribarian", "Lu", "Banafsheh", "Spielberg", "Jordan", "Castle" and "Simpson". 3. Now add a method that creates an array list called randomNames which picks a random first name from the array in step 1 and a random last name in...

  • In Java please, These are instance methods which modify the linked list ,* accessed through the...

    In Java please, These are instance methods which modify the linked list ,* accessed through the instance variable: first * Note that this list keeps track of the number of elements in the instance varible N * It is important that N accurately reflect the length of the list. * You may not add any fields to the node or list classes. * You may not add any methods to the node class. static class Node ; } public Node...

  • Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and...

    Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: o Write a method called cubeIt that accepts one integer parameter and returns the value raised to the third power as an integer. 2. Write a method called randomInRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. o Write a method called larger that accepts two double parameters and...

  • Java programming: Write a program called Distribution that reads a file of double values into an...

    Java programming: Write a program called Distribution that reads a file of double values into an array and computes and prints the percentage of those numbers within 1 standard deviation (SD), within 2 SDs, and within 3 SDs of the mean. The program should be modular and should at least contain the main method and a method for computing the above percentages given the numbers, the mean, and the standard deviation. Other required statistics should be computed in their own...

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