Question

In: Computer Science

import java.util.LinkedList; import java.util.ListIterator; public class ProjectList { /** This is the main function for the...

import java.util.LinkedList;
import java.util.ListIterator;

public class ProjectList
{
/** This is the main function for the program */
public static void main()
{
System.out.println("\n\tBegin ProjectList demo program");
  
// 1. TO DO: Describe your project (1 Pt)
System.out.println("Project: . . . . . . \n");

System.out.println("Create a LinkedList to store the tasks");
// 2. TO DO: Declare a LinkedList of String objects called "tasks" (1 Pt)
  
  
System.out.println("Add initial tasks into the list");
// 3. TO DO: Add initial list of four or more tasks (5 Pts)

  
  
  
  
  
System.out.println("\nDisplay Initial list: ");
printList(tasks);
  
System.out.println("Add a step to the front of the list");
// 4. TO DO: Add a task to the front of the list (2 Pts)

printList(tasks);
  
System.out.println("Create a ListIterator for the tasks");
// 5. TO DO: Declare a List iterator for the tasks (2 Pts)
  
  
System.out.println("\nIterate two or more steps forward and insert one or more tasks");
// 6. TO DO: Iterate two or more steps forward and insert one or more tasks (3 Pts)

  
  
  
printList(tasks);
  
System.out.println("Move forward one or more tasks and remove a task");
// 7. TO DO: Iterate down one or more tasks and remove a task (3 Pts)

  
printList(tasks);
  
System.out.println("Move back one or more tasks and add some tasks");
// 8. TO DO: Iterate back one or more tasks and add some tasks (3 Pts)

  
  
  
printList(tasks);
  
System.out.println("Add remaining task(s) to finish the project");
// 9. TO DO: Add at least one remaining task(s) to finish the project (3 Pts)

  
  
  
  
System.out.println("\nFinal list of elements:");
printList(tasks);   

System.out.println("\tEnd LinkedList demo program\n");
}

/**
* This method displays the elements in the LinkedList
* It declares a LinkedList iterator for traversal
* @param tasks - reference to the LinkedList to be displayed
*/
private static void printList(LinkedList<String> tasks)
{
int number = 1;
ListIterator iterator = tasks.listIterator();
while (iterator.hasNext())
System.out.printf("%3d - %s\n", number++, iterator.next().toString());
System.out.println();
}
}

Solutions

Expert Solution


import java.util.LinkedList;
import java.util.ListIterator;

public class ProjectList {

   /** This is the main function for the program */
   public static void main(String[] args)
   {
       System.out.println("\n\tBegin ProjectList demo program");
      
       // 1. Describe your project (1 Pt)
       System.out.println("Project: LinkedList demo program\n");
  
       System.out.println("Create a LinkedList to store the tasks");
       // 2. Declare a LinkedList of String objects called "tasks" (1 Pt)
       LinkedList<String> tasks = new LinkedList<String>();
      
       System.out.println("Add initial tasks into the list");
       // 3. Add initial list of four or more tasks (5 Pts)
       tasks.add("Task 1");
       tasks.add("Task 2");
       tasks.add("Task 3");
       tasks.add("Task 4");
      
      
       System.out.println("\nDisplay Initial list: ");
       printList(tasks);
      
       System.out.println("Add a step to the front of the list");
       // 4. Add a task to the front of the list (2 Pts)
       tasks.addFirst("Task 5");
       printList(tasks);
      
       System.out.println("Create a ListIterator for the tasks");
       // 5. Declare a List iterator for the tasks (2 Pts)
       ListIterator<String> iterator = tasks.listIterator();
      
       System.out.println("\nIterate two or more steps forward and insert one or more tasks");
       // 6. Iterate two or more steps forward and insert one or more tasks (3 Pts)
       iterator.next();
       iterator.next();
      
       iterator.add("Task 6");
      
       printList(tasks);
      
       System.out.println("Move forward one or more tasks and remove a task");
       // 7. Iterate down one or more tasks and remove a task (3 Pts)
       iterator.next();
       iterator.remove();
      
       printList(tasks);
      
       System.out.println("Move back one or more tasks and add some tasks");
       // 8. Iterate back one or more tasks and add some tasks (3 Pts)
       iterator.previous();
       iterator.add("Task 7");
       iterator.add("Task 8");
      
      
       printList(tasks);
      
       System.out.println("Add remaining task(s) to finish the project");
       // 9. Add at least one remaining task(s) to finish the project (3 Pts)
       tasks.add("Task 9");
      
      
       System.out.println("\nFinal list of elements:");
       printList(tasks);   
  
       System.out.println("\tEnd LinkedList demo program\n");
   }

