Questions
<!DOCTYPE html> <html> <body> <script> // // A car's miles-per-gallon (MPG) can be calculated with the...

<!DOCTYPE html>
<html>
<body>
<script>
//
// A car's miles-per-gallon (MPG) can be calculated with the following formula:
//
//      MPG=Milesdriven/Gallonsofgasused
//
// Write a program that asks the user for the number of miles driven and the 
// gallons of gas used. It should then call a function to calculate and return 
// the car's MPG and display the result.
//

function calculateMPG(miles, gas) {

/////////////////////////////////////////////////////////////////////////////////
// Insert your code between here and the next comment block.  Do not alter     //
// any code in any other part of this file.                                    //
/////////////////////////////////////////////////////////////////////////////////

        
/////////////////////////////////////////////////////////////////////////////////
// Insert your code between here and the previous comment block.  Do not alter //
// any code in any other part of this file.                                    //
/////////////////////////////////////////////////////////////////////////////////

}

var milesDriven = prompt('How many miles have you driven? ');
var gasUsed = prompt('How much gas have you used driving that far? ')

alert('You car is getting ' + calculateMPG(milesDriven, gasUsed) + ' MPG.');

</script>
</body>
</html>

In: Computer Science

Write a class to implement HeadTailListInterface. Instead of using an array, use a List object as...

Write a class to implement HeadTailListInterface. Instead of using an array, use a List object as your instance data variable. (List (Links to an external site.) from the Java standard library- not ListInterface!). Instantiate the List object to type ArrayList.

Inside the methods of this class, invoke methods on the List object to accomplish the task. Note: some methods might look very simple... this does not mean they are wrong!

There is one difference in how this class will work compared to the other: in this extra credit class, you do not have control over the capacity, so you should not print the capacity in display and the capacity does not have to be exactly doubled in the two add methods.

For full credit:

  • Pay close attention to what should happen in "failed" conditions as described by the HeadTailListInterface compared to List!
  • Make sure your ListHeadTailList behaves as described in HeadTailListInterface.
  • Use the methods of the List interface/ArrayList class when possible instead of re-writing the code yourself.

The class header and instance data will be:

public class ListHeadTailList<T> implements HeadTailListInterface<T>

List<T> list; // initialize to type ArrayList<T> in the ListHeadTailList constructor

------------------------------------------------------------------------------------------------------------------------------------------------

/**
* An interface for a list. Entries in a list have positions that begin with 0.
* Entries can only be removed or added to the beginning and end of the list.
* Entries can be accessed from any position.
*
* @author Jessica Masters
*/
public interface HeadTailListInterface<T> {
  
   /**
   * Adds a new entry to the beginning of the list.
   * Entries currently in the list are shifted down.
   * The list size is increased by 1.
   *
   * @param newEntry The object to be added as a new entry.
   */
   public void addFront(T newEntry);
  
   /**
   * Adds a new entry to the end of the list.
   * Entries currently in the list are unaffected.
   * The list size is increased by 1.
   *
   * @param newEntry The object to be added as a new entry.
   */
   public void addBack(T newEntry);

   /**
   * Removes an entry from the beginning of the list.
   * Entries currently in the list are shifted up.
   * The list size is decreased by 1.
   *
   * @return A reference to the removed entry or null if the list is empty.
   */
   public T removeFront();
  
   /**
   * Removes an entry from the end of the list.
   * Entries currently in the list are unaffected.
   * The list size is decreased by 1.
   *
   * @return A reference to the removed entry or null if the list is empty.
   */
   public T removeBack();

  
   /** Removes all entries from this list. */
   public void clear();

  
   /**
   * Retrieves the entry at a given position in this list.
   *
   * @param givenPosition An integer that indicates the position of the desired entry.
   * @return A reference to the indicated entry or null if the index is out of bounds.
   */
   public T getEntry(int givenPosition);
  
   /**
   * Displays the contents of the list to the console, in order.
   */
   public void display();
  
