資源簡介
1)輸入三個整數a、b、c,分別作為三角形的三條邊,通過程序判斷這三條邊是否能構成三角形?如果能構成三角形,則判斷三角形的類型(等邊三角形、等腰三角形、一般三角形)。要求輸入三個整數a、b、c,必須滿足以下條件:1≤a≤100;1≤b≤100;1≤c≤100。
要求:
a.大家用自己熟悉的編程語言,實現上面問題的描述。
b.請用等價類設計測試用例。

代碼片段和文件信息
import?java.awt.*;
import?java.awt.event.*;
import?javax.swing.*;
public?class?SanTest?extends?frame?
{
Jting?Panduan=new?Jting();
Button?b1?=?new?Button(“判斷“);
Button?b2?=?new?Button(“退出“);
WindowClose2?Tuichu?=?new?WindowClose2();
TextField?txt1?=?new?TextField(30);
TextField?txt2?=?new?TextField(30);
TextField?txt3?=?new?TextField(30);
int?a?b?c;
public?SanTest()?
{
super(“判斷三角形“);
this.setSize(300?300);
this.setLocation(300?200);
this.setForeground(Color.black);
this.setBackground(Color.white);
this.setLayout(new?FlowLayout());
this.add(new?Label(“a:“));
this.add(txt1);
this.add(new?Label(“b:“));
this.add(txt2);
this.add(new?Label(“c:“));
this.add(txt3);
add(b1);
b1.addActionListener(Panduan);
add(b2);
b2.addActionListener(Tuichu);
this.addWindowListener(new?WindowClose1());
this.setVisible(true);
}
class?Jting?implements?ActionListener?
{
public?void?actionPerformed(ActionEvent?e)?
{
if?(e.getSource()==b1)?
{
getABC();
txt1.setText(““);
txt2.setText(““);
txt3.setText(““);
if?(!(a>0&&a<101&&b>0&&b<101&&c>0&&c<101))
{
JOptionPane.showMessageDialog(b1?“邊不是1-100之間的數,請重輸:“);
}
else
{
if((a+b>c&&a-bb&&a-ca&&b-c {
if(a==b&&b==c&&a==c)
???JOptionPane.showMessageDialog(b1?“等邊三角形!“);
else?
????????if(a==b||b==c||a==c)
??????JOptionPane.showMessageDialog(b1?“等腰三角形!“);
????????else
??????JOptionPane.showMessageDialog(b1?“一般三角形!“);
}
else
JOptionPane.showMessageDialog(b1?“非三角形!“);
}
}
}
}
public?void?getABC()
{
try
{
a?=?Integer.parseInt(txt1.getText().trim());
b?=?Integer.parseInt(txt2.getText().trim());
c?=?Integer.parseInt(txt3.getText().trim());
}
catch?(Exception?ex)
{
JOptionPane.showMessageDialog(b1?“請將邊abc輸入整數!“);
}
}
class?WindowClose1?extends?WindowAdapter?
{
public?void?windowClosing(WindowEvent?e)?
{
System.exit(0);
}
}
class?WindowClose2?implements?ActionListener?
{
public?void?actionPerformed(ActionEvent?e)?
{
if?(e.getSource()?==?b2)
{
System.exit(0);
}
}
}
public?static?void?main(String?args[])
{
SanTest?aa?=?new?SanTest();
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1531??2011-04-28?07:10??測試三角形\SanTest$Jting.class
?????文件????????474??2011-04-28?07:10??測試三角形\SanTest$WindowClose1.class
?????文件????????656??2011-04-28?07:10??測試三角形\SanTest$WindowClose2.class
?????文件???????2341??2011-04-28?07:10??測試三角形\SanTest.class
?????文件???????2450??2013-03-21?14:23??測試三角形\SanTest.java
?????文件??????74752??2013-03-21?14:11??測試三角形\黑盒測試-三角形.doc
?????目錄??????????0??2013-03-21?14:22??測試三角形
-----------?---------??----------?-----??----
????????????????82204????????????????????7
- 上一篇:2.5分頻 verilog
- 下一篇:操作系統課后習題答案完整詳細
評論
共有 條評論