(Java) Building a Doubly Linked List off of an interface I am
having trouble with these two methods
@Override
public void add(T newEntry) {
DoubleLinkedNode newNode = new DoubleLinkedNode(newEntry);
if (!isEmpty()) {
}
if (isEmpty()) {
first = newNode;
last = newNode;
} else {
last.setNextNode(newNode);
newNode.setPreviousNode(last);
last = newNode;
}
// length++;
numElements++;
}
@Override
public void add(int newPosition, T newEntry) {
DoubleLinkedNode newAdder = new DoubleLinkedNode(newEntry);
if ((newPosition >= 0) && (newPosition <= numElements)) {
numElements++;
if (newPosition == 0) {
add(newEntry);
} else if (newPosition >= getLength() + 1) {
DoubleLinkedNode previousNode = getNodeAt(newPosition - 1);
DoubleLinkedNode NextNode = previousNode.getNextNode();
newAdder.setNextNode(NextNode);
newAdder.setPreviousNode(previousNode);
previousNode.setNextNode(newAdder);
NextNode.setPreviousNode(newAdder);
} else if (newPosition == getLength()) {
DoubleLinkedNode previousNode = getNodeAt(newPosition - 1);
previousNode.setNextNode(newAdder);
newAdder.setPreviousNode(previousNode);
last = newAdder;
}
} else {
throw new IndexOutOfBoundsException("");
}
}
I cannot figure out how to get the add newEntry and other add method to work All the Method calls do what you'd think they'd do
In: Computer Science
Q. An Operating system is an intermediary agent between the user and the computer hardware. Explain !
In: Computer Science
(java)
Create a specification(your choice) of a data abstraction , decide a rep for the data abstraction. Write the abstraction function and the rep invariant for the rep.
Note* add comments for explanation..
In: Computer Science
A data structure can be defined as a mechanism for organizing the data a program stores in memory. An example of a data structure is a Linked List. Discuss how a linked list works and the methods of this data structure. (Please be super detailed and type the solution)
In: Computer Science
1 for each of the problems listed below write the c++ program while using WHILE loop structures
A program will display each term in the following sequence
1 -10 100 -1000 10000 -100000 1000000
A program will calculate and display the corresponding celsius temperatures for the given Farenheit ones from 0f to 212 f (hint c=(f-32/1.8)
In: Computer Science
2D object transformations(Use NetBeans IDE)
Task: create a program that realizes 2D transformations for 2D
object with at least three
control points:
• Movement
o The user must be able to input the movement step (in
pixels)
o The movement can be controlled with keyboard cursor keys
(←↑→↓)
• Scaling
o The user must be able to input the scaling parameters
o The scaling should be controlled with keyboard keys (for example
"Page
Up", "Page Down")
• Rotation
o The user must be able to input the angle of rotation (in
degrees)
o The user must be able to input a point, around which the object
will rotate
(X, Y)
o Automatic rotation must be implemented, the user pushes a button
and the
object begins to rotate around the given point (animation using
timer)
In: Computer Science
You are given a text file that contains the timetable for buses that travel a college campus. The first line of the file contains the name for each stop on the bus system separated by colons. Each following line contains the times using a 24-hour clock at which each bus in the system will arrive at a bus stop, also separated by colons.The timetable will have the following format:
Edinburgh:Danderhall:Dalkeith:Edgehead:Pathhead:Blackshiels:Oxton:Carfraemill:Lauder:Earlston:Leaderfoot:Newtown St Boswells:St Boswells:Clintmains:Kelso
0850:0911:0918:0930:0933:0939:0953:0955:1001:1015:1025:1029:1032:1038:1055
1150:1211:1218:1230:1233:1239:1253:1255:1301:1315:1325:1329:1332:1338:1355
1350:1411:1418:1430:1433:1439:1453:1455:1501:1515:1525:1529:1532:1538:1555
1610:1633:1640:1652:1655:1701:1715:1717:1723:1737:1746:1750:1753:1803:1820
1750:1811:1818:1830:1833:1839:1853:1855:1901:1919:1925:1929:1932:1938:1955
2000:2021:2028:2037:2040:2046:2100:2102:2108:2121:2126:2130:2133:2138:2155
Write a program in Python that reads this file and outputs a row for each bus stop, showing the times when a bus arrives at that stop
In: Computer Science
Convert signed integer 0xACE9 to binary and decimal.
Convert unsigned integer0xACE9 to binary and decimal.
In: Computer Science
In: Computer Science
The Harrison Group Life Insurance company computes annual policy premiums based on the age the customer turns in the current calendar year. The premium is computed by taking the decade of the customer’s age, adding 15 to it, and multiplying by 20.
For example, a 34-year-old would pay $360, which is calculated by adding the decades (3) to 15 and then multiplying by 20.
Write an application that prompts a user for the current year then a birth year. Pass both to a method that calculates and returns the premium amount, and then display the returned amount.
Insurance.java
In: Computer Science
Outline the process that occurs when a hardware interrupt is generated by a disk controller. Set the context for the interrupt disk read and describe how an interrupt handler would address the event.
In: Computer Science
finish the java programming
Create a new class named MyCharacterListTools that provides the API shown below.
This class does not need a constructor nor will any user-defined constructor be called by the
provided code in MainClassQ1.java.
◦ MyLinkedList createCharacterList(String str) – This method is to
return a MyLinkedList whose data items are the characters of str. All of the
characters must appear in the list and in the same order as they are given in str.
◦ void removeNonLetters(MyLinkedList list) – This method is to remove
from the list any spaces, numbers and punctuation characters (this is to be done inplace).
Letters of the alphabet are to be left in the list in the same order they were given.
For example, if the list contained {H_e_l_l_o_ _W_o_r_l_d_!} then after calling this
function, the list would hold {H_e_l_l_o_W_o_r_l_d}. You may use the built-in Java
static method Character.isLetter(char ch) to test whether the list items are
letters.
◦ boolean testEquality(MyLinkedList l1, MyLinkedList l2) – This
method is to compare two MyLinkedLists for equality. Two lists are considered
equal if their contents are the same and in the same order. Letter case should not be
observed (i.e. 'A' is equal to 'a', 'B' is equal to 'b', etc...). If the two lists are equal then
return true. Return false otherwise. The static built-in Java methods
Character.toLowerCase(char ch) and Character.toUpperCase(char
ch) may be used in this method.
In: Computer Science
Write a C++ program that displays the current time
In: Computer Science
inserting a node after given node.
DLL::DLL(int x){ // constructor, initializes a list with one new
node with data x
DNode *n = new DNode (x);
first = n;
last = n;
size=1;
}
DNode::DNode( int x){
data = x;
next = NULL;
prev = NULL;
}
void DLL::addFirst(int x) {
DNode* tmp = new DNode(x);
first = tmp;
last = first;
}
void DLL::insertAt(int ind, int x) {
int i = 0;
DNode *tmp = first;
DNode *tmp2;
while(i < ind && tmp != NULL) {
i += 1;
tmp2 = tmp;
tmp = tmp->next;
}
if (tmp != NULL) {
DNode *tmp3 = new DNode(x);
tmp3->next = tmp;
tmp->prev = tmp3;
tmp2->next = tmp3;
tmp3->prev = tmp2;
}
}
command to get out put:
codelist.addFirst(0);
codelist.printList();
codelist.insertAt(1,1);
codelist.printList();
codelist.insertAt(2,3);
codelist.printList();
codelist.insertAt(2,2);
codelist.printList();
codelist.push(4);
codelist.printList();
codelist.insertAt(2,42);
codelist.printList();
desired output:
0,
0, 1,
0, 1, 3,
0, 1, 2, 3,
0, 1, 2, 3, 4,
0, 1, 42, 2, 3, 4,
actual output:
0,
0,
0,
0,
0, 4,
0, 4,
In: Computer Science
Please code this in C
In this project, we shall simulate the operations of an ATM machine.
Suppose you’re in charge of this simulation and here is a scenario of what is required to do:
The customer will be assigned a random number for his/her balance.
First, the customer is prompted to enter his personal identification number pin (for this case study, we test only if this pin is formed by 4 digits! otherwise, a message like “Invalid PIN, try again . . .” will be displayed) and the user is re-prompted to enter the pin. The customer is given three chances to enter his pin. If he/she fails during the three trials you display a message like “Sorry you can’t continue, contact your bank for assistance!”
If the pin is correct (formed by 4 digits), then the system will ask the customer for the receipt ( 1 for YES and 2 for NO ) and a menu will be displayed containing five possible options to choose from: Fast Cash, Deposit, Withdraw, Balance and Get Card Back.
Here is the explanation of each of the 5 options:
Get Card Back: Display the message “Goodbye! “and exit the program.
Fast Cash: Let the customer choosing the amount of cash from a menu similar to the following:
Press:
1 --> $20.00 $40.00 <-- 2
3 --> $80.00 $100.00 <-- 4
Withdraw: Prompt the user for the amount of money he/she would like to withdraw and make the sure that he/she has enough money for that!
Deposit: Prompt the customer for the amount of deposit.
Balance: Just display the amount of money the customer has.
Don’t forget to print the receipt if the customer wants one.
Sample execution: bolded text represents the user entry
Virtual Bank at West
WELCOME
Enter Pin: 245
Invalid PIN, Re-enter Pin: 5487
(clear screen )
Receipt y or Y -> Yes No <- n or N
Enter choice: N
(Clear screen)
CHOOSE FROM THE FOLLOWING
1 -> Fast Cash Withdraw <- 2
3 -> Deposit Check Balance <- 4
5 -> Get Card Back
Enter your choice: 4
(Clear screen)
Your Balance is : $124.3
1 -> Another Transaction Get Card Back <- 2
Enter your choice: 1
(Clear screen)
CHOOSE FROM THE FOLLOWING
1 -> Fast Cash Withdraw <- 2
3 -> Deposit Check Balance <- 4
5 -> Get Card Back
Enter your choice: 2
(Clear screen )
Enter amount (enter 0 to cancel): 300.00
Sorry not enough balance
Enter amount (enter 0 to cancel): 30.00
Take your cash…
(Clear screen)
Your Balance is: $124.32
1 -> Another Transaction Get Card Back <- 2
Enter your choice: 1
(Clear screen)
CHOOSE FROM THE FOLLOWING
1 -> Fast Cash Withdraw <- 2
3 -> Deposit Check Balance <- 4
5 -> Get Card Back
Enter your choice: 8
Invalid Entry
(Clear screen)
CHOOSE FROM THE FOLLOWING
1 -> Fast Cash Withdraw <- 2
3 -> Deposit Check Balance <- 4
5 -> Get Card Back
Enter your choice: 5
(Clear screen)
THANK FOR USING OUR VIRTUAL BANK SYSTEM
GOODBYE. . .
In: Computer Science