日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java 自动化测试_java写一个自动化测试

發布時間:2023/12/9 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 自动化测试_java写一个自动化测试 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

你模仿購物車試一下,同樣是買東西,加上勝負平的賠率,輸出改下應該就可以了

package com.homework.lhh;

import java.util.ArrayList;

import java.util.Comparator;

import java.util.Scanner;

public class Ex04 {public?static?void?main(String[]?args)?{

ShoppingCart?shoppingcart?=?new?ShoppingCart();

@SuppressWarnings("resource")

Scanner?sc?=?new?Scanner(System.in);

System.out.println("-------------購物車系統-------------");

while?(true)?{

System.out.println("1.添加商品");

System.out.println("2.刪除商品");

System.out.println("3.修改商品");

System.out.println("4.查看商品");

System.out.println("5.退出系統");

System.out.println("請選擇您要進行的操作:");

int?num?=?sc.nextInt();

switch?(num)?{

case?1:

shoppingcart.addMerchandise();

break;

case?2:

shoppingcart.delMerchandise();

break;

case?3:

shoppingcart.alterMerchandise();

break;

case?4:

shoppingcart.showInfo();

break;

case?5:

System.out.println("退出系統成功!");

System.exit(0);

break;

}

}

}

}//?購物車類

class?ShoppingCart?{

private?int?id;//?編號

private?int?count;//?數量

private?double?price;//?價格public?int?getId()?{

return?id;

}

public?void?setId(int?id)?{

this.id?=?id;

}

public?int?getCount()?{

return?count;

}

public?void?setCount(int?count)?{

this.count?=?count;

}

public?double?getPrice()?{

return?price;

}

public?void?setPrice(double?price)?{

this.price?=?price;

}

public?ShoppingCart(int?id,?int?count,?double?price)?{

super();

this.id?=?id;

this.count?=?count;

this.price?=?price;

}

public?ShoppingCart()?{

}

ArrayList?list?=?new?ArrayList();

Scanner?sc?=?new?Scanner(System.in);

//?添加商品

public?void?addMerchandise()?{

System.out.println("請輸入商品的編號:");

setId(sc.nextInt());

System.out.println("請輸入添加的數量:");

setCount(sc.nextInt());

System.out.println("請輸入商品的價格:");

setPrice(sc.nextDouble());

list.add(new?ShoppingCart(getId(),?getCount(),?getPrice()));

System.out.println("添加商品成功");

}

//?刪除商品

public?void?delMerchandise()?{

System.out.println("請輸入商品編號:");

setId(sc.nextInt());

for?(int?i?=?0;?i?

if?(getId()?==?list.get(i).getId())?{

list.remove(i);

}

}

System.out.println("刪除編號為"?+?getId()?+?"的商品成功");

}

//?修改商品

public?void?alterMerchandise()?{

System.out.println("請輸入商品的編號:");

setId(sc.nextInt());

System.out.println("請輸入商品的更改數量:");

setCount(sc.nextInt());

System.out.println("請輸入商品的單價:");

setPrice(sc.nextDouble());

for?(int?i?=?0;?i?

if?(getId()?==?list.get(i).getId())?{

list.set(i,?new?ShoppingCart(getId(),?getCount(),?getPrice()));

}

}

System.out.println("修改商品成功");

}

//?顯示所有商品的信息

public?void?showInfo()?{

if?(list.size()?==?0)?{

System.out.println("你的購物車是空的,快去剁手吧!");

}?else?{

list.sort(new?Comparator()?{

@Override

public?int?compare(ShoppingCart?o1,?ShoppingCart?o2)?{

if?((o1.getPrice()?*?o1.getCount())?>?(o2.getPrice()?*?o2.getCount()))?{

return?1;

}?else?if?((o1.getPrice()?*?o1.getCount())?

return?-1;

}?else?{

return?0;

}

}

});

for?(ShoppingCart?shoppingcart?:?list)?{

System.out.println(shoppingcart);

}

}

}

//?輸出

@Override

public?String?toString()?{

return?"購物車?[商品編號="?+?id?+?",?商品數量="?+?count?+?",?商品單價="?+?price?+?",總價="?+?(price?*?count)?+?"]";

}

}

總結

以上是生活随笔為你收集整理的java 自动化测试_java写一个自动化测试的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。