股票补仓计算机在线计算,股票计算器在线计算

这么快就课程设计了?? 呵呵 看到我以前交作业的也苦苦求代码上弄了近1个小时终于弄出来了 我简单调试了你举的那个例子 没问题 其他的你自己调试吧

import java.io.*;

import java.util.*;

public class QueueTest {

public int value;

public int num;

public QueueTest(int value, int num) {

this.value = value;

this.num = num;

}

public static void main(String args[]) {

Queue list = new LinkedList();

InputStreamReader isr = null;

BufferedReader br = null; //从命令行读取数据用的

try {

while(true) {

System.out.println("1 买股票");

System.out.println("2 卖股票");

System.out.println("3 退出");

isr = new InputStreamReader(System.in);

br = new BufferedReader(isr);

int i = -1;

int value = 0;

int num = 0;

try {

i = Integer.parseInt(br.readLine()); //读取命令操作代号

} catch(NumberFormatException ne) {

System.out.println("输入错误");

}

if(i == 1) {

System.out.println("请输入股价");

isr = new InputStreamReader(System.in);

br = new BufferedReader(isr);

try {

value = Integer.parseInt(br.readLine());

} catch(NumberFormatException ne) {

System.out.println("输入错误");

continue; //读取所输入股价 股票数目

}

System.out.println("请输入买入数目");

isr = new InputStreamReader(System.in);

br = new BufferedReader(isr);

try {

num = Integer.parseInt(br.readLine());

} catch(NumberFormatException ne) {

System.out.println("输入错误");

continue;

}

list.add(new QueueTest(value, num)); //向队列中加入购股记录

} else if(i == 2) {

int income = 0;

System.out.println("请输入股价");

isr = new InputStreamReader(System.in);

br = new BufferedReader(isr);

try {

value = Integer.parseInt(br.readLine());

} catch(NumberFormatException ne) {

System.out.println("输入错误");

continue;

}

System.out.println("请输入卖出数目");

isr = new InputStreamReader(System.in);

br = new BufferedReader(isr);

try {

num = Integer.parseInt(br.readLine());

} catch(NumberFormatException ne) {

System.out.println("输入错误"); //与上同

continue;

}

while (list.peek() != null) {

QueueTest t = (QueueTest)list.peek();

if(t.num > num) {

t.num -= num;

income += num * (value - t.value);

System.out.println("收益是:" + income);

break; //当购股记录股数大于卖出剩余量时,添加收益,退出队列访问

} else {

num -= t.num;

income += t.num * (value - t.value);

list.poll(); //当购股记录股数大于卖出剩余量时,添加收益,继续访问

}

}

if (list.peek() == null) { //现存股总数小于卖出数,将存货全卖出,输出还需要但没卖出的股数以及收益

System.out.println("已将剩余全部股票卖出,还缺少卖出股票数目:" + num);

System.out.println("收益是:" + income);

}

} else if(i == 3) {

return;

} else {

System.out.println("输入错误");

}

}

} catch(IOException e) {

e.printStackTrace();

} finally {

try {

if(br != null) br.close();

if(isr != null) isr.close();

} catch(IOException e) {

e.printStackTrace();

}

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值