   /**
   * Determines the position in the list of a given entry.
   * If the entry appears more than once, the first index is returned.
   *
   * @param anEntry the object to search for in the list.
   * @return the first position the entry that was found or -1 if the object is not found.
   */
   public int indexOf(T anEntry);
  
   /**
   * Determines the position in the list of a given entry.
   * If the entry appears more than once, the last index is returned.
   *
   * @param anEntry the object to search for in the list.
   * @return the last position the entry that was found or -1 if the object is not found.
   */
   public int lastIndexOf(T anEntry);
  
   /**
   * Determines whether an entry is in the list.
   *
   * @param anEntry the object to search for in the list.
   * @return true if the list contains the entry, false otherwise
   */
   public boolean contains(T anEntry);


   /**
   * Gets the length of this list.
   *
   * @return The integer number of entries currently in the list.
   */
   public int size();

   /**
   * Checks whether this list is empty.
   *
   * @return True if the list is empty, or false if the list contains one or more elements.
   */
   public boolean isEmpty();
}

------------------------------------------------------------------------------------------------------------------------

********TESTING ISEMPTY AND EMPTY DISPLAY
Empty is true: true

Should display:
0 elements; capacity = 10
0 elements; capacity N/A        


********TESTING ADD TO FRONT
Should display:
1 elements; capacity = 10       [2]
1 elements; capacity N/A        [2]

Should display:
3 elements; capacity = 10       [3, 4, 2]
3 elements; capacity N/A        [3, 4, 2]

Empty is false: false


********TESTING CLEAR
Should display:
0 elements; capacity = 10
0 elements; capacity N/A        

********TESTING ADD TO BACK
Should display:
1 elements; capacity = 10       [7]
1 elements; capacity N/A        [7]

Should display:
3 elements; capacity = 10       [7, 10, 5]
3 elements; capacity N/A        [7, 10, 5]


********TESTING CONTAINS
Contains 5 true:  true
Contains 7 true:  true
Contains 4 false: false


********TESTING ADD WITH EXPANSION
Should display:
32 elements; capacity = 40      [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
32 elements; capacity N/A       [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]


********TESTING INDEX OF
Index of 0  is  0: 0
Index of 31 is 31: 31
Index of -5 is -1: -1
Index of 32 is -1: -1
Index of 3  is  0: 0
Index of 5  is  6: 6


********TESTING LAST INDEX OF
Last index of 0  is  1:  1
Last index of 31 is 32: 32
Last index of -5 is -1: -1
Last index of 35 is -1: -1
Last index of 3  is  4:  4
Last index of 5  is  33: 33


********TESTING SIZE
Size is 34: 34


********TESTING GET ENTRY
Element in position 15 is 14: 14
Element in position  0 is  3: 3
Element in position 39 is null: null
Element in position -1 is null: null


********TESTING REMOVES
Remove front element 3: 3
Remove back element  5 :5
Remove front element 0: 0
Remove back element 31: 31

Should display:
30 elements; capacity = 40      [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
30 elements; capacity N/A       [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]

Remove element null: null
Remove element null: null

Remove element 1: 1
Should display:
0 elements; capacity = 40
0 elements; capacity N/A        

Remove element 1: 1
Should display:
0 elements; capacity = 40
0 elements; capacity N/A        

Remove element 1: 1
Should display:
0 elements; capacity = 40
0 elements; capacity N/A        

Remove element 1: 1
Should display:
0 elements; capacity = 40
0 elements; capacity N/A        



********TESTING MIX OF ADDS AND REMOVES
Should display:
7 elements; capacity = 40       [5, 4, 3, 2, 3, 8, 9]
7 elements; capacity N/A        [5, 4, 3, 2, 3, 8, 9]

Should display:
5 elements; capacity = 40       [4, 3, 2, 3, 8]
5 elements; capacity N/A        [4, 3, 2, 3, 8]

********TESTING WITH STRINGS
Should display:
5 elements; capacity = 5        [You, did, it!, Nice, job!]
5 elements; capacity = 5        [You, did, it!, Nice, job!]

Contains "Nice" is true: true
Contains "You"  is true: true
Contains "you"  is false: false

Index of "it!" is 2: 2
Last index of "it!" is 2: 2

In: Computer Science

PYTHON Part A. Write a program for salespersons to show discounted prices. a) Request the salesperson...

PYTHON

Part A. Write a program for salespersons to show discounted prices.

a) Request the salesperson to enter the listed price of a product
b) Write a function to meet the requirements:
i. The function takes the listed price as a parameter
ii. Print a table which lists discounted prices (10%, 20%, 30%, 40%, and 50% off) (see below)
iii. Note that the printing job needs to be done inside the function [3 pts]

Part B. Write another program to meet additional requirements:
c) Request the salesperson to enter 2 inputs: (1) the listed price & (2) increment of discount rates.
For example: the salesperson can enter 0.05 to indicate a 5% discount increment.
d) Write a function to meet the requirements:
i. The function takes two parameters: (1) the listed price & (2) the rate increment
ii. Using a loop, print a table which lists discounted prices, up to 50% off (see below)
iii. Note that the printing job needs to be done inside the function

Note: All prices (including listed & discounted) must be presented with 2 decimals and $. For discount rate increment, the smallest possible input is 0.01, i.e., 1%. No need to worry if a rate incremental has 3 decimals or more.

In: Computer Science

Run the following R commends. set.seed(2019) x = rnorm(100,mean=0, sd=2) y = rnorm(100,mean=0, sd=20) [NOTE: Do...

Run the following R commends.
set.seed(2019) x = rnorm(100,mean=0, sd=2) y = rnorm(100,mean=0, sd=20)
[NOTE: Do NOT use built-in functions which can directly solve the problems.]
(1) Compute the means of values in the vectors x and y, respectively. Which one is more close to zero? Explain the reason.
(2) Compute the sample standard deviations of values in the vector x and y, respectively.
(3) Find the index positions in x and y of the values between -5 and 5, respectively

In: Computer Science

programming with processing Draw a circle in the top left corner of the screen. make your...

programming with processing

Draw a circle in the top left corner of the screen. make your circle go around a square path continuously.the cycle should

-in a straight line go to the far-right side of the window

-in a straight line go to the bottom of the window

-in a straight line go to the far-left corner of the window

in a straight line go to the top left of the window

-keep repeating the above steps

This process should be repeated until program is terminated

drawing should not go out of the bounds of the window .

i have this so far can't get it to got to the left:

int x = 40, y = 40;


void setup()
{
size(600, 600);
}
void draw()
{
background (200);
ellipse (x, y, 80, 80);
if ((x<560))
{
x=x+xdir;
}
else if(y<560)
{y=y+ydir;
}
else if(x<560)
{
  

}
  
  
}

In: Computer Science

go to w3schools online html editor • Your Name in Bold • Your Current College Major,...

go to w3schools online html editor

• Your Name in Bold

• Your Current College Major, Not in Bold text

• A horizontal line

• Your Favorite Hobby in Italics

• Your Favorite Movie written in Red text ... use any resource you would like (web/textbook/etc) to figure out how to complete this step.

• A picture from another website of your Favorite Book or Magazine

• Text under the Book or Magazine stating what it is or why it's your favorite

• A link to an interesting webpage, the link text must match the page you are linking to. (ie: Don't write CNN for the link, and have it point at MSNBC.com)

• A picture of an interesting person that is also a link to their wikipedia page. The picture itself must be the link, no actual text to click on.

• Embed a you tube video of your favorite music video.  

In: Computer Science

Java language This is your first homework on objects and classes, and the basics of object-oriented...

Java language

This is your first homework on objects and classes, and the basics of object-oriented programming. For each exercise, your task is to first write the class that defines the given object. Compile it and check it for syntax errors. Then write the “demo class” with the main program that creates and uses the object.

a)You are planning to purchase a new motor boat for cool cruises on Porter’s Lake this summer, but you want to simulate it before you make the purchase. Write a class MotorBoat that represents motorboats. A motorboat has attributes for

  • The capacity of the fuel tank (liters)
  • The amount of fuel in the tank (liters)
  • The maximum speed of the boat (kmph)
  • The current speed of the boat (kmph)
  • The rate of fuel consumption (liters/km)
  • The distance traveled (km)

and the following methods:

  • Constructor that sets the capacity, fuel in the tank, max speed and fuel consumption to the given values and current speed to zero.
  • Method to set the current speed of the boat
  • Method to get the current speed of the boat
  • Method to change the speed of the boat (the method should accept the change which is a positive or negative number and change the current speed. If the change is greater than max speed, it should set the current speed to max speed).
  • Operate the boat for an amount of time in minutes at the current speed (this method should set the distance traveled and reduce the amount of fuel in the tank by the appropriate amount).
  • Refuel the boat with some amount of fuel (if the total amount of fuel is greater than the capacity, set it to the capacity).
  • Return the amount of fuel in the tank
  • Return the distance traveled so far

Note: If the rate of fuel consumption is r and the distance traveled is d, then the amount of fuel remaining in the tank = fuel in tank – r*d

b) Write a tester program that creates a motorboat with capacity 100 liters, fuel in tank 50 liters, max. speed 100 kmph, rate of fuel consumption 1. Set its speed to 25 kmph and operate it for 30 minutes. Print the current speed, distance driven and the fuel remaining in the tank. Then increase the speed by 25, and operate it for 30 minutes. Print the current speed, distance driven and fuel in tank. Your output should be:

