成都创新互联网站制作重庆分公司

java票务系统代码,java编程火车购票系统代码

java编程实现景区售票规则:成人票每人10元,儿童票折半(如果儿童身高不超过1.2

这个规则就是设计一个方法,该方法最后值为一个票价,参数应该是身高,所以有如下代码

创新互联公司是一家专业提供甘孜州企业网站建设,专注与成都网站建设、成都网站设计、HTML5建站、小程序制作等业务。10年已为甘孜州众多企业、政府机构等服务。创新互联专业网站建设公司优惠进行中。

public class PriceTest {

public static void main(String[] args) {

int childPrice = getPrice(1.2);

int adultPrice = getPrice(1.5);

System.out.println("1.2米身高的票价为:"+childPrice);

System.out.println("1.5米身高的成人票价为:"+adultPrice);

}

private static int getPrice(double height) {

return height  1.2?10:5;

}

}

最后结果如下:

Java编程 假设有火车票1000张,创建10个线程模拟10个售票点,每个售票点100毫秒售出一张票。

package tmp;

public class Test {

private static int k=0;//售出票数

private static int count=1000;//总票数

private static synchronized boolean sell(int n){

if(kcount){

k++;

System.out.println("第"+n+"售票点售出第"+k+"张票");

return true;

}

return false;

}

static class SellPot extends Thread{//售票点

int n;//售票点编号

public SellPot(int n){

this.n=n;

}

public void run(){

while(sell(n)){

try {

Thread.sleep(100);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

}

public static void main(String[] args) {

for(int i=1;i=10;i++){

new SellPot(i).start();

}

}

}

//银行汇款

public class Test2 {

private static int k=0;//总汇款

private static synchronized void send(int m,int i,int n){

k+=m;

System.out.println("第"+n+"个顾客进行第"+(i+1)+"次汇款,银行接收总汇款"+k);

}

static class Costum extends Thread{//售票点

int n;//顾客编号

public Costum(int n){

this.n=n;

}

public void run(){

for(int i=0;i3;i++){

send(100,i,n);//汇款100

try {

Thread.sleep(100);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

}

public static void main(String[] args) {

for(int i=1;i=3;i++){

new Costum(i).start();

}

}

}

用JAVA编写购物系统的代码是什么?(急)

算是最简单的吧

package cn.job01;

import java.util.Scanner;

public class Lx07 {

public static void choice() {

System.out.println("登陆菜单 ");

System.out.println("1登陆系统");

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

}

static void choice1() {

System.out.println("购物管理系统客户信息");

System.out.println("1显示所有客户信息");

System.out.println("2添加客户信息");

System.out.println("3修改客户信息");

System.out.println("4查询客户信息");

}

static void choice2() {

System.out.println("购物管理系统真情回馈");

System.out.println("1幸运大放送");

System.out.println("2幸运抽奖");

System.out.println("3生日问候");

}

public static void main(String[] args) {

choice();

Scanner input = new Scanner(System.in);

System.out.println("请输入1or2");

int num = input.nextInt();

switch (num) {

case 1:

System.out.println("主菜单");

System.out.println("1客户信息管理");

System.out.println("2购物结算");

System.out.println("3真情回馈");

System.out.println("4注销");

break;

}

System.out.println("选择输入数字");

int num1 = input.nextInt();

switch (num1) {

case 1:

choice1();

break;

case 2:

System.out.println("购物结算");

break;

case 3:

choice2();

break;

case 4:

choice();

break;

}

}

}

怎么用Java编写一个地铁售票机的程序

说简单点,需求出来了啥都好写。

就是一个资源管理,涉及到一些并发处理。

java编写火车售票系统

你说的这个程序应该是不难的,只不过N久没有写过javaswing 了

还有就是java没有多继承的,只有多实现接口的

继承的关键字是:extends

接口的关键字是:interface

用java模拟四个售票点,不重复的卖出100张票(票的编号为1--100),售完为止。

public class ShowDemo{

public static void main(String[] rags)throws Exception{

MyThread mt= new MyThread();

Thread th1 = new Thread(mt,"售票一");

Thread th2 = new Thread(mt,"售票二");

Thread th3 = new Thread(mt,"售票三");

Thread th4 = new Thread(mt,"售票四");

th1.start();th2.start();th3.start();th4.start();

}

}

class MyThread implements Runnable{

int ticket=1;

public void run(){

while(ticket=100){

if("售票一".equals(Thread.currentThread().getName())  ticket%2!=0){

System.out.println("售票一售出:"+ticket++);

}

if("售票二".equals(Thread.currentThread().getName())  ticket%2!=0){

System.out.println("售票二售出:"+ticket++);

}

if("售票三".equals(Thread.currentThread().getName())  ticket%2==0){

System.out.println("售票三售出:"+ticket++);

}

if("售票四".equals(Thread.currentThread().getName())  ticket%4==0){

System.out.println("售票四售出:"+ticket++);

}

}

}

}


网页标题:java票务系统代码,java编程火车购票系统代码
浏览地址:http://cxhlcq.com/article/hssidg.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部