黑马程序员技术交流社区
标题:
hello,thank you ,thank you very much!hello,thank you ,thank you very much!!
[打印本页]
作者:
AsialJim
时间:
2018-7-17 19:47
标题:
hello,thank you ,thank you very much!hello,thank you ,thank you very much!!
are you ok?
这个,发点啥,一首来自雷军的are you ok?送给你!!!
然后第三天的个人代码奉上!
package StockTrade;
/**
* @version 1.0.2
* @author asialjim
* @这是一个模拟的股票买卖程序
*/
public class StockTrade extends defaultData
{
public static void main(String args[])
{
Sighin sighin1 = new Sighin();
//如果通过,执行下列程序,如果不通过,程序结束。
if(sighin1.sighIn(ID,password)==true) {
//veiw() ;
ChooseFunction choose =new ChooseFunction();
choose.choosefunction();
}else {
exit();
System.out.println();
}
}
}
package StockTrade;
import java.util.Scanner;
public class defaultData {
Scanner input =new Scanner(System.in);
//初始化股票账户
static String stockID;
static String ID="asialjim";
//初始化股票密码
static String stockPassword;
static String password="zengbo1026";
static String stock="000301";
static double stockPrice=1;
static int totalMoumt=100000000;
static double stockValue;
static int tradeNum;
static int buyNum;
static int saleNum;
static double tradeMoney;
static double buyPrice;
static double salePrice;
public static void valueUpdate() {
stockValue=stockPrice*totalMoumt; //当前市值等于当前股价乘以总股份
}
public static void tradeMoneyUpdate() {
tradeMoney=stockPrice*tradeNum; //交易额等于当前股价乘以交易量
}
public static void veiw()
{
System.out.println("代码\t价格\t总量\t市值\t成交量\t成交额");
System.out.println(stock+"\t"+stockPrice+"\t"+totalMoumt+"\t"
+stockValue+"\t"+tradeNum+"\t"+tradeMoney);
}
public static void exit()
{
System.out.println("你已经登出系统!");
System.out.println("系统即将关闭!请按任意键退出");
Scanner input = new Scanner(System.in);
/*String x =*/input.next();
//System.out.println();
}
}
package StockTrade;
import java.util.Scanner;
public class trade extends defaultData{
Scanner input =new Scanner(System.in);
public void buystock()
{
System.out.print("请输入你要委托买入的价格:");
buyPrice=input.nextDouble();
System.out.print("请输入你要委托买入的数量:");
buyNum=input.nextInt();
System.out.println("委托成功,委托单价:"+buyPrice+"\t委托数量:"+buyNum);
trade();
//valueUpdate();
//veiewTrade();
//tradeNumUpdate();
}
public void salestock()
{
System.out.print("请输入你要委托卖出的价格:");
salePrice=input.nextDouble();
System.out.print("请输入你要委托卖出的数量:");
saleNum=input.nextInt();
trade();
//valueUpdate();
//veiewTrade();
//tradeNumUpdate();
}
public void trade()
{
//valueUpdate();
//veiewTrade();
//判断成交
if(buyNum==0 && saleNum==0)
{
System.out.println("暂无买入或者卖出委托!");
}else if(buyPrice>=salePrice && buyNum!=0 && saleNum!=0)
{
stockPrice=(buyPrice+salePrice)/2; //成交价:当买入价格高于卖出价格时,成交价为两者之间的平均值,否则不成交
tradeNum=buyNum<=saleNum ? buyNum : saleNum; //交易量取决于买卖委托量当中较小值
}//else
//{
//System.out.println("暂无成交!");
//}
valueUpdate();
tradeMoneyUpdate();
veiewTrade();
tradeNumUpdate();
veiewEnTrust();
}
public void veiewTrade()
{
//显示当前交易情况
System.out.println("当前交易情况:");
System.out.println("买入价\t买入量\t \t卖出价\t卖出量\t \t成交量\t \t成交额\t \t当前股价\t当前市值" );
System.out.println(buyPrice+"\t"+buyNum+"\t \t"+salePrice+"\t"+saleNum
+"\t \t"+tradeNum+"\t \t"+tradeMoney+"\t \t"+stockPrice+"\t"+stockValue/10000+"万元");
}
public void veiewEnTrust() {
System.out.println("当前交易委托情况:");
System.out.println("买入价\t买入量\t \t卖出价\t卖出量\t \t成交量\t \t成交额\t \t当前股价\t当前市值" );
System.out.println(buyPrice+"\t"+buyNum+"\t \t"+salePrice+"\t"+saleNum
+"\t \t"+tradeNum+"\t \t"+tradeMoney+"\t \t"+stockPrice+"\t"+stockValue/10000+"万元");
}
public void tradeNumUpdate() {
if(buyNum<=saleNum) {
saleNum=saleNum-buyNum;
buyNum=0;
}else {
buyNum=buyNum-saleNum;
saleNum=0;
}
}
//委托量更新
}
package StockTrade;
import java.util.Scanner;
public class ChooseFunction
{
public void choosefunction()
{
for(; ; )
{
System.out.println("请输入你要选择的功能:");
System.out.println("【buy】 【sale】 【changepwd】 【sighout】 ");
Scanner input =new Scanner(System.in);
String choose=input.next();
if(choose.equals("buy")) {
trade trade = new trade();
trade.buystock();
}else if (choose.equals("sale")) {
trade trade = new trade();
trade.salestock();
}else if (choose.equals("changepwd")) {
changePwd chpwd=new changePwd();
chpwd.changePassword();
}
else if (choose.equals("sighout")) {
StockTrade.exit();
break;
}
}
}
}
package StockTrade;
import java.util.Scanner;
public class changePwd extends defaultData{
public void changePassword(){
//初始化密码的问题,链接数据库
//String password="zengbo1026"; //初始化账户密码关键
for(int i=1 ;i<=3 ;i++ ) {
Scanner input =new Scanner(System.in);
System.out.println("请输入你要修改的密码" );
String password1 ;
String password2 ;
password1=input.next();
System.out.println("请再输入一次" );
password2=input.next();
if(password1.equals(password2)) {
password=password1;
System.out.println("密码修改成功");
System.out.println("请重新登录");
//重新执行主程序main方法
StockTrade backMain = new StockTrade();
StockTrade.main(null);
break;
}else {
System.out.println("输入错误,请重新修改密码");
}
System.out.println("你修改次数已达三次,请关闭程序,重新开始 ");
}
}
}
package StockTrade;
import java.util.Scanner;
public class Sighin extends defaultData
{
//public void sighIn(String ID, String password)
public boolean sighIn(String ID, String password)
{
Scanner input =new Scanner(System.in);
boolean b=false;
for(int i=1;i<=3 ;i++ )
{
System.out.print("请输入账号:");
String stockID=input.next();
System.out.println();
System.out.print("请输入账号密码:");
String stockPassword=input.next();
if(stockID.equals(ID) && stockPassword.equals(password))
{
System.out.println("欢迎登入简易股票交易系统!");
b = true;
break;
}
else if (i==3) {
System.out.println("你连续输入错误三次,账户已锁定,请联系运营商解锁!");
b = false;
}
else{
System.out.println("你输入错误请重新输入!");
System.out.println();
continue;
}
}
return b;
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2