• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

JAVA Linked Lists问题

题目和要求:In this question, you will write a linked list class, and use it to store all of the words contained in a text file.You will write your linked list class in a file called LinkedList.java, which will contain BOTH theLinkedList class and the Node class (only the LinkedList class is public).You have been provided with a main program file called A4Test.java and a text file calleddarwin.txt.First, create a Node class. It should contain, as usual, a pointer to another node, and a String reference.Write a constructor that sets the data being stored in the Node, and set its link to the next Node to null.Write appropriate getters and setters as well.Next, create your LinkedList class. As usual, it should contain a first (top) pointer to the first node inthe list. Additionally, create a last pointer to the last Node in the linked list (we’ll see why later). Add aninteger instance variable to keep track of the size (i.e. the number of words) in the linked list.Create the following public methods: A null constructor that initializes the two Node pointers to null and the size to 0 int size() that returns the size of the list. void append(String), which takes the given word and places it at the end of the list, not atthe beginning. Instead of performing a costly traversal of the linked list from the beginninguntil the end is reached, use the last pointer instead, when appending a new item. Be mindfulof the case when the list is empty. A second constructor that takes a String parameter, which is the name of a file. Theconstructor will attempt to read the file and add all the words in the file to the linked list (usingappend). Use whitespace to separate the lines into words. In Java, the String literal"\\p{Space}+" specifies one or more whitespace characters. String format(int width) that returns a String containing all the words in their originalorder, formatted in lines that are width characters long, fully justified (i.e. the lines are alignedon both the left and right sides). This is achieved by adding extra spaces between the words sothat the right side is aligned at width characters. In order to make the justification lookbalanced, distribute the extra spaces throughout the line. Add the extra spaces left-to-right oneach second line, and right-to-left on the alternating lines. You may find it helpful to use twoprivate methods to perform these justification steps (though you are not required to do so). Thelast line is not justified, since it may contain only a few words.A4test code:public class A4Test{  public static void main(String [] args){    String fileName = "darwin.txt";    System.out.println("This is A4Test.\n");    LinkedList myList = new LinkedList(fileName);    System.out.println(myList.format(80));    System.out.println(fileName + " contains " + myList.size() + " words.");  }// main}// class A4Testdrawin.txt内容:qwertyuiopasdfghjklzxcvbnm

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

发新帖

发布任务需求已有1031166位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!