   /**
   * This method displays the elements in the LinkedList
   * It declares a LinkedList iterator for traversal
   * @param tasks - reference to the LinkedList to be displayed
   */
   private static void printList(LinkedList<String> tasks)
   {
       int number = 1;
       ListIterator iterator = tasks.listIterator();
       while (iterator.hasNext())
       System.out.printf("%3d - %s\n", number++, iterator.next().toString());
       System.out.println();
   }

}

//end of program

Output:


Related Solutions

import java.util.LinkedList; import java.util.Queue; import java.time.*; public class CheckOutLine { /** This is the main function...
import java.util.LinkedList; import java.util.Queue; import java.time.*; public class CheckOutLine { /** This is the main function for the program */ public static void main() { System.out.println("\n\tBegin CheckOutLine Demo\n"); System.out.println("\nCreating a Queue called \"register\" based on a LinkedList"); Queue<Customer> register = new LinkedList<Customer>();    System.out.println("\nAdding Customers to the Register queue"); // 1. TO DO: add five or more customers to the register line (5 Pts) // format: register.add(new Customer(name, checkout time));                System.out.printf("Register line has %d customers\n",...
import java.util.LinkedList; public class StudentLinkedList { public static void main(String[] args) { LinkedList<Student> linkedlist = new...
import java.util.LinkedList; public class StudentLinkedList { public static void main(String[] args) { LinkedList<Student> linkedlist = new LinkedList<Student>(); linkedlist.add(new Student("Ahmed Ali", 20111021, 18, 38, 38)); linkedlist.add(new Student("Sami Kamal", 20121021, 17, 39, 35)); linkedlist.add(new Student("Salem Salim", 20131021, 20, 40, 40)); linkedlist.add(new Student("Rami Mohammed", 20111031, 15, 35, 30)); linkedlist.add(new Student("Kim Joe", 20121024, 12, 32, 32)); linkedlist.addFirst(new Student("Hadi Ali", 20111025, 19, 38, 39)); linkedlist.addLast(new Student("Waleed Salim", 20131025, 10, 30, 30)); linkedlist.set(0, new Student("Khalid Ali", 20111027, 15, 30, 30)); linkedlist.removeFirst(); linkedlist.removeLast(); linkedlist.add(0, new Student("John Don",...
Can someone please convert this java code to C code? import java.util.LinkedList; import java.util.List; public class...
Can someone please convert this java code to C code? import java.util.LinkedList; import java.util.List; public class Phase1 { /* Translates the MAL instruction to 1-3 TAL instructions * and returns the TAL instructions in a list * * mals: input program as a list of Instruction objects * * returns a list of TAL instructions (should be same size or longer than input list) */ public static List<Instruction> temp = new LinkedList<>(); public static List<Instruction> mal_to_tal(List<Instruction> mals) { for (int...
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {       ...
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {        Stack<Integer> new_stack = new Stack<>();/* Start with the empty stack */        Scanner scan = new Scanner(System.in);        int num;        for (int i=0; i<10; i++){//Read values            num = scan.nextInt();            new_stack.push(num);        } System.out.println(""+getAvg(new_stack));    }     public static int getAvg(Stack s) {        //TODO: Find the average of the elements in the...
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {       ...
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {        Stack<Integer> new_stack = new Stack<>();/* Start with the empty stack */        Scanner scan = new Scanner(System.in);        int num;        for (int i=0; i<10; i++){//Read values            num = scan.nextInt();            new_stack.push(num);        }        int new_k = scan.nextInt(); System.out.println(""+smallerK(new_stack, new_k));    }     public static int smallerK(Stack s, int k) {       ...
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Exercise { public static void main(String[] args) {...
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Exercise { public static void main(String[] args) { Scanner input=new Scanner(System.in); int[] WordsCharsLetters = {0,1,2}; while(input.hasNext()) { String sentence=input.nextLine(); if(sentence!=null&&sentence.length()>0){ WordsCharsLetters[0] += calculateAndPrintChars(sentence)[0]; WordsCharsLetters[1] += calculateAndPrintChars(sentence)[1]; WordsCharsLetters[2] += calculateAndPrintChars(sentence)[2]; } else break; } input.close(); System.out.println("Words: " + WordsCharsLetters[0]); System.out.println("Characters: " + WordsCharsLetters[1]); System.out.println("Letters: " + WordsCharsLetters[2]); } static int[] calculateAndPrintChars(String sentence) { int[] WCL = new int[3]; String[] sentenceArray=sentence.split(" "); WCL[0] = sentenceArray.length; int letterCount=0; for(int i=0;i<sentence.length();i++) { if(Character.isLetter(sentence.charAt(i))) letterCount++; } WCL[1]...
TASK: Based upon the following code: import java.util.Scanner; // Import the Scanner class public class Main...
TASK: Based upon the following code: import java.util.Scanner; // Import the Scanner class public class Main {   public static void main( String[] args ) {     Scanner myInput = new Scanner(System.in); // Create a Scanner object     System.out.println("Enter (3) digits: ");     int W = myInput.nextInt();     int X = myInput.nextInt();     int Y = myInput.nextInt();      } } Use the tools described thus far to create additional code that will sort the integers in either monotonic ascending or descending order. Copy your code and...
------------------------------------------------------------------------------------ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input =...
------------------------------------------------------------------------------------ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int result = 0; System.out.print("Enter the first number: "); int x = input.nextInt(); System.out.print("Enter the second number: "); int y = input.nextInt(); System.out.println("operation type for + = 0"); System.out.println("operation type for - = 1"); System.out.println("operation type for * = 2"); System.out.print("Enter the operation type: "); int z = input.nextInt(); if(z==0){ result = x + y; System.out.println("The result is " + result); }else...
import chapter6.date.SimpleDate; import java.util.Scanner; public class SimpleDateTestDefault { public static void main(String[] args) { Scanner stdin...
import chapter6.date.SimpleDate; import java.util.Scanner; public class SimpleDateTestDefault { public static void main(String[] args) { Scanner stdin = new Scanner(System.in); SimpleDate d1 = new SimpleDate(); SimpleDate d2 = new SimpleDate(stdin.nextInt(), stdin.nextInt(), stdin.nextInt()); System.out.println(d1); System.out.println(d2); System.out.println(d1.before(d2)); System.out.println(d2.before(d1)); } } Implement SimpleDate class in chapter6.date package with the following attributes: day, (int type,  private) month, (int type,  private) year (int type,  private) The class should have the following methods: a constructor with three parameters: year, month, and day a constructor with no parameters which initialize the...
import java.util.Scanner; public class Lab9Q3 { public static void main (String [] atgs) { double mass;...
import java.util.Scanner; public class Lab9Q3 { public static void main (String [] atgs) { double mass; double velocity; double totalkineticEnergy;    Scanner keyboard = new Scanner (System.in); System.out.println ("Please enter the objects mass in kilograms"); mass = keyboard.nextDouble();    System.out.println ("Please enter the objects velocity in meters per second: "); velocity = keyboard.nextDouble();    double actualTotal = kineticEnergy (mass, velocity); System.out.println ("Objects Kinetic Energy: " + actualTotal); } public static double kineticEnergy (double mass, double velocity) { double totalkineticEnergy =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT