Introduction: In this project you will create a generic linked list using Java Generics. Description: Create a generic class called GenLinkedList. GenLinkedList will use nodes that store a value of the generic type to store its contents. It should have the following methods. The methods should all operate on the object making the call (none are static). Perform checking of the parameters and throw exceptions where appropriate. The linked list should be singly-linked. It should not use sentinel nodes (empty header and tail nodes). You should strive for an efficient implementation of each method. 7 points each (a-h) a. addFront receives an item to add as a parameter, and adds to the front of the list. b. addEnd receives an item to add as a parameter, and adds to the end of the list. c. removeFront removes a node from the front of the list. d. removeEnd removes a node from the end of the list. e. set receives a position and item as parameters, sets the element at this position, provided it is within the current size f. get receives a position as a parameter, returns the item at this position, provided it is within the current size g. swap receives two index positions as parameters, and swaps the nodes at these positions, provided both positions are within the current size h. shift receives an integer as a parameter, and shifts the list forward or backward this number of nodes, provided it is within the current size 11 points each (i-l) i. removeMatching receives a value of the generic type as a parameter and removes all occurrences of this value from the list. j. erase receives an index position and number of elements as parameters, and removes elements beginning at the index position for the number of elements specified, provided the index position is within the size and together with the number of elements does not exceed the size k. insertList receives a generic List (a Java List) and an index position as parameters, and copies each value of the passed list into the current list starting at the index position, provided the index position does not exceed the size. For example, if list has a,b,c and another list having 1,2,3 is inserted at position 2, the list becomes a,b,1,2,3,c l. main add code to the main method to demonstrate each of your methods Submit to eLearning: GenLinkedList.java
In: Computer Science
Write a program that will calculate the cost of installing fiber optic cable at a cost of .87 per ft for a company. Your program should display the company name and the total cost.
In: Computer Science
In no more than half a page, explain and discuss the phase transition phenomenon in random Random 3-SAT. Note: This requires some research. Marks will depend on the quality of presentation, and the depth and breadth of the explanation?
In: Computer Science
You are going to set up a small shopping system, where you are going to implement a "shopping bag" subject to the following specifications:
Make sure your code is well documented. Use the methods that are available in the Bag class.
Source code for Assignment #
/** An interface that describes the operations of a bag of objects. @author Frank M. Carrano @author Timothy M. Henry @version 4.1 */ public interface BagInterface<T> { /** Gets the current number of entries in this bag. @return The integer number of entries currently in the bag. */ public int getCurrentSize(); /** Sees whether this bag is empty. @return True if the bag is empty, or false if not. */ public boolean isEmpty(); /** Adds a new entry to this bag. @param newEntry The object to be added as a new entry. @return True if the addition is successful, or false if not. */ public boolean add(T newEntry); /** Removes one unspecified entry from this bag, if possible. @return Either the removed entry, if the removal. was successful, or null. */ public T remove(); /** Removes one occurrence of a given entry from this bag. @param anEntry The entry to be removed. @return True if the removal was successful, or false if not. */ public boolean remove(T anEntry); /** Removes all entries from this bag. */ public void clear(); /** Counts the number of times a given entry appears in this bag. @param anEntry The entry to be counted. @return The number of times anEntry appears in the bag. */ public int getFrequencyOf(T anEntry); /** Tests whether this bag contains a given entry. @param anEntry The entry to locate. @return True if the bag contains anEntry, or false if not. */ public boolean contains(T anEntry); /** Retrieves all entries that are in this bag. @return A newly allocated array of all the entries in the bag. Note: If the bag is empty, the returned array is empty. */ public T[] toArray(); // public <T> T[] toArray(); // Alternate // public Object[] toArray(); // Alternate /** Creates a new bag that combines the contents of this bag and anotherBag. @param anotherBag The bag that is to be added. @return A combined bag. */ // public BagInterface<T> union(BagInterface<T> anotherBag); /** Creates a new bag that contains those objects that occur in both this bag and anotherBag. @param anotherBag The bag that is to be compared. @return A combined bag. */ // public BagInterface<T> intersection(BagInterface<T> anotherBag); /** Creates a new bag of objects that would be left in this bag after removing those that also occur in anotherBag. @param anotherBag The bag that is to be removed. @return A combined bag. */ // public BagInterface<T> difference(BagInterface<T> anotherBag); } // end BagInterface Bag Class public final class LinkedBag<T> implements BagInterface<T> { private Node firstNode; // Reference to first node private int numberOfEntries; public LinkedBag() { firstNode = null; numberOfEntries = 0; } // end default constructor /** Sees whether this bag is empty. @return True if this bag is empty, or false if not. */ public boolean isEmpty() { return numberOfEntries == 0; } // end isEmpty /** Gets the number of entries currently in this bag. @return The integer number of entries currently in this bag. */ public int getCurrentSize() { return numberOfEntries; } // end getCurrentSize /** Adds a new entry to this bag. @param newEntry The object to be added as a new entry @return True if the addition is successful, or false if not. */ public boolean add(T newEntry) // OutOfMemoryError possible { // Add to beginning of chain: Node newNode = new Node(newEntry); newNode.next = firstNode; // Make new node reference rest of chain // (firstNode is null if chain is empty) firstNode = newNode; // New node is at beginning of chain numberOfEntries++; return true; } // end add /** Retrieves all entries that are in this bag. @return A newly allocated array of all the entries in this bag. */ public T[] toArray() { // The cast is safe because the new array contains null entries @SuppressWarnings("unchecked") T[] result = (T[])new Object[numberOfEntries]; // Unchecked cast int index = 0; Node currentNode = firstNode; while ((index < numberOfEntries) && (currentNode != null)) { result[index] = currentNode.data; index++; currentNode = currentNode.next; } // end while return result; } // end toArray /** Counts the number of times a given entry appears in this bag. @param anEntry The entry to be counted. @return The number of times anEntry appears in this bag. */ public int getFrequencyOf(T anEntry) { int frequency = 0; int counter = 0; Node currentNode = firstNode; while ((counter < numberOfEntries) && (currentNode != null)) { if (anEntry.equals(currentNode.data)) { frequency++; } // end if counter++; currentNode = currentNode.next; } // end while return frequency; } // end getFrequencyOf /** Tests whether this bag contains a given entry. @param anEntry The entry to locate. @return True if the bag contains anEntry, or false otherwise. */ public boolean contains(T anEntry) { boolean found = false; Node currentNode = firstNode; while (!found && (currentNode != null)) { if (anEntry.equals(currentNode.data)) found = true; else currentNode = currentNode.next; } // end while return found; } // end contains // Locates a given entry within this bag. // Returns a reference to the node containing the entry, if located, // or null otherwise. private Node getReferenceTo(T anEntry) { boolean found = false; Node currentNode = firstNode; while (!found && (currentNode != null)) { if (anEntry.equals(currentNode.data)) found = true; else currentNode = currentNode.next; } // end while return currentNode; } // end getReferenceTo /** Removes all entries from this bag. */ public void clear() { while (!isEmpty()) remove(); } // end clear /** Removes one unspecified entry from this bag, if possible. @return Either the removed entry, if the removal was successful, or null. */ public T remove() { T result = null; if (firstNode != null) { result = firstNode.data; firstNode = firstNode.next; // Remove first node from chain numberOfEntries--; } // end if return result; } // end remove /** Removes one occurrence of a given entry from this bag, if possible. @param anEntry The entry to be removed. @return True if the removal was successful, or false otherwise. */ public boolean remove(T anEntry) { boolean result = false; Node nodeN = getReferenceTo(anEntry); if (nodeN != null) { nodeN.data = firstNode.data; // Replace located entry with entry in first node firstNode = firstNode.next; // Remove first node numberOfEntries--; result = true; } // end if return result; } // end remove private class Node { private T data; // Entry in bag private Node next; // Link to next node private Node(T dataPortion) { this(dataPortion, null); } // end constructor private Node(T dataPortion, Node nextNode) { data = dataPortion; next = nextNode; } // end constructor } // end Node } // end LinkedBag
In: Computer Science
For the Exploitation tools, find the usage and the required counter measures to avoid effects of the following tools:
B). Safe tools, FACEBOOK DEMETRICATOR, TWITTER DEMETRICATOR, INSTAGRAM DEMETRICATOR, TEXTBOOK, GO RANDO, AND TRACING YOU, EXPLAIN ALL IN 500 WORDS.
In: Computer Science
JAVA
1. Create an Interface Vehicle. Declare one public void method in it paint( ).
2. Create a class Car. Implements Vehicle. It's paint() method prints "Car Painted". It's drive( ) method prints "Car Driven".
3. Create a class Bus. Implements Vehicle. It's paint() method prints "Bus Painted" . It's drive( ) method prints "Bus Driven".
4. Create a method AutoWork which accepts an object of type Vehicle. The method makes a call to the vehicle's paint( ) and drive() methods.
5. In the main method of your Main class, create a reference and object of Car class. Pass it to the AutoWork method.
6. In the main method of your Main class, create a reference and object of Bus class. Pass it to the AutoWork method.
------
7. In the main method of your Main class, create a reference v of Vehicle interface and object of Car class. Pass it to the AutoWork method. (You may have to remove/comment the call to the drive() method in AutoWork)
8. Using the same reference v, create object of Bus. Pass it to the AutoWork method. (Again you may have to remove/comment the call to the drive() method in AutoWork)
In: Computer Science
In C++
Create two functions called TheNumber. One version of TheNumber should accept a string and output the accepted string 10 times. The other version of TheNumber should accept a double and output the accepted double 10 times. This uses function overloading.
In: Computer Science
using c++. ALWAYS GRADE MY ANSWERS
nstructions
Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits.
For example, it should output the individual digits of:
#2
Instructions
Write a program that
prompts the user to input a sequence of characters and outputs the
number of vowels.
(Use the function isVowel written in Programming Exercise
2.)
Your output should look like the following:
There are # vowels in this sentence.
... where # is the number of vowels.
#3
Instructions
You are given a file consisting of students’ names in the following form: lastName, firstName middleName. (Note that a student may not have a middle name.)
Write a program that converts each name to the following form: firstName middleName lastName. Your program must read each student’s entire name in a variable and must consist of a function that takes as input a string, consists of a student’s name, and returns the string consisting of the altered name. Use the string function find to find the index of ,; the function length to find the length of the string; and the function substr to extract the firstName, middleName, and lastName
here is the file:
Miller, Jason
Brian
Blair, Lisa Maria
Gupta, Anil Kumar
Arora, Sumit Sahil
Saleh, Rhonda Beth
Spilner, Brody
In: Computer Science
JAVA
Write a class to implement a list with the ability to insert a new item at any location within the list, remove an item, and search for an item. The list should use a linked list implementation. This implementation should make use of a dummy node at the head of the list and should have explict references head and previous. Add a method to the list that inserts elements in acsending order assuming the list is already sorted before each insert.
In: Computer Science
In: Computer Science
A sequential file contains at most four billion 32-bit integers in random order, we need to find a 32-bit integer that isn’t in the file. Note that certainly we can simply read them all into memory (if we have enough memory) and sort them. That would cost O(n log n) for sorting and O(n) for searching. Think if we do better than that WITHOUT sorting and answer the following questions with better solutions.
(a) Explain why there must be at least one such integer missing?
(b) If you have some memory that is enough to hold one bit for each such integer, i.e., with such bitmap approach, how would you solve the problem?
(c) If you only have a few hundred bytes of main memory but you could use several external files, how would you solve it? (hint: use binary search)
In: Computer Science
Abstraction is a key part of object-oriented programming and the concepts apply particularly well to classes. How would the same concepts apply to data structures and how we tend to define and think of ADTs?
In: Computer Science
Using the Java programming language: Create and implement a class Car that models a car. A Car is invented to have a gasoline tank that can hold a constant max of 12.5 gallons, and an odometer that is set to 0 for a new car. All cars have an original fuel economy of 23.4 miles per gallon, but the value is not constant.
Provide methods for constructing an instance of a Car (one should be zero parameter, and the other should take one parameter, namely a value for the fuel efficiency). Additional method simulates the car traveling a given number of miles (at the end of traveling that user-specified distance, the odometer is updated and the gas tank level is reduced by an elementary calculation using the miles driven and fuel efficiency), to fill a given number of gallons to the tank, to get the odometer reading, and to get the gas tank level in gallons. (Test case that makes sure the tank isn’t already at capacity)
In: Computer Science
CS 400 Assignment 2: applying ArrayList In this assignment, you are going to build a program that can help rental car companies to manage their rental fleet. Requirement: - build ArrayList class as container. - build Car class/structure to represent car objects. - An ArrayList object is to hold Car objects. Car class should have following fields: - id (int) - make (string) - model (string) - color (string) Instructions: - make up 15 cars and save them into a file: cars.data - load these cars' info from the file, initialize 15 Car objects, place them into the Arraylist - if new cars are added by user, they should be appended to the cars.data file when exiting the program - design a menu based user interface that allows following operations: -- search by id -- search by make -- search by model -- search by color -- add a new car (new car id cannot be same as existing ones) -- delete an existing car by id -- list all cars -- exit the program Grading: - compilable and meaningful attemps: 30 points. - functionality: 60 points (ArrayList 10p, Car 10p, file io 10p, menu functions 30p) - comments and indentation: 10 points. Submission: - submit related .h files, .cpp files and cars.data via blackboard. Do not forget to submit cars.data!
In: Computer Science
In: Computer Science