java票務(wù)系統(tǒng)代碼,java編程火車(chē)購(gòu)票系統(tǒng)代碼

java編程實(shí)現(xiàn)景區(qū)售票規(guī)則:成人票每人10元,兒童票折半(如果兒童身高不超過(guò)1.2

這個(gè)規(guī)則就是設(shè)計(jì)一個(gè)方法,該方法最后值為一個(gè)票價(jià),參數(shù)應(yīng)該是身高,所以有如下代碼

創(chuàng)新互聯(lián)公司是一家專(zhuān)業(yè)提供甘孜州企業(yè)網(wǎng)站建設(shè),專(zhuān)注與成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)、HTML5建站、小程序制作等業(yè)務(wù)。10年已為甘孜州眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專(zhuān)業(yè)網(wǎng)站建設(shè)公司優(yōu)惠進(jìn)行中。

public?class?PriceTest?{

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

int?childPrice?=?getPrice(1.2);

int?adultPrice?=?getPrice(1.5);

System.out.println("1.2米身高的票價(jià)為:"+childPrice);

System.out.println("1.5米身高的成人票價(jià)為:"+adultPrice);

}

private?static?int?getPrice(double?height)?{

return?height??1.2?10:5;

}

}

最后結(jié)果如下:

Java編程 假設(shè)有火車(chē)票1000張,創(chuàng)建10個(gè)線程模擬10個(gè)售票點(diǎn),每個(gè)售票點(diǎn)100毫秒售出一張票。

package?tmp;

public?class?Test?{

private?static?int?k=0;//售出票數(shù)

private?static?int?count=1000;//總票數(shù)

private?static?synchronized?boolean?sell(int?n){

if(kcount){

k++;

System.out.println("第"+n+"售票點(diǎn)售出第"+k+"張票");

return?true;

}

return?false;

}

static?class?SellPot?extends?Thread{//售票點(diǎn)

int?n;//售票點(diǎn)編號(hào)

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+"個(gè)顧客進(jìn)行第"+(i+1)+"次匯款,銀行接收總匯款"+k);

}

static?class?Costum?extends?Thread{//售票點(diǎn)

int?n;//顧客編號(hào)

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編寫(xiě)購(gòu)物系統(tǒng)的代碼是什么?(急)

算是最簡(jiǎn)單的吧

package cn.job01;

import java.util.Scanner;

public class Lx07 {

public static void choice() {

System.out.println("登陸菜單 ");

System.out.println("1登陸系統(tǒng)");

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

}

static void choice1() {

System.out.println("購(gòu)物管理系統(tǒng)客戶信息");

System.out.println("1顯示所有客戶信息");

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

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

System.out.println("4查詢客戶信息");

}

static void choice2() {

System.out.println("購(gòu)物管理系統(tǒng)真情回饋");

System.out.println("1幸運(yùn)大放送");

System.out.println("2幸運(yùn)抽獎(jiǎng)");

System.out.println("3生日問(wèn)候");

}

public static void main(String[] args) {

choice();

Scanner input = new Scanner(System.in);

System.out.println("請(qǐng)輸入1or2");

int num = input.nextInt();

switch (num) {

case 1:

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

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

System.out.println("2購(gòu)物結(jié)算");

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

System.out.println("4注銷(xiāo)");

break;

}

System.out.println("選擇輸入數(shù)字");

int num1 = input.nextInt();

switch (num1) {

case 1:

choice1();

break;

case 2:

System.out.println("購(gòu)物結(jié)算");

break;

case 3:

choice2();

break;

case 4:

choice();

break;

}

}

}

怎么用Java編寫(xiě)一個(gè)地鐵售票機(jī)的程序

說(shuō)簡(jiǎn)單點(diǎn),需求出來(lái)了啥都好寫(xiě)。

就是一個(gè)資源管理,涉及到一些并發(fā)處理。

java編寫(xiě)火車(chē)售票系統(tǒng)

你說(shuō)的這個(gè)程序應(yīng)該是不難的,只不過(guò)N久沒(méi)有寫(xiě)過(guò)javaswing 了

還有就是java沒(méi)有多繼承的,只有多實(shí)現(xiàn)接口的

繼承的關(guān)鍵字是:extends

接口的關(guān)鍵字是:interface

用java模擬四個(gè)售票點(diǎn),不重復(fù)的賣(mài)出100張票(票的編號(hào)為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++);

}

}

}

}

網(wǎng)站標(biāo)題:java票務(wù)系統(tǒng)代碼,java編程火車(chē)購(gòu)票系統(tǒng)代碼
當(dāng)前路徑:http://www.muchs.cn/article16/hssidg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、網(wǎng)頁(yè)設(shè)計(jì)公司網(wǎng)站改版、網(wǎng)站排名、移動(dòng)網(wǎng)站建設(shè)動(dòng)態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名