안녕하십니까. 링크 된 목록에서 연도의 범위를 결정하려고하는데 도움이 필요합니다. 이것을 달성하기 위해 나는 subscYears 링크 된 목록을 보유하고있는 컨테이너 클래스에 minYear 및 maxYear라는 2 개의 변수를 가지고 있습니다. SubscriptionYear는 해당 연도의 연도 및 셀룰러 데이터를 읽습니다. 클래스 국가는 국가 이름을 저장하고 각 국가의 연도 및 셀룰러 데이터를 저장하는 linked list subscriptionYear의 컨테이너입니다.링크 된 목록의 연도 범위 결정
minYear는 9999로 설정되고 maxYear는 0으로 설정됩니다. 목록에 구독을 추가 할 때마다 minYear 및 maxYear를 업데이트합니다. 그리고 "minYear"와 "maxYear"를 사용하여 요청한 가입 기간이 유효한지 확인합니다. 요청한 구독이 유효한지 확인하기 위해 minYear 및 maxYear를 어떻게 구현합니까?
내 수업 Subscriptionyear는 해당 연도의 연도 및 셀룰러 데이터를 이중으로 저장합니다.
//stores the year and statistical subscription data for that year
public class SubscriptionYear {
private int year;
private double subscriptions;
SubscriptionYear next;
public SubscriptionYear(int year,double subscriptions)
{
setYear(year);
setSubscription(subscriptions);
this.next = null;
}
public void setYear(int Year)
{
this.year= Year;
}
public void setSubscription(double value)
{
this.subscriptions = value;
}
public int getYear()
{
return year;
}
public double getSubscription()
{
return subscriptions;
}
public String toString()
{
return "Number of Subscriptions: "+subscriptions;
}
public void setNode(SubscriptionYear next)
{
this.next = next;
}
public SubscriptionYear getNext()
{
return this.next;
}
}
수준의 나라 : 내 클래스 국가 국가의 이름을 저장하고 해당 국가 연도와 통계 정보를 포함 susbcriptionYear의 연결리스트에 대한 컨테이너 역할을합니다. 목록을 만들고 성공적으로 목록을 인쇄 할 수 있었지만 위의 해결 된 문제를 해결할 수 없습니다. Country
객체가 minYear=9999
및 maxYear=0
와 함께, 당신은 비교 및 검증을 수행 할 Country.addSubscription()
방법을 업데이트 할 수 있습니다 인스턴스화해야하는 과제에 제약이 있기 때문에 통계 데이터 1960 년에서 2012 년
public class Country {
private String countryNames;
private SubscriptionYear subscriptions;
private int minYear;
private int maxYear;
public Country(String country)
{
this.countryNames = country;
this.subscriptions = null;
this.maxYear = 0;
this.minYear = 9999;
}
//adds the subscription and updates the minYear and maxYear
//Dont think i set up the minYear and maxYear correctly.
public void addSubscriptionYear(int year, double subscription)
{
SubscriptionYear newNode = new SubscriptionYear(year, subscription);
if(this.isEmpty())
{
newNode.setNode(subscriptions);
subscriptions = newNode;
if(newNode.getYear()==1960)
{
this.minYear++;
}
}
else{
SubscriptionYear current = subscriptions;
while(current.getNext()!=null)
{
if(current.getYear()==1960)
{
this.minYear++;
}
else if(current.getYear()==2012)
{
this.maxYear++
}
current = current.getNext();
}
current.setNode(newNode);
}
}
//overrides the toString method and prints out the countries.
public String toString()
{
String result="";
result += "\n"+this.countryNames;
SubscriptionYear current = subscriptions;
while(current!=null)
{
result+="\t"+current.getSubscription();
current = current.getNext();
}
return result;
}
//returns countryName
public String getName()
{
return this.countryNames;
}
public boolean isEmpty()
{
return (subscriptions == null);
}
}
가입 기간 중 가장 이른 연도와 가장 최근 연도를 찾으십니까? 또는 1960 년과 2012 년에 구독이 몇 개인 지 계산하려고합니까? 또한이 컴파일 오류가 발생 했습니까? –
@DavidWallace와 같은 질문을 할 것입니다. 또한 호기심을 위해서 왜 LinkedList 클래스를 사용하여 몇 년 동안의 목록을 유지하고 있지 않습니까? – working
@RJadhav 이것은 교수의 프로젝트였습니다. 우리는 그녀의 지침을 따라야했습니다. 그녀는 API –