Storm
マルチレイヤーのLinkedListを使用してオブジェクトを分類する大学のコースでADTを使用してプログラムをセットアップしようとしています。これが私がする必要があることです。
- 2レベルのリンクリストを使用して、データベース内の情報を整理します。
- 上位のリンクリストのノードは年を表し、1年に1つのノードがあります。
毎年のノードには、その年の嵐のリンクリストへの参照が含まれます。
リンクされた各リストの項目を並べ替えられた順序で維持し、上のリストを年(番号順、低から高)で並べ替え、下のリストを名前(標準の辞書順)で並べ替える必要があります。
- 必要なリンクリストのバリエーションを使用できます。ダミーヘッドノード、ヘッド/エンドポインタ、二重リンクリストなど。
- リストを管理するために、必要に応じて追加のクラスを実装できます。
誰かが私にこれを教えてもらえますか?私は困惑し、これについて考えすぎて一生懸命に努力しました。
私はすでに2つのリストに4つの異なるクラスを持っています
- YearNode.java
- YearList.java
- StormNode.java
- StormList.java
- Storm.java
コードは次のとおりです。
YearNode.java
public class YearNode
{
int year;
YearNode next;
StormNode sNext;
public int getYear()
{
return year;
}
public StormNode getSNext()
{
return sNext;
}
public YearNode getNext()
{
return next;
}
public void setYear(int year)
{
this.year = year;
}
public void setNext(YearNode next)
{
this.next = next;
}
public void setSNext(StormNode next)
{
this.sNext = sNext;
}
}
YearList.java
public class YearList
{
YearNode head;
YearNode sHead;
public YearList()
{
YearNode head = null;
YearNode sHead = null;
}
public boolean isEmpty()
{
return(head == null);
}
public boolean isStormEmpty()
{
return(sHead == null);
}
public void setSList(StormNode node)
{
StormNode sHead = node;
}
public int size()
{
YearNode current = head;
int counter = 0;
while(current != null)
{
counter++;
current = current.getNext();
}
return counter;
}
public int get(int index)
{
int size = size();
YearNode current = head;
if((index > size) || (index < 0))
{
throw new IndexOutOfBoundsException();
}
else
{
int counter = index;
while(counter != 0)
{
current = current.getNext();
counter--;
}
return current.getYear();
}
}
public void add(int index, int year)
{
if((index < 0) || (index > size()))
{
throw new IndexOutOfBoundsException();
}
YearNode current = head;
YearNode previous = null;
while (index > 0)
{
index--;
previous = current;
current = current.getNext();
}
YearNode Splice = new YearNode();
Splice.setYear(year);
Splice.setNext(current);
if(previous == null)
{
head = Splice;
}
else
{
previous.setNext(Splice);
}
}
public int remove(int index)
{
if((index < 0) || (index > size()))
{
throw new IndexOutOfBoundsException();
}
YearNode current = head;
YearNode previous = null;
while (index > 0)
{
index--;
previous = current;
current = current.getNext();
}
if(previous == null)
{
head = current.getNext();
}
else
{
previous.setNext(current.getNext());
}
return current.getYear();
}
public void removeAll()
{
head = null;
}
}
StormNode.java
public class StormNode
{
Storm storm;
StormNode next;
public Storm getStorm()
{
return storm;
}
public StormNode getNext()
{
return next;
}
public void setStorm(Storm storm)
{
this.storm = storm;
}
public void setNext(StormNode next)
{
this.next = next;
}
}
StormList.java
public class StormList
{
StormNode head;
public StormList()
{
StormNode head = null;
}
public StormNode getHead()
{
return head;
}
public boolean isEmpty()
{
return(head == null);
}
public int size()
{
StormNode current = head;
int counter = 0;
while(current != null)
{
counter++;
current = current.getNext();
}
return counter;
}
public Object get(int index)
{
int size = size();
StormNode current = head;
if((index >= size) || (index < 0))
{
throw new IndexOutOfBoundsException();
}
else
{
int counter = index;
while(counter != 0)
{
current = current.getNext();
counter--;
}
return current.getStorm();
}
}
public void add(int index, Storm Storm)
{
if((index < 0) || (index > size()))
{
throw new IndexOutOfBoundsException();
}
StormNode current = head;
StormNode previous = null;
while (index > 0)
{
index--;
previous = current;
current = current.getNext();
}
StormNode Splice = new StormNode();
Splice.setStorm(Storm);
Splice.setNext(current);
if(previous == null)
{
head = Splice;
}
else
{
previous.setNext(Splice);
}
}
public Object remove(int index)
{
if((index < 0) || (index > size()))
{
throw new IndexOutOfBoundsException();
}
StormNode current = head;
StormNode previous = null;
while (index > 0)
{
index--;
previous = current;
current = current.getNext();
}
if(previous == null)
{
head = current.getNext();
}
else
{
previous.setNext(current.getNext());
}
return current.getStorm();
}
public void removeAll()
{
head = null;
}
}
Storm.java
public class Storm{
private int year; //
private String name;
private int startDay;
private int endDay;
private int category;
public Storm(int year, String name, int startDay, int endDay, int category){
this.year = year;
this.name = name;
this.startDay = startDay;
this.endDay = endDay;
this.category = category;
}
public Storm()
{
this.year = 0;
this.name = "";
this.startDay = 0;
this.endDay = 0;
this.category = 7;
}
public String getName()
{
return this.name;
}
public int getYear()
{
return this.year;
}
public int getStartDay()
{
return this.startDay;
}
public int getEndDay()
{
return this.endDay;
}
public int getCategory()
{
return this.category;
}
public String getFormattedStartDay()
{
String startDayReturn = "";
if (this.startDay == 9999)
{
startDayReturn = "(no start)";
}
else
{
int startDayDigit1 = (this.startDay / 1000) % 10;
int startDayDigit2 = (this.startDay / 100) % 10;
int startDayDigit3 = (this.startDay / 10) % 10;
int startDayDigit4 = this.startDay % 10;
startDayReturn = (startDayDigit1 + startDayDigit2 + "/" + startDayDigit3 + startDayDigit4);
}
return startDayReturn;
}
public String getFormattedEndDay()
{
String endDayReturn = "";
if(this.endDay == 9999)
{
endDayReturn = "(no end)";
}
else
{
int endDayDigit1 = (this.endDay / 1000) % 10;
int endDayDigit2 = (this.endDay / 100) % 10;
int endDayDigit3 = (this.endDay / 10) % 10;
int endDayDigit4 = this.endDay % 10;
endDayReturn = (endDayDigit1 + endDayDigit2 + "/" + endDayDigit3 + endDayDigit4);
}
return endDayReturn;
}
public String getFormattedCategory()
{
int cat = this.category;
String categoryReturn = "";
switch(cat){
case 0:
categoryReturn = "Tropical Storm";
break;
case 1:
categoryReturn = "Hurricane Level 1";
break;
case 2:
categoryReturn = "Hurricane Level 2";
break;
case 3:
categoryReturn = "Hurricane Level 3";
break;
case 4:
categoryReturn = "Hurricane Level 4";
break;
case 5:
categoryReturn = "Hurricane Level 5";
break;
case 6:
categoryReturn = "Hurricane Level 6";
break;
default:
categoryReturn = "no info";
break;
}
return categoryReturn;
}
}
申し訳ありません。ご協力いただきありがとうございます!