這個(gè)規(guī)則就是設(shè)計(jì)一個(gè)方法,該方法最后值為一個(gè)票價(jià),參數(shù)應(yīng)該是身高,所以有如下代碼
創(chuàng)新互聯(lián)公司是一家專業(yè)提供甘孜州企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)、HTML5建站、小程序制作等業(yè)務(wù)。10年已為甘孜州眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(liá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é)果如下:
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();
}
}
}
算是最簡單的吧
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("購物管理系統(tǒng)客戶信息");
System.out.println("1顯示所有客戶信息");
System.out.println("2添加客戶信息");
System.out.println("3修改客戶信息");
System.out.println("4查詢客戶信息");
}
static void choice2() {
System.out.println("購物管理系統(tǒng)真情回饋");
System.out.println("1幸運(yùn)大放送");
System.out.println("2幸運(yùn)抽獎(jiǎng)");
System.out.println("3生日問候");
}
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購物結(jié)算");
System.out.println("3真情回饋");
System.out.println("4注銷");
break;
}
System.out.println("選擇輸入數(shù)字");
int num1 = input.nextInt();
switch (num1) {
case 1:
choice1();
break;
case 2:
System.out.println("購物結(jié)算");
break;
case 3:
choice2();
break;
case 4:
choice();
break;
}
}
}
說簡單點(diǎn),需求出來了啥都好寫。
就是一個(gè)資源管理,涉及到一些并發(fā)處理。
你說的這個(gè)程序應(yīng)該是不難的,只不過N久沒有寫過javaswing 了
還有就是java沒有多繼承的,只有多實(shí)現(xiàn)接口的
繼承的關(guān)鍵字是:extends
接口的關(guān)鍵字是:interface
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++);
}
}
}
}