
Java编测试程序
publicclassJiaQi{publicinterfaceInterface1{publicabstractvoidArrayStack();publicabstr...
public class JiaQi
{
public interface Interface1
{
public abstract void ArrayStack ();
public abstract boolean isEmpty();
public abstract void makeEmpty();
public abstract int top();
public abstract void pop();
public abstract int topAndPop();
public abstract void push(int x);
public static final int DEFAULT_CAPACITY = 10;
}
public static void main(String[] args)
{
//System.out.println("Hello World!");
class text implements Interface1
{
private int[] theArray;
private int topOfStack;
public void ArrayStack()
{
theArray = new int[DEFAULT_CAPACITY];
topOfStack = -1;
}
public boolean isEmpty()
{
return topOfStack == -1;
}
public void makeEmpty()
{
topOfStack = -1;
}
public void push(int x)
{
if(topOfStack + 1 == theArray.length)
System.out.println("over flow");
else
theArray[++topOfStack] = x;
}
public int top()
{
if(isEmpty())
System.out.println("the ArrayStack is empty");
//else
return theArray[topOfStack];
}
public void pop()
{
if(isEmpty())
System.out.println("the ArrayStack is empty");
else
topOfStack--;
}
public int topAndPop()
{
if(isEmpty())
System.out.println("the ArrayStack is empty");
//else
return theArray[topOfStack--];
}
}
}
}
---------------------------
这个程序怎么编测试程序呀?
还有就是怎么把传参int改成object型,
希望具体解释下原因。
在此致谢了。 展开
{
public interface Interface1
{
public abstract void ArrayStack ();
public abstract boolean isEmpty();
public abstract void makeEmpty();
public abstract int top();
public abstract void pop();
public abstract int topAndPop();
public abstract void push(int x);
public static final int DEFAULT_CAPACITY = 10;
}
public static void main(String[] args)
{
//System.out.println("Hello World!");
class text implements Interface1
{
private int[] theArray;
private int topOfStack;
public void ArrayStack()
{
theArray = new int[DEFAULT_CAPACITY];
topOfStack = -1;
}
public boolean isEmpty()
{
return topOfStack == -1;
}
public void makeEmpty()
{
topOfStack = -1;
}
public void push(int x)
{
if(topOfStack + 1 == theArray.length)
System.out.println("over flow");
else
theArray[++topOfStack] = x;
}
public int top()
{
if(isEmpty())
System.out.println("the ArrayStack is empty");
//else
return theArray[topOfStack];
}
public void pop()
{
if(isEmpty())
System.out.println("the ArrayStack is empty");
else
topOfStack--;
}
public int topAndPop()
{
if(isEmpty())
System.out.println("the ArrayStack is empty");
//else
return theArray[topOfStack--];
}
}
}
}
---------------------------
这个程序怎么编测试程序呀?
还有就是怎么把传参int改成object型,
希望具体解释下原因。
在此致谢了。 展开
展开全部
把接口里的int型都换成object型 然后实现类里也一样
测试程序就是接口声明 实现类实例化 然后调用方法
测试程序就是接口声明 实现类实例化 然后调用方法
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你这个程序还是错的啊,汗,
Integer I=new Integer(i);这个I是对象,
用JAVA的封装类.
Integer I=new Integer(i);这个I是对象,
用JAVA的封装类.
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Integer I=new Integer(i);这个I是对象,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询