Javaウィジェット:ショッピングプロセスを実現する機能
33896 ワード
/**
*@ author
*@ version V1.00
*@ date 2014/4/9
*@ purpose
*/
import java.util.Scanner; // java.util Scanner
import java.util.Random; // java.util Random
import java.util.Date; // java.util Date
public class Shopping3 {
public static void main(String[] args){
// , 10 ,
String [] username = new String []{"name0","name1","name2","name3","name4","name5"
,"name6","name7","name8","name9"};
String [] password = new String []{"pass0","pass1","pass2","pass3","pass4","pass5"
,"pass6","pass7","pass8","pass9"};
// ,
int [] custNo = new int[10]; // 10
String [] custName = new String[10]; // 10
String [] custBirth = new String[10]; // 10
int [] custScore = new int[10]; // 10
//
for(int cn=0;cn<custNo.length;cn++){ // , 1001 1010
custNo[cn]=cn+1001;
}
custName[0]=" ";
custBirth[0]="1992-7-10"; //
custScore[0]=20000;
custName[1]=" ";
custBirth[1]="1992-6-17"; //
custScore[1]=25000;
custName[2]=" ";
custBirth[2]="1992-7-10"; //
custScore[2]=30000;
custName[3]=" ";
custBirth[3]="1992-11-1"; //
custScore[3]=10000;
custName[4]=" ";
custBirth[4]="1992-11-17"; //
custScore[4]=10000;
//
N1:
while (true){
System.out.println("\t\t 1.0
");
System.out.print("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");
System.out.println("");
System.out.println("\t\t\t1.
");
System.out.println("\t\t\t2.
");
System.out.println("\t\t\t3.
");
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");
//
int Logindex = 0; //
int f=2; //
int m=2 ; //
int h = 0; //
System.out.print(" :");
Scanner input = new Scanner(System.in);
int choice1 = input.nextInt();
// ,
if (choice1 == 1) {/* */
// :
N2:
while(true){
System.out.println(" :");
String name = input.next();
System.out.println(" :");
String pass = input.next();
// , ,
/* ==; , equals */
for(int i=0;i<username.length;i++){
if (name.equals(username[i]) && pass.equals(password[i])) {
System.out.println(" !");
// ,
N3:
while (true) {
System.out.println("\t\t
");
System.out.print("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
System.out.println("");
System.out.println("\t\t\t1.
");
System.out.println("\t\t\t2.
");
System.out.println("\t\t\t3.
");
System.out.println("\t\t\t4.
");
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
// ,
System.out.println(" :");
int choice2 = input.nextInt();
if (choice2 == 1) {
N4:
while (true) {// 1,
System.out.println(" >
");
System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
System.out.println("");
System.out.println("\t\t\t1.
");
System.out.println("\t\t\t2.
");
System.out.println("\t\t\t3.
");
System.out.println("\t\t\t4.
");
System.out.println("\t\t\t5.
");
System.out.print("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
System.out.println("");
// ,
System.out.println(" :");
int choice3 = input.nextInt();
if (choice3 == 1) {//
System.out.print(" \t \t\t \t\t
");
for(int j=0;j<custName.length;j++){
if(custName[j]==null){ // null ,
break;
}
System.out.println(custNo[j]+"\t\t"+custName[j]+"\t\t\t"+
custBirth[j]+"\t\t"+custScore[j]);
}
System.out.println(" !");
String str0 = input.next();
if (str0 != "\0") {//if ,
continue;
}
}else if (choice3 == 2) {
System.out.println(" !");
System.out.println(" (2-8 ):");
String newName=input.next();
System.out.println(" ( :YYYY-MM-DD):");
String newBirth = input.next ();
System.out.println(" :");
int newScore=input.nextInt();
int index = -1; //
for(int a=0;a<custName.length;a++){
if(custName[a]==null){
// null ,
index=a;
break;
}
}
//
custName[index]=newName;
custBirth[index]=newBirth;
custScore[index]=newScore;
System.out.println(" , !");
System.out.println(" !");
String str1=input.next();
if(str1 !="\0"){
continue;
}
}else if (choice3 == 3) {
System.out.println(" :");
int num1=input.nextInt();
System.out.println(" \t \t \t ");
for(int k=0;k<custNo.length;k++){
if(num1==custNo[k]){
System.out.println(num1+"\t\t"+custName[k]+"\t\t"+
custBirth[k]+"\t\t"+custScore[k]+"
");
System.out.println(" :1. 2. ");
System.out.println(" :");
int ch1= input.nextInt();
if (ch1 == 1) {
System.out.println(" (2-8 ):");
String str = input.next();
custName[k]=str;
System.out.println(" !");
System.out.println(" !");
String str2 = input.next();
if(str2 != "\0"){
continue N4;
}
}else {
System.out.println(" ( :YYYY-MM-DD):");
String birth = input.next();
custBirth[k] = birth;
System.out.println(" !");
System.out.println(" !");
String str3 = input.next();
if (str3 != "\0") {
continue N4;
} //if
} //else
} //if
} //for
}else if (choice3 == 4) {
System.out.println(" :");
int num2=input.nextInt();
System.out.println(" \t \t \t\t
");
for(int p=0;p<custNo.length;p++){
if(num2==custNo[p]){
System.out.println(num2+"\t\t"+custName[p]+"\t\t"+
custBirth[p]+"\t\t"+custScore[p]+"
");
}
}
System.out.println(" !");
String str4 = input.next();
if (str4 !="\0") {
continue;
}
}else if (choice3 == 5) {
continue N3;
}else{
System.out.println(" !");
System.out.println(" !");
String str = input.next();
if (str != "\0") {
continue;
} //if
} //else
} //N4
}else if (choice2 == 2) {
System.out.println(" !");
System.out.println(" (1001-1010):");
int cNo = input.nextInt();
int [] goodsNo = new int[]{1,2,3,4,5,6,7,8};
String [] goodsName = new String[]{" "," "," "," ",
" "," "," "," "};
double []goodsPrice = new double[]{18.00,1998.00,4998.00,25.80,5.60,
350.00,400.00,99.80};
System.out.println(" :");
System.out.println(" \t \t\t ");
for(int r=0;r<goodsNo.length;r++){
System.out.println(goodsNo[r]+"\t\t"+goodsName[r]+"\t\t ¥"+goodsPrice[r]);
}
int []gNos = new int[8]; //
int []gCounts = new int [8];//
N:
while(true){
System.out.println(" : ");
int gNo= input.nextInt();
gNos[h] =gNo; //
if(!(gNo>0&&gNo<9)){
System.out.println(" , !");
continue N ;
}
System.out.println(" : ");
int count = input.nextInt();
gCounts[h] = count; //
System.out.println(" ?( y , )");
String tr=input.next();
if("y".equals(tr)){
h++;
/*for(int v1=0;v1<h;v1++){
for(int v2=1;v2<=h;v2++){
if(gNos[v2]==gNos[v1]){
gCounts[v1] += gCounts[v2];
}
}
} */
continue;
} //if
//
for(int n=0 ;n<custNo.length;n++){ //
if(cNo == custNo[n]){ //
System.out.println(" :" + custName[n]);
break;
}
}
double totalPrice = 0;
System.out.println(" \t \t \t\t ");
for(int g=0;g<=h;g++){
for(int r=0;r<goodsNo.length;r++){
// gNos[] ,
if(gNos[g]==goodsNo[r]){
System.out.println(goodsName[r] + "\t ¥" + goodsPrice[r]+ "\t\t" +
gCounts[g]+ "\t\t ¥"+(float)(gCounts[g]*goodsPrice[r]));
totalPrice += gCounts[g]*goodsPrice[r];
}
}
}
System.out.println();
System.out.println(" : ¥"+(float)totalPrice);
System.out.println(" , :0.85");
double pay = totalPrice * 0.85;
// , ,
System.out.println(" : ¥"+(float)(pay));
System.out.print(" : ¥");
N5:
while(true){
double money = input.nextDouble();
if (money >= pay) {
System.out.println(" !");
System.out.println(" :"+ (float)(money - pay));
System.out.println(" !");
break;
}else {// ,
System.out.println(" , :");
continue;
}
}
System.out.println(" !");
String str6 = input.next();
if (str6 != "\0") {
continue N3;
} //if
} //N
}else if (choice2 == 3) { //
N6:
while (true) {
System.out.println(" >
");
System.out.print("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
System.out.println("");
System.out.println("\t\t\t1.
");
System.out.println("\t\t\t2.
");
System.out.println("\t\t\t3.
");
System.out.println("\t\t\t4.
");
System.out.print("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
System.out.println("");
// ,
System.out.println(" :");
int ch2 = input.nextInt();
if (ch2 == 1) {
int max=custScore[0]; // “ ” ,
int t =0;//
for(int c=1;c<custNo.length;c++){
if(custScore[c]>max){ // max
// max , ,
max = custScore[c];
t = c;// t
}
}
System.out.println(" :"+custName[t]);
System.out.println(" \t \t \t\t ");
System.out.println(custNo[t]+"\t\t"+custName[t]+"\t\t"+
custBirth[t]+"\t\t"+custScore[t]+"
");
Random rand0 =new Random(); //
int randnum0 = rand0.nextInt(5);// 0 5
switch(randnum0){// ,
case 0:
System.out.println(" , ¥50.00 ");
break;
case 1:
System.out.println(" , ¥32.00 ");
break;
case 2:
System.out.println(" , ¥18.00 ");
break;
case 3:
System.out.println(" , ¥7.80 ");
break;
case 4:
System.out.println(" , ¥3.50 ");
break;
default:
break;
}
System.out.println(" !");
String str7 = input.next();
if (str7 != "\0") {
continue;
}
}else if (ch2 == 2) {
Random rand1 =new Random(); //
// 0 6 ,
int randnum1 =rand1.nextInt(7);
System.out.println(" :"+custName[randnum1]);
System.out.println(" \t\t \t\t ");
System.out.println(custNo[randnum1]+"\t\t\t"+custName[randnum1]
+"\t\t\t"+custBirth[randnum1]);
Random rand2 =new Random();
int randnum2 = rand2.nextInt(7);
switch(randnum2){ //
case 0:
System.out.println(" , ¥30.00 ");
break;
case 1:
System.out.println(" , ¥22.00 ");
break;
case 2:
System.out.println(" , ¥13.50 ");
break;
case 3:
System.out.println(" , ¥7.80 ");
break;
case 4:
System.out.println(" , ¥3.50 ");
break;
default:
System.out.println(" , , ");
break;
}
System.out.println(" !");
String str8 = input.next();
if (str8 != "\0") {
continue;
}
}else if (ch2 == 3) {// , ,
System.out.println(" , !");
System.out.println(" !");
String str9 = input.next();
if (str9 != "\0") {
continue;
}
}else if(ch2 == 4){
continue N3;
}else{
System.out.println(" !");
System.out.println(" !");
String str = input.next();
if (str != "\0") {
continue;
} //if
} //else
} // N6
}else if(choice2 ==4){
continue N1;
}else{
System.out.println(" !");
System.out.println(" !");
String str = input.next();
if (str != "\0") {
continue;
} //if
} //else
} //N3
} //if
} //for
if(f!=0){
System.out.println(" , . "+ f +" ");
f--;
}
Logindex++;
if(Logindex > 2){
System.out.println(" 3 , !");
break N1;
} //if
} //N2
}else if(choice1 == 2){
N7:
while(true){
System.out.println(" : ");
String uname = input.next();
System.out.println(" : ");
String opassword = input.next();
for(int e=0;e <username.length;e++){
if(uname.equals(username[e])&&opassword.equals(password[e])){
N8:
while(true){
System.out.println(" : ");
String upassword = input.next();
System.out.println(" : ");
String upassword1 = input.next();
if(upassword1.equals(upassword)){
System.out.println(" !");
password[e] = upassword1;
System.out.println(" !");
String str = input.next();
if (str != "\0"){
continue N1;
}
}else{
if(m==0){
System.out.println(" , , !");
System.out.println(" !");
String str = input.next();
if (str != "\0"){
continue N1;
}
}
System.out.println(" , "+m+" !");
m--;
continue N8;
} //else
} //N8
} //if
} //for
if(f==0){
System.out.println(" 3 , !");
System.out.println(" !");
String str = input.next();
if (str != "\0"){
continue N1;
}
}
System.out.println(" , "+ f +" ");
f--;
continue N7;
} //N7
}else if (choice1 ==3) {/* */
System.out.println(" ......");
System.exit(1);//
}else {/* */
System.out.println(" , ");
continue;
} //else
} //N1
} // main
} // Shopping3
分からないみんなは私のQQをプラスして私に聞くことができます
QQ:765133133 1797077217