请大家帮忙,小弟弟在这里先谢了。

learsu 2008-03-27 10:10:07
Demonstration.java and Maths.java files.




Part 1
You are to write a StockItem class.



The attributes of StockItem are:

<!--[if !supportLists]-->· <!--[endif]-->A unique Identifier which is a String.

<!--[if !supportLists]-->· <!--[endif]-->A name which is a String

<!--[if !supportLists]-->· <!--[endif]-->A stock quantity which is a whole number

<!--[if !supportLists]-->· <!--[endif]-->A unit price which is a double



The methods of StockItem are:

<!--[if !supportLists]-->· <!--[endif]-->A constructor which allows input of attribute values

<!--[if !supportLists]-->· <!--[endif]-->display() to show the record in a window

<!--[if !supportLists]-->· <!--[endif]-->a toString() method



All input should be validated using the try and catch mechanism

display() should use a textArea and showMessageDialog() method for output.

The toString() method will be required as usual.



Note that you will not need tio.*





Part 2



Write a SList class, a list of StockItems

Slist should use only javax.swing components.

All input and output should be through the gui interface.

All input should be validated by the try catch mechanism.

In addition the operations of adding to a full list and finding non existent objects, should also use the try catch method.



Part 3

You must write a FrontEnd class which uses the other classes and GUIInput.java to produce a menu which presents the options of



<!--[if !supportLists]-->· <!--[endif]-->Add to the list

<!--[if !supportLists]-->· <!--[endif]-->Display the list

<!--[if !supportLists]-->· <!--[endif]-->Quit



Part 4

The functionality of delete() should be added to the Slist class and a new option should be added to the FrontEnd class to add the delete() function. Delete should request a reference, and the Item with that reference should be removed.
...全文
102 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
a_nuo 2008-03-27
  • 打赏
  • 举报
回复
我把程序改了一下
import javax.swing.*;
import java.io.*;
public class StockItem
{
private final String str;
private String a=" ";
private String name;
private int num;
private double price;
public StockItem(){
BufferedReader dataIn= new BufferedReader(new InputStreamReader(System.in));
try {
System.out.println("please input a String!");

a=dataIn.readLine();

System.out.println("please input a name!");
name=dataIn.readLine();
System.out.println(name);
System.out.println("please input a Integer!");
num=Integer.parseInt(dataIn.readLine());
System.out.println("please input a price(double)!");
price=Double.parseDouble(dataIn.readLine());
}
catch (IOException ex) {
System.out.println(ex);
}
str=a;
}
public void display(){
JOptionPane.showMessageDialog(null,""+str+" "+name+" "+num+" "+price,"nei bu xin xi!",JOptionPane.DEFAULT_OPTION);
}
public static void main(String[] args)
{
StockItem a=new StockItem();
a.display();
}
public String toString(){
return super.toString();
}
}
a_nuo 2008-03-27
  • 打赏
  • 举报
回复
Part1
import javax.swing.*;
public class StockItem
{
private final String str;
private String name;
private int num;
private double price;
public StockItem(){
this.str=JOptionPane.showInputDialog("please input a String!");
this.name=JOptionPane.showInputDialog("please input a name!");
this.num=Integer.parseInt(JOptionPane.showInputDialog("please input a Integer!"));
this.price=Double.parseDouble(JOptionPane.showInputDialog("please input a price!"));
}
public void display(){
JOptionPane.showMessageDialog(null,""+str+" "+name+" "+num+" "+price,"nei bu xin xi!",JOptionPane.DEFAULT_OPTION);
}
public static void main(String[] args)
{
StockItem a=new StockItem();
a.display();
}
public String toString(){
return super.toString();
}
}

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