Current speed: 25.0 kmph

Distance driven: 12.5 km

Fuel in tank: 37.5 liters

Current speed: 50.0 kmph

Distance driven: 25.0 km

Fuel in tank: 12.5 liters

Test your program to check for other cases as well.

In: Computer Science

Hello, I have created the following code in C++. The goal of this code is to...

Hello,

I have created the following code in C++. The goal of this code is to read 3 types of employee information(String/*Name*/, String/*Phone number*/,Int/*Office number*/, ) from a .txt file and store that information into an array which can be accessed by various functions. The code below is within a header file, and im trying to define some functions (within a .cpp file) of my class to carry out the following tasks.

I have already managed to define a couple functions, but I'm stuck on the two listed below and need help coding them.

Thank you.

CODE:
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

const int SIZE = 25;

struct Phone
{
   string employeeName;
   string phoneExt;
   int officeNumber;
};

class Directory
{
public:
   Directory(string/*file name*/, int = SIZE/*max number of employees*/);
   void showPhone(string/*employee phone*/, int /*employee office*/);
   void showPhoneOffice(string/*Name*/) const;
   void writeDirectory(ostream &)const;
   void addEmployee(string/*Name*/, string/*Phone*/, int/*Office*/); // this is second function I need help defining
   void showNoEmployees(ostream &) const; //This is first function I need help defining
   int getNoEmployees() const {return noEmployees;}


private:
   Phone employees[SIZE];
   int maxEmployees;
   int noEmployees;
   void findEmployee();
  
};

1. showPhoneOffice() that displays a string(a name) and int( a phone number). The function receives the string and int. It does not return a value. Displays the data or a meaningful error message if the string was not found

2. . addEmployee() that adds an employee(string/*Name*/,string/*Name*/,int/*Office Number*/) to the employee array. The function receives the employee’s string, string and int. It does not return a value. Ensure the employee is not already in an existing array and that the array is not full. You can assume valid data is passed.

In: Computer Science

Blocks/pages are units of both storage allocation and data transfer. True False ------------------------------------- While clustering of...

Blocks/pages are units of both storage allocation and data transfer.

True

False

-------------------------------------

While clustering of records from two or more tables can enhance the performance of some join queries, other queries may see diminished performance.

True

False

----------------------------

databases are too large to fit on the main Memory so they are stored on the magnetic disk

True

False

----------------

In: Computer Science

