将整个代码放到while(){}中,然后增加一个boolean变量控制while的循环。随后会贴出修改后的源码。
//代码修改如下,带有//的行为我添加的代码。
//import javautilScanner;
public class New {
public static void main(String[] args) {
// TODO Auto-generated method stub
// 初始化
boolean next = true;
//while (next) {
Systemoutprintln("您好!欢迎使用车票自动贩售系统!");
Systemoutprintln("查询线路请按1");
Systemoutprintln("计算里程数请按2");
Systemoutprintln("购票请按3");
//Systemoutprintln("退出请按4");
Scanner in = new Scanner(Systemin);
int type = innextInt();
switch (type) {
case 1:
Systemoutprintln("线路信息");
break;
case 2:
Systemoutprintln("里程数");
break;
case 3:
Systemoutprintln("请输入您的路程里数:");
Systemoutprintln("若不超过20公里为15元每公里;若超过20公里为2元每公里");
Systemoutprintln("不足一公里按一公里计算,请输入整数公里数");
double a = innextInt();
if (a >= 20)
Systemoutprintln("需收金额为:" + a 2);
else
Systemoutprintln("需收金额为:" + a 15);
Systemoutprintln("请投币;");
int bill = innextInt();
Systemoutprintln("正在验钞请稍后。。。");
Systemoutprintln("收入金额为:" + bill);
if (a >= 20)
Systemoutprintln("需收金额为:" + a 2);
else
Systemoutprintln("需收金额为:" + a 15);
if (a >= 20)
Systemoutprintln("找零:" + (bill - (a 2)));
if (a < 20)
Systemoutprintln("找零:" + (bill - (a 15)));
Systemoutprintln("是否确认购买?");
Systemoutprintln("确认请按1,取消请按2!");
int s = innextInt();
if (s == 1)
Systemoutprintln("请稍后,正在为您打印车票。。。");
if (s != 1)
Systemoutprintln("购买请求已取消!");
break;
//case 4:
//next = false;
//break;
default:
Systemoutprintln("对不起,您输入的代码有误,请重新输入!");
}
}
//}
}
public class Yugi implements Runnable
{
@Override
public void run()
{
String name = ThreadcurrentThread()getName();
while(namestartsWith("窗口"))
{
if(ticketslength == 0)
{
stop();
break;
}
int num = (int) (Mathrandom() ticketslength) + 1;
tickets = new int[ticketslength - num];
Systemoutprintln(name + " 售出了 " + num + " 张票");
try
{
Threadsleep(500);
}
catch(InterruptedException e)
{}
}
}
public synchronized void start()
{
for(int i = 0; i < tslength; i++)
{
Thread thread = ts[i];
if(thread == null)
{
thread = new Thread(this);
threadsetPriority(ThreadMIN_PRIORITY);
threadsetName("窗口" + (i + 1));
threadstart();
}
}
}
public synchronized void stop()
{
for(int i = 0; i < tslength; i++)
{
Thread thread = ts[i];
if(thread != null)
{
threadinterrupt();
}
thread = null;
}
notifyAll();
}
static int[] tickets = new int[100];
private static int WIN = 5;
Thread[] ts = new Thread[WIN];
public static void main(String[] args)
{
new Yugi()start();
}
}
//第一题的答案:
import javautilScanner;
public class test {
public static void main(String[] args)
{
Systemoutprintln("输入购买金额:");
Scanner input=new Scanner(Systemin);
double a=inputnextDouble();
Systemoutprintln("输入顾客类型(会员或普通):");
String b=inputnext();
if(b=="会员")
{
if(a>=100)
{
a=a08;
Systemoutprintln("需付款:"+a);
}
else
{
Systemoutprintln("需付款:"+a);
}
}
if(b=="普通")
{
if(a>=200)
{
a=a075;
Systemoutprintln("需付款:"+a);
}
else
{
Systemoutprintln("需付款:"+a);
}
}
}
}
//下面是第二题答案:
public class test {public static void main(String[] args)
{
for(int i = 0; i < 3; i++)
{
for(int x = i + 1; x < 3; x++)
{
Systemoutprint(" ");
}
for(int y = 0; y < (i + 1) 2 - 1; y++)
{
Systemoutprint("");
}
Systemoutprintln();
}
for(int i = 0; i < 4; i++)
{
for(int x = 0; x < i; x++)
{
Systemoutprint(" ");
}
for(int y = i; y < 2 4 - i - 1; y++)
{
Systemoutprint("");
}
Systemoutprintln();
}
}
}
第一个:
import javautilScanner;
/
Created by Chen on 2015/11/11
/
public class T {
public static void main(String[] args) {
int temp = 0;
Scanner s = new Scanner(Systemin);
Systemoutprint("请输入3个整数");
int a = snextInt();
int b = snextInt();
int c = snextInt();
if (a > b) {
temp = a;
a = b;
b = temp;
}
if (a > c) {
temp = a;
a = c;
c = temp;
}
if (b > c) {
temp = b;
b = c;
c = temp;
}
Systemoutprintln("a的值:" + a + "b的值:" + b + "c的值:" + c);
}
}
第二题:
import javautilScanner;
/
Created by Chen on 2015/11/11
/
public class T {
public static void main(String[] args) {
int temp = 0;
Scanner s = new Scanner(Systemin);
Systemoutprint("输入一个数");
int a = snextInt();
if((a%3==0)||(a%5==0))
Systemoutprintln("该整数是3或5的倍数");
else Systemoutprintln("“该数不能被3或5中的任何一个数整除" );
}
}
第三题:
import javautilScanner;
/
Created by Chen on 2015/11/11
/
public class T {
public static void main(String[] args) {
int price = 5000;
Scanner s = new Scanner(Systemin);
Systemoutprint("输入订票月份:");
int month = snextInt();
if (month > 0 && month < 13) {
if (month > 3 && month < 11) {
Systemoutprintln("该月车票价格如下:头等舱" + price 09 + "元" + " " + "经济舱" + price 08);
} else Systemoutprintln("该月车票价格如下:头等舱" + price 05 + "元" + " " + "经济舱" + price 04);
} else Systemoutprintln("请输入正确的月份");
}
}
以上就是关于用java做了一个收费的系统,选择选项后怎么回退到程序刚开始呢全部的内容,包括:用java做了一个收费的系统,选择选项后怎么回退到程序刚开始呢、用java实现卖电影票的程序,实现5个窗口同时售卖100张票.(用数组保存)、求大神帮忙,谢谢!!!!!(要Java代码)等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)