标签:保存 oid dir 优秀 对比 xtend color sse 长度
File
-> Settings
或Ctrl + Alt + S
进入Settings页面,点击Plugins
,在搜索框内输入junit
,找到对应的工具并下载。Plugins
->junit
解压File
-> Project Structure
-> Dependancies
-> +
-> JARs or Directories
junit.jar
和junit4-12.jar
Go To
-> test
-> Creat New Test
Testing Library
选择JUnit3
并勾选Member
下所有选项New
-> Directory
-> 输入Test
Test
文件夹,Mark Directory as
-> Test Sources Rood
百分制转五分制:
如果成绩小于60,转成“不及格”
如果成绩在60与70之间,转成“及格”
如果成绩在70与80之间,转成“中等”
如果成绩在80与90之间,转成“良好”
如果成绩在90与100之间,转成“优秀”
其他,转成“错误”
public class MyUtil{
public static String percentage2fivegrade(int grade){
//如果成绩小于0,转成“错误”
if ((grade < 0))
return "错误";
//如果成绩小于60,转成“不及格”
else if (grade < 60)
return "不及格";
//如果成绩在60与70之间,转成“及格”
else if (grade < 70)
return "及格";
//如果成绩在70与80之间,转成“中等”
else if (grade < 80)
return "中等";
//如果成绩在80与90之间,转成“良好”
else if (grade < 90)
return "良好";
//如果成绩在90与100之间,转成“优秀”
else if (grade <=100)
return "优秀";
//如果成绩大于100,转成“错误”
else
return "错误";
}
}
import org.junit.Test;
import junit.framework.TestCase;
public class MyUtilTest extends TestCase {
@Test
public void testNormal() {
assertEquals("不及格", MyUtil.percentage2fivegrade(55));
assertEquals("及格", MyUtil.percentage2fivegrade(65));
assertEquals("中等", MyUtil.percentage2fivegrade(75));
assertEquals("良好", MyUtil.percentage2fivegrade(85));
assertEquals("优秀", MyUtil.percentage2fivegrade(95));
}
@Test
public void testExceptions(){
assertEquals("错误",MyUtil.percentage2fivegrade(-55));
assertEquals("错误",MyUtil.percentage2fivegrade(105));
}
@Test
public void testBoundary(){
assertEquals("不及格",MyUtil.percentage2fivegrade(0));
assertEquals("及格",MyUtil.percentage2fivegrade(60));
assertEquals("中等",MyUtil.percentage2fivegrade(70));
assertEquals("良好",MyUtil.percentage2fivegrade(80));
assertEquals("优秀",MyUtil.percentage2fivegrade(90));
assertEquals("优秀",MyUtil.percentage2fivegrade(100));
}
}
测试成功截图:
public class StringBufferDemo{
StringBuffer buffer = new StringBuffer();
public StringBufferDemo(StringBuffer buffer){
this.buffer = buffer;
}
public Character charAt(int i){
return buffer.charAt(i);
}
public int capacity(){
return buffer.capacity();
}
public int length(){
return buffer.length();
}
public int indexOf(String buf) {
return buffer.indexOf(buf);
}
}
import junit.framework.TestCase;
import org.junit.Test;
public class StringBufferDemoTest extends TestCase {
StringBuffer a1 = new StringBuffer("StringBuffer");
StringBuffer a2 = new StringBuffer("StringBufferStringBuffer");
StringBuffer a3 = new StringBuffer("StringBuffer used by 20175215");
@Test
public void testCharAt() throws Exception{//验证返回是否是整个字符串中的第x个字符
assertEquals('S',a1.charAt(0));
assertEquals('t',a2.charAt(13));
assertEquals('b',a3.charAt(18));
}
@Test
public void testcapacity() throws Exception{//验证容量
assertEquals(28,a1.capacity());
assertEquals(40,a2.capacity());
assertEquals(45,a3.capacity());
}
@Test
public void testlength() throws Exception{//验证字符串的长度
assertEquals(12,a1.length());
assertEquals(24,a2.length());
assertEquals(29,a3.length());
}
@Test
public void testindexOf(){//验证所在位置
assertEquals(6,a1.indexOf("Buff"));
assertEquals(1,a2.indexOf("tring"));
assertEquals(25,a3.indexOf("5215"));
}
}
abstract class Data {
abstract public void DisplayValue();
}
class Integer extends Data {
int value;
Integer() {
value=100;
}
@Override
public void DisplayValue(){
System.out.println (value);
}
}
class Short extends Data {
int value;
Short() {
value=5;
}
@Override
public void DisplayValue(){
System.out.println (value);
}
}
abstract class Factory {
abstract public Data CreateDataObject();
}
class IntFactory extends Factory {
@Override
public Data CreateDataObject(){
return new Integer();
}
}
class ShortFactory extends Factory {
@Override
public Data CreateDataObject(){
return new Short();
}
}
class Document {
Data pd;
Document(Factory pf){
pd = pf.CreateDataObject();
}
public void DisplayData(){
pd.DisplayValue();
}
}
public class MyDoc {
static Document d;
public static void main(String[] args) {
d = new Document(new IntFactory());
d.DisplayData();
d = new Document(new ShortFactory());
d.DisplayData();
}
}
import java.text.DecimalFormat;//引入DecimalFormat包取一位整数和一位小数
public class Complex {
double Real=0;
double Imaginary=0;
public Complex(){}
public Complex(double Real,double Imaginary){
this.Real=Real;
this.Imaginary=Imaginary;
}
public double getReal(){
return Real;
}
public double getImaginary(){
return Imaginary;
}
public String toString(){
String s = "";
double r=Real;
double i=Imaginary;
if(r==0&&i==0){
s="0";
}
else if(r==0&&i!=0){
s=i+"i";
}
else if(r!=0&&i<0){
s=r+""+i+"i";
}
else if(r!=0&&i==0){
s=r+"";
}
else
{
s=r+"+"+i+"i";
}
return s;
}
public boolean equals(Object obj){//重写equals方法,使其不用来对比字符序列
if(this==obj){
return true;
}
else
return false;
}
DecimalFormat df = new DecimalFormat( "0.0");
public Complex ComplexAdd(Complex a){
return new Complex(Real+a.getReal(),Imaginary+a.getImaginary());
}
public Complex ComplexSub(Complex a){
return new Complex(Real-a.getReal(),Imaginary-a.getImaginary());
}
public Complex ComplexMulti(Complex a){
double r=Real*a.getReal()-Imaginary*a.getImaginary();
double i =Imaginary*a.getReal()+Real*a.getImaginary();
return new Complex(Double.valueOf(df.format(r)),Double.valueOf(df.format(i)));
}
public Complex ComplexDiv(Complex a){
double r=(Real * a.Imaginary + Imaginary * a.Real) / (a.Imaginary * a.Imaginary + a.Real * a.Real);
double i=(Imaginary * a.Imaginary + Real * a.Real) / (a.Real * a.Real + a.Real * a.Real);
return new Complex(Double.valueOf(df.format(r)),Double.valueOf(df.format(i)));
}
}
mport junit.framework.TestCase;
import org.junit.Test;
public class ComplexTest extends TestCase {
Complex a1 =new Complex(3.0,4.0);
Complex a2 =new Complex( 2.0,-4.0);
Complex a3 =new Complex(0.0,0.0);
Complex a4 =new Complex(-3.0,0.0);
Complex a5 =new Complex(-6.0,-0.8);
@Test
public void testgetRealPart()throws Exception{
assertEquals(3.0,a1.getReal());
assertEquals(2.0,a2.getReal());
assertEquals(0.0,a3.getReal());
assertEquals(-3.0,a4.getReal());
assertEquals(-6.0,a5.getReal());
}
@Test
public void testgetImagePart()throws Exception{
assertEquals(4.0,a1.getImaginary());
assertEquals(-4.0,a2.getImaginary());
assertEquals(0.0,a3.getImaginary());
assertEquals(0.0,a4.getImaginary());
assertEquals(-0.8,a5.getImaginary());
}
@Test
public void testtoString()throws Exception{
assertEquals("3.0+4.0i",a1.toString());
assertEquals("2.0-4.0i",a2.toString());
assertEquals("0",a3.toString());
assertEquals("-3.0",a4.toString());
assertEquals("-6.0-0.8i",a5.toString());
}
@Test
public void testComplexAdd()throws Exception{
assertEquals("5.0",a1.ComplexAdd(a2).toString());
assertEquals("2.0-4.0i",a2.ComplexAdd(a3).toString());
assertEquals("-3.0",a3.ComplexAdd(a4).toString());
}
@Test
public void testComplexSub()throws Exception{
assertEquals("1.0+8.0i",a1.ComplexSub(a2).toString());
assertEquals("-2.0+4.0i",a3.ComplexSub(a2).toString());
assertEquals("3.0",a3.ComplexSub(a4).toString());
}
@Test
public void testComplexMulti()throws Exception{
assertEquals("22.0-4.0i",a1.ComplexMulti(a2).toString());
assertEquals("0",a2.ComplexMulti(a3).toString());
assertEquals("18.0+2.4i",a4.ComplexMulti(a5).toString());
}
@Test
public void testComplexDiv()throws Exception{
assertEquals("-0.2-1.2i",a1.ComplexDiv(a2).toString());
assertEquals("0",a3.ComplexDiv(a2).toString());
}
@Test
public void testequals()throws Exception{
assertEquals(true,a1.equals(a1));
assertEquals(false,a1.equals(a2));
}
}
模式与设计模式
模式是某外在环境(Context) 下﹐对特定问题(Problem)的惯用解决之道(Solution)。模式必须使得问题明晰,阐明为什么用它来求解问题,以及在什么情况下有用,什么情况下不能起作用,每个模式因其重复性从而可被复用,本身有自己的名字,有可传授性,能移植到不同情景下。模式可以看作对一个问题可复用的专家级解决方法。计算机科学中有很多模式:
GRASP模式
分析模式
软件体系结构模式
设计模式:创建型,结构型,行为型
管理模式: The Manager Pool 实现模式
界面设计交互模式
…
步骤 | 耗时 | 百分比 |
---|---|---|
需求分析 | 5 | 5% |
设计 | 10 | 9% |
代码实现 | 25 | 23% |
测试 | 30 | 27% |
分析总结 | 40 | 36% |
2018-2019-2 20175207 实验二《面向对象程序设计》实验报告
标签:保存 oid dir 优秀 对比 xtend color sse 长度
原文地址:https://www.cnblogs.com/ln-0407/p/10742942.html