Cant get this to loop properly. Any tips out there? import java.util.Scanner; public class Lab4 {...

Cant get this to loop properly. Any tips out there?

import java.util.Scanner;
public class Lab4 {
public static void main(String[] args) {

//Declared variables
int choice;int number; int sum=0; int fact =1;
Scanner scan = new Scanner(System.in);

do {
System.out.println("Please choose one option from the following menu:");
System.out.println("1) Calculate the sum of integers from 1 to m");
System.out.println("2) Calculate the factorial of a given number");
System.out.println("3) Display the leftmost digit of a given number");
System.out.println("4) Quit");
choice= scan.nextInt();

//Based on choice, the entered menun options will be executed
switch(choice){

case 1:
System.out.println("enter a number");
number = scan.nextInt();
for(int i =1; i<=number; i++) {
sum = sum + i;
}
System.out.println("the sum of 1 to " + "" + number + " " + "is" + " " + sum );
number = scan.nextInt();
break;

case 2:
System.out.println("enter a number");
number = scan.nextInt();
for(int i=1; i<=number; i++) {
fact = fact * i;
}System.out.println("The factorial is" + " " + fact);
number = scan.nextInt();
break;
  
case 3:
System.out.println("Enter Number");
number = scan.nextInt();
while(number >= 10)
number = number / 10;
System.out.println("The left most digit is" + " " + number);
number = scan.nextInt();
break;

default:
System.out.println("Invalid choice.");
number = scan.nextInt();
break;
}

}while(choice!=4); {

}
}
}

In: Computer Science

Write the code in python only. You will need the graphics library for this assignment. Please...

Write the code in python only.

You will need the graphics library for this assignment. Please download the library and place it in the same file as your solution.

Draw a 12" ruler on the screen. A ruler is basically a rectangular outline with tick marks extending from the top edge. The tick marks should be drawn at each quarter-inch mark. Below the tick marks, your ruler should show large integers at each full-inch position.

In: Computer Science

def box_sort(names, sizes): Given a list of strings names, a corresponding list of ints sizes, we...

def box_sort(names, sizes): Given a list of strings names, a corresponding list of ints sizes, we want to sort items by size so that each of our four sublists contains items in the smallest possible boxes of the following exact sizes: 2, 5, 25, and 50 units. Anything larger than 50 won't fit in a box and is simply ignored at this time. Create and return a list of the four sublists of items.

o Assume: names is a list of strings, and sizes is a list of ints.
o Restrictions: remember, you can't call any built-in sorting functions. It's not hard-coding to

directly calculate based on the four given sizes, but keeping a list of box sizes may actually simplify your code.
box_sort(['a','b','c','d'], [1,5,6,10]) → [['a'],['b'],['c','d'],[]] box_sort(['a','b','c'], [49,50,51]) → [[],[],[],['a','b']]

def packing_list(names, sizes, box_size): Given a list of names, a corresponding list of int sizes, and an int box_size, this time we want to keep packing items into boxes of the given box_size until it's full, and then start filling another box of the same size. We return a list of filled boxes as a list of lists of strings. Oversized items are immediately placed into our output in a list by themselves, with an asterisk prefix to indicate that it does not fit. (We continue filling the current box after an oversized item). Items are only considered in their given ordering; do not reorder the items to seek a better packing list! Create and return this list of lists, each one containing items in one box or the single oversized item.

o Assume: names is a list of strings, sizes is a list of ints, and box_size is an int. Order is preserved for all non-oversized items, and oversized items show up immediately before the box that was being filled at the time of consideration.

          # boxes of 2+1, 4, and 2.

packing_list(['a','b','c','d'], [2,1,4,2],5) → [['a','b'],['c'],['d']]

          # while packing our second box, we find oversized item b, then finish our box.

packing_list(['x','a','b','c'], [5,2,10,3], 5) → [['x'],['*b'],['a','c']]

In: Computer Science

C++ language You will create a Hangman class. Possible private member variables: int numOfCharacters; //for the...

C++ language

You will create a Hangman class.
Possible private member variables:
int numOfCharacters; //for the secret word
char * secretWord;
char *guessedWord;

public:

//please create related constructors, getters, setters,constructor()

constructor()

You will need to initialize all member variables including the two dynamic variables.

destructor()

Please deallocate/freeup(delete) the two dynamic arrays memories.

guessALetter(char letter)

1.the function will check if the letter guessed is included in the word.

2. display the guessed word with related field(s) filled if the letter guessed matches the some of the letters of the word

gameResult()

1. Display how many times guessed so far

2. Display how many times with the wrong letter guessed3. Display "you win" if all letters are filled in the guess word4. Display "you lost" if the times of guessing the wrong letter reaches 6 (Note: 6 body parts - head, body, left arm, right arm, left leg, right leg)


main()

Instantiate an object of Hangman.Ask the host: how many letters in the guess word.

Ask the host: what is the guess word?

Design a loop for the player to play the guess game

1. The loop should exit if the number of wrong guess reaches 6

2. inside the loop, there should be a condition to allow the player to exit, say "Do you want to continue playing (y|n)?". If the user chooses 'n', exit the loop.

3. Inside the loop, you may do some function chaining calls, something like:

obj.guessALetter(guessLetter).gameResult()

In: Computer Science

Program in Java Write an algorithm to transfer the elements from queue Q1 to queue Q2,...

Program in Java

Write an algorithm to transfer the elements from queue Q1 to queue Q2, so that the contents in Q2 will be in reverse order as they are in Q1 (e.g. if your queue Q1 has elements A, B, and C from front to rear, your queue Q2 should have C, B, and A from front to rear). Your algorithm must explicitly use an additional stack to solve the problem. Write your algorithm in pseudo code first, and make sure to share it.

You may want to implement your own stack and queue for practice purpose although you are allowed to use the library if you want to. However, you can only use the basic methods such as push and pop for stack, enqueue and dequeue for queues.

In: Computer Science

Objective: Manipulate the Linked List Pointer. Write a java subclass to extend LList.java. Provide a reverse...

Objective: Manipulate the Linked List Pointer.

  1. Write a java subclass to extend LList.java. Provide a reverse list method in the subclass to reverse the order of the linked list.
  2. Print the original linked list and the reverse ordered linked list at the end of program.
  3. You can use the gamescore.txt to test the reverse method.

_____________________________________________________________________________________________________________________________________________________

/** Source code example for "A Practical Introduction to Data

    Structures and Algorithm Analysis, 3rd Edition (Java)"

    by Clifford A. Shaffer

    Copyright 2008-2011 by Clifford A. Shaffer

*/

/** List ADT */

public interface List {

  /** Remove all contents from the list, so it is once again

      empty. Client is responsible for reclaiming storage

      used by the list elements. */

  public void clear();

  /** Insert an element at the current location. The client

      must ensure that the list's capacity is not exceeded.   

      @param item The element to be inserted. */

  public void insert(E item);

  /** Append an element at the end of the list. The client

      must ensure that the list's capacity is not exceeded.   

      @param item The element to be appended. */

  public void append(E item);

  /** Remove and return the current element.

      @return The element that was removed. */

  public E remove();

  /** Set the current position to the start of the list */

  public void moveToStart();

  /** Set the current position to the end of the list */

  public void moveToEnd();

  /** Move the current position one step left. No change

      if already at beginning. */

  public void prev();

  /** Move the current position one step right. No change

      if already at end. */

  public void next();

  /** @return The number of elements in the list. */

  public int length();

  /** @return The position of the current element. */

  public int currPos();

  /** Set current position.

      @param pos The position to make current. */

  public void moveToPos(int pos);

  /** @return The current element. */

  public E getValue();

}

/** Source code example for "A Practical Introduction to Data

    Structures and Algorithm Analysis, 3rd Edition (Java)"

    by Clifford A. Shaffer

    Copyright 2008-2011 by Clifford A. Shaffer

*/

// Doubly linked list implementation

class LList implements List {

protected DLink head;        // Pointer to list header

protected DLink tail;        // Pointer to last element in list

protected DLink curr;      // Pointer ahead of current element

int cnt;          // Size of list

//Constructors

LList(int size) { this(); }  // Ignore size

LList() {

  curr = head = new DLink(null, null); // Create header node

  tail = new DLink(head, null);

  head.setNext(tail);

  cnt = 0;

}

public void clear() {         // Remove all elements from list

  head.setNext(null);         // Drop access to rest of links

  curr = head = new DLink(null, null); // Create header node

  tail = new DLink(head, null);

  head.setNext(tail);

  cnt = 0;

}

public void moveToStart()  // Set curr at list start

{ curr = head; }

public void moveToEnd()  // Set curr at list end

{ curr = tail.prev(); }

/** Insert "it" at current position */

public void insert(E it) {

  curr.setNext(new DLink(it, curr, curr.next()));  

  curr.next().next().setPrev(curr.next());

  cnt++;

}

/** Append "it" to list */

public void append(E it) {

  tail.setPrev(new DLink(it, tail.prev(), tail));

  tail.prev().prev().setNext(tail.prev());

  cnt++;

}

/** Remove and return current element */

public E remove() {

  if (curr.next() == tail) return null; // Nothing to remove

  E it = curr.next().element();      // Remember value

  curr.next().next().setPrev(curr);

  curr.setNext(curr.next().next());  // Remove from list

  cnt--;           // Decrement the count

  return it;                         // Return value removed

}

/** Move curr one step left; no change if at front */

public void prev() {

  if (curr != head)   // Can't back up from list head

    curr = curr.prev();

}

// Move curr one step right; no change if at end

public void next()

  { if (curr != tail.prev()) curr = curr.next(); }

public int length() { return cnt; }

// Return the position of the current element

public int currPos() {

  DLink temp = head;

  int i;

  for (i=0; curr != temp; i++)

    temp = temp.next();

  return i;

}

// Move down list to "pos" position

public void moveToPos(int pos) {

  assert (pos>=0) && (pos<=cnt) : "Position out of range";

  curr = head;

  for(int i=0; i

}

public E getValue() {   // Return current element

  if (curr.next() == tail) return null;

  return curr.next().element();

}

// Extra stuff not printed in the book.

  /**

   * Generate a human-readable representation of this list's contents

   * that looks something like this: < 1 2 3 | 4 5 6 >.  The vertical

   * bar represents the current location of the fence.  This method

   * uses toString() on the individual elements.

   * @return The string representation of this list

   */

  public String toString()

  {

    // Save the current position of the list

    int oldPos = currPos();

    int length = length();

    StringBuffer out = new StringBuffer((length() + 1) * 4);

    moveToStart();

    out.append("< ");

    for (int i = 0; i < oldPos; i++) {

      out.append(getValue());

      out.append(" ");

      next();

    }

    out.append("| ");

    for (int i = oldPos; i < length; i++) {

      out.append(getValue());

      out.append(" ");

      next();

    }

    out.append(">");

    moveToPos(oldPos); // Reset the fence to its original position

    return out.toString();

  }

}

/** Source code example for "A Practical Introduction to Data

    Structures and Algorithm Analysis, 3rd Edition (Java)"

    by Clifford A. Shaffer

    Copyright 2008-2011 by Clifford A. Shaffer

*/

/** Doubly linked list node */

class DLink {

  private E element;         // Value for this node

  private DLink next;     // Pointer to next node in list

  private DLink prev;     // Pointer to previous node

  /** Constructors */

  DLink(E it, DLink p, DLink n)

  { element = it;  prev = p; next = n; }

  DLink(DLink p, DLink n) { prev = p; next = n; }

  /** Get and set methods for the data members */

  DLink next() { return next; }

  DLink setNext(DLink nextval)

    { return next = nextval; }

  DLink prev() { return prev; }

  DLink setPrev(DLink prevval)

    { return prev = prevval; }

  E element() { return element; }

  E setElement(E it) { return element = it; }

}

public class GameEntry {

protected String name;

protected int score;

public GameEntry(String n, int s) {

   name = n;

   score = s;

}

public String getName() {return name;}

public int getScore() {return score;}

public String toString() {

return "("+name+","+score+")";

}

}

//gamescore.txt

Mike,1105
Rob,750
Paul,720
Anna,660
Rose,590
Jack,510

In: Computer Science