1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Alinara [238K]
3 years ago
7

Hey, I am in need of urgent help! My teacher is REALLY bad at his job (no exaggeration) and if I dont get a 100 on this lab, I w

ill fail the class. Please help me, thank you!!!
This link contains the instructions and classes needed for the lab:
https://www.dropbox.com/sh/469usrw1vctot52/AAARAgfqC63k3OPksAkvdRsGa?dl=0

Please put the code in the Circular List Class, the rest is already done, thanks!
Computers and Technology
1 answer:
anygoal [31]3 years ago
7 0

Answer:

public class CircularList

{

  private ListNode head; // front of the LinkedList

  private ListNode tail; // last node of the LinkedList

  private int size; // size of the LinkedList

   

  // constructs a new CircularList

  public CircularList()

  {

    head = tail = null;

    size = 0;

  }

   

  // returns the size of the array

  public int size()

  {

     return size;

  }

   

  // returns whether the list is empty

  public boolean isEmpty()

  {

     return (size == 0);

  }

   

  // returns the value of the first node

  public Integer first()

  {

     if (head != null) {

       return head.getValue();

     }

     return -1;

  }

   

  // returns the value of the last node

  public Integer last()

  {

     if (tail != null) {

       return tail.getValue();

     }

     return -1;

  }

  // adds a node to the front of the list

  public void addFirst(Integer value)

  {

    head = new ListNode(value, head);

    if (tail == null) {

      tail = head;

    }

    size++;

  }

   

  // adds a node to the end of the list

  public void addLast(Integer value)

  {

    ListNode newTail = new ListNode(value, null);

    if (tail != null) {

      tail.setNext(newTail);

      tail = newTail;

    } else {

      head = tail = newTail;

    }

     

    size++;

  }

   

  // adds a node at the position pos  

  public void addAtPos(int pos, Integer value)

  {

     if (pos == 0) { // Add at the start

       addFirst(value);

       return;

     }

     if (pos <= 0 || pos > size) { // Ignore attempts to add beyond the ends

       return;

     }

     if (pos == size) { // Special case, tail has to be adjusted

       addLast(value);

       return;

     }

     // size and pos are guaranteed both non-zero

     ListNode ptr = head; // ptr is the node before the new one

     for(int i=0; i<pos-1; i++) {

       ptr = ptr.getNext();

     }

     ListNode newNode = new ListNode(value, ptr.getNext());

     ptr.setNext(newNode);

     size++;

  }

   

  // removes the first node and returns the value of the removed node or -1 if the list is empty

  public Integer removeFirst()

  {

     Integer retVal = -1;

     if (head != null) {

       retVal = head.getValue();

       head = head.getNext();

       size--;

     }

     if (size == 0) {

       head = tail = null;

     }

     return retVal;

  }

   

  // removes the node at position pos and returns the value of the removed node or -1 if pos is not a valid position

  public Integer removeNode(int pos)

  {

     Integer retVal = -1;

     if (head == null || pos < 0 || pos >= size) {

       return retVal;

     }

     if (pos == 0) {

       return removeFirst();

     }

     ListNode ptr = head; // ptr is the node before the deleted

     for(int i=0; i<pos-1; i++) {

       ptr = ptr.getNext();

     }

     retVal = ptr.getNext().getValue();

     if (pos == size-1) { // Is it the last element?      

       tail = ptr;

       tail.setNext(null);

     } else {

       ptr.setNext(ptr.getNext().getNext());

     }

     

     size--;

     return retVal;

  }  

   

  // finds and returns the position of find, or -1 if not found

  public int findNode(Integer find)

  {

     ListNode ptr = head;

     for(int pos=0; pos<size; pos++) {

       if (ptr.getValue() == find) {

         return pos;

       }

       ptr = ptr.getNext();

     }

     return -1;

  }  

   

  // rotates the list by placing the first element at the end

  public void rotate()

  {

     addLast(removeFirst());

  }

   

  // returns the list of values in the LinkedList

  public String toString()

  {

     String output = "";

     ListNode iter = head;

     while(iter != null) {

       output += String.format("%d ", iter.getValue());

       iter = iter.getNext();

     }

     return output;

  }

         

}

Explanation:

Enjoy. Linked list are always more complex than you expect. It is a good exercise to try once, then start using libraries. Life is too short to debug linked lists!

You might be interested in
What is working with others to find a mutually agreeable outcome?
Arturiano [62]

Answer:

its B. negotiation

Explanation:

1. I got it right on the exam :)

2. negotiation resolves in problem solving. you work together with others to solve problems, together which is negotiating/ talking things through to figure out an answer/ outcome.

Hope this helps! :))

Have an awesome day!!

3 0
3 years ago
Having a good credit score is important because:
Lisa [10]
It would be better if we could see the options, fully. But from what I can see, it should be B.
7 0
4 years ago
Describe how you would create a Java program that prompted the user to correctly enter a username and password. The username is
schepotkina [342]

Answer:

Explanation:

The program in question would create a new Scanner Object which asks the user for the Username first. It would then save this input into a temporary variable and compare it to the actual username in the database. Since the username is not case sensitive, we would use the toLowerCase() method on both the input and the database username so that they match even if the letters are not the same case structure. If both usernames match then we would move on to ask the user for the Password and compare it with the database password for that user. Since this one is case sensitive we would compare as is. Finally, if both Username and Password match we would print "Hello World" otherwise we would print "Login Failed."

3 0
3 years ago
Complete the following:_____
alexira [117]

Answer:

The answer to the give question as follows:

1) \n

2) \t

3) \'

4) \"

5) \\

Explanation:

The description of the above symbols as follows:

  • The \n is used to provide the new line spacing.
  • The \t is used to provide a tab space.
  • To assign a single character value we use \' single.
  • The double \" quote is used to assign a string value.
  • The backslash is used to provide the character of the escape and it also used in a file path.
7 0
3 years ago
(1) Prompt the user to enter a string of their choosing. Output the string.
barxatty [35]

Answer:

See solution below

See comments for explanations

Explanation:

import java.util.*;

class Main {

 public static void main(String[] args) {

   //PrompT the User to enter a String

   System.out.println("Enter a sentence or phrase: ");

   //Receiving the string entered with the Scanner Object

   Scanner input = new Scanner (System.in);

   String string_input = input.nextLine();

   //Print out string entered by user

   System.out.println("You entered: "+string_input);

   //Call the first method (GetNumOfCharacters)

   System.out.println("Number of characters: "+ GetNumOfCharacters(string_input));

   //Call the second method (OutputWithoutWhitespace)

   System.out.println("String with no whitespace: "+OutputWithoutWhitespace(string_input));

   }

 //Create the method GetNumOfCharacters

   public static int GetNumOfCharacters (String word) {

   //Variable to hold number of characters

   int noOfCharactersCount = 0;

   //Use a for loop to iterate the entire string

   for(int i = 0; i< word.length(); i++){

     //Increase th number of characters each time

     noOfCharactersCount++;

   }

   return noOfCharactersCount;

 }

 //Creating the OutputWithoutWhitespace() method

 //This method will remove all tabs and spaces from the original string

 public static String OutputWithoutWhitespace(String word){

   //Use the replaceAll all method of strings to replace all whitespaces

   String stringWithoutWhiteSpace = word.replaceAll(" ","");

   return stringWithoutWhiteSpace;

 }

}

6 0
3 years ago
Other questions:
  • Only business writing requires an editing stage
    8·1 answer
  • Explain the term remote backup with examples.​
    5·1 answer
  • There are several factors that can substantially affect the consumer search process. Match the factor with an example of how the
    5·1 answer
  • Richard needs to copy information from another slide presentation that uses a different design template. To ensure that the info
    7·1 answer
  • Write an if/else statement that compares the double variable pH with 7.0 and makes the following assignments to the bool variabl
    6·1 answer
  • Anyone down to play gta later i play on ps4?
    15·2 answers
  • Consider a disk that rotates at 3600 rpm. The seek time to move the head between adjacent tracks is 2 ms. There are 32 sectors p
    5·1 answer
  • Where can formatting features be found ?! Need help asp !‍♀️
    9·1 answer
  • What is the two’s compliment of -95,-122,-111,-57
    9·1 answer
  • Which type of relationship is responsible for teaching you values and how to communicate?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!