【发布时间】:2014-11-16 23:55:30
【问题描述】:
大家好,我在实现这个特定问题时遇到了麻烦。每次我向列表添加订阅时,检查是否需要更新“minYear”和“maxYear”。稍后使用“minYear”和“maxYear”检查请求的订阅期是否有效。基本上我正在尝试确定订阅链接列表的年份范围。
Class SubscriptionYear:首先读取特定国家的年份和蜂窝数据。这是从文件中读取的。它需要年份和该年份的统计数据。
下面是我的 SubscriptionYear 代码:
public class SubscriptionYear {
private int year;
private double subscriptions;
SubscriptionYear next;
//stores the year and it's statistical data.
public SubscriptionYear(int year,double subscriptions)
{
setYear(year);
setSubscription(subscriptions);
this.next = null;
}
//sets the year
public void setYear(int Year)
{
this.year= Year;
}
//sets the cellular data.
public void setSubscription(double value)
{
this.subscriptions = value;
}
public int getYear()
{
return year;
}
//returns the stat data
public double getSubscription()
{
return subscriptions;
}
public String toString()
{
return "Number of Subscriptions: "+subscriptions;
}
//sets the node
public void setNode(SubscriptionYear next)
{
this.next = next;
}
public SubscriptionYear getNext()
{
return this.next;
}
}
类国家: 这读取国家名称并充当对象节点 SubscripitpnYear 的容器,用于存储年份和统计数据。它有变量字段 minYear 和 maxYear 来检查订阅何时添加到列表中是否需要更新。使用 minYear 和 maxYear 检查请求的订阅是否有效。这是我在将 SusbcriptionYear 添加到列表时遇到困难的地方 我如何检查是否需要更新 minYear 和 maxYear?并使用 minYear 和 maxYear 来检查订阅是否有效?
我的班级国家:
public class Country {
//variable fields.
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.
public void addSubscriptionYear(int year, double subscription)
{
SubscriptionYear newNode = new SubscriptionYear(year, subscription);
if(this.isEmpty())
{
newNode.setNode(subscriptions);
subscriptions = newNode;
}
else{
SubscriptionYear current = subscriptions;
while(current.getNext()!=null)
{
current = current.getNext();
}
current.setNode(newNode);
}
}
//need help implementing this function
public void update(int minYear, int maxYear)
{
}
//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;
}
//overrides the equals method and returns country name if found
public boolean equals(Object obj)
{
return this.countryNames.equalsIgnoreCase(((Country) obj).getName());
}
public boolean isEmpty()
{
return (subscriptions == null);
}
【问题讨论】:
-
欢迎来到 Stack Overflow!您可能希望将您发布的内容提炼成更集中的内容。想象一下,你正在给你的同事写一封电子邮件。我们很难阅读段落和段落并弄清楚您想要什么。给出几句话的背景,解释你需要什么,然后明确地陈述你的问题。这样,我们就能更轻松地为您提供帮助。
-
还有 LALA... 当人们努力回答你的问题时,你应该选择一个“正确”的答案。哎呀,有一天你可能会试图回答一些帖子。
-
@BrianT。抱歉,我是堆栈溢出的新手。会确保这样做
-
@AlexK 感谢您的建议,因为我已经修改了问题并且更加明确。但是这个问题将如何解决。我最初解决这个问题的想法或概念是一种类似的数组越界方法。但是由于我们正在处理列表,所以它完全不同。我的想法是否正确
-
@BrianT。为了解决这个问题,我解决这个问题的最初想法或概念是一种类似的数组越界方法。但是由于我们正在处理列表,所以它完全不同。我的想法是否正确