我输入的数组没有继续报告。
import java.util.Scanner;
class PSS {
public static void main(String[] args) {
login();
}
public static void login() {
String user;
String pass;
System.out.println("--- LogIn ---\n");
Scanner get = new Scanner(System. in );
do {
System.out.print("Enter Username: ");
user = get.nextLine();
System.out.print("Enter Password: ");
pass = get.nextLine();
if (!user.equals("admin") || !pass.equals("pass")) System.out.print("\nInvalid Input\n\n");
} while (!user.equals("admin") || !pass.equals("pass"));
MMenu();
}
public static void MMenu() {
Scanner is = new Scanner(System. in );
int[] code = new int[10];
String[] Pname = new String[10];
String[] descrip = new String[10];
double[] Sellprice = new double[10];
double[] BuyPrice = new double[10];
int[] quanti1 = new int[10];
System.out.print("\n--- Main Menu ---\n");
System.out.println("\n1 - File Maintenance.");
System.out.println("2 - Transaction.");
System.out.println("3 - Report.");
System.out.println("4 - Log-out.");
System.out.println("Enter Choice: ");
int a = is.nextInt();
if (a == 1) {
System.out.println("--- File Maintenance ---\n");
Scanner are = new Scanner(System. in );
System.out.println("\n(a) - Add Product.");
System.out.println("(e) - Edit Product.");
System.out.println("(d) - Delete Product.");
System.out.println("(b) - Back to Main Menu\n");
System.out.print("Enter Choice: \n");
char b = are.next().charAt(0);
if (b == 'a') {
int d = 0;
int c = 0;
System.out.println("*****************************");
System.out.println("Add Product ");
Scanner was = new Scanner(System. in );
do {
System.out.println("*****************************");
System.out.print("Product No.: ");
code[c] = was.nextInt();
was.nextLine();
System.out.print("Product Name: ");
Pname[c] = was.nextLine();
System.out.print("Description: ");
descrip[c] = was.nextLine();
System.out.print("Buying Price: ");
BuyPrice[c] = was.nextDouble();
System.out.print("Selling Price: ");
Sellprice[c] = was.nextDouble();
System.out.println("\ndo you want to add more? (1 - Yes/0 - No)");
d = was.nextInt();
c++;
} while (d != 0);
MMenu();
}
if (b == 'e') {
System.out.println("This page is Under Construction.\n");
MMenu();
}
if (b == 'd') {
System.out.println("This page is Under Construction.\n");
MMenu();
}
if (b == 'b') {
MMenu();
}
}
if (a == 2) {
System.out.println("*****************************");
System.out.println("---Transaction---");
Scanner were = new Scanner(System. in );
int f;
System.out.println("1 - Stock - in");
System.out.println("2 - Sell Items\n");
System.out.println("Enter Choice: ");
f = were.nextInt();
if (f == 1) {
System.out.println("----Stock-in----");
Scanner be = new Scanner(System. in );
int q1 = 0;
int q2;
int h;
do {
System.out.print("Enter Product No.: ");
int g = be.nextInt();
if (g == (code[0])) {
System.out.println("Product Name: " + Pname[0]);
System.out.println("Description: " + descrip[0]);
System.out.println("Buying Price: " + BuyPrice[0]);
System.out.println("Selling Price: " + Sellprice[0]);
System.out.println("Quantity in-hand: " + quanti1[0]);
System.out.print("Enter Quantity: ");
quanti1[0] = be.nextInt();
q2 = quanti1[0] + q1;
q1 = quanti1[0];
quanti1[0] = q2;
} else if (g == (code[1])) {
System.out.println("Product Name: " + Pname[1]);
System.out.println("Description: " + descrip[1]);
System.out.println("Buying Price: " + BuyPrice[1]);
System.out.println("Selling Price: " + Sellprice[1]);
System.out.println("Quantity in-hand: " + quanti1[1]);
System.out.print("Enter Quantity: ");
quanti1[1] = be.nextInt();
q2 = quanti1[1] + q1;
q1 = quanti1[1];
quanti1[1] = q2;
} else if (g == (code[2])) {
System.out.println("Product Name: " + Pname[2]);
System.out.println("Description: " + descrip[2]);
System.out.println("Buying Price: " + BuyPrice[2]);
System.out.println("Selling Price: " + Sellprice[2]);
System.out.println("Quantity in-hand: " + quanti1[2]);
System.out.print("Enter Quantity: ");
quanti1[2] = be.nextInt();
q2 = quanti1[2] + q1;
q1 = quanti1[2];
quanti1[2] = q2;
} else if (g == (code[3])) {
System.out.println("Product Name: " + Pname[3]);
System.out.println("Description: " + descrip[3]);
System.out.println("Buying Price: " + BuyPrice[3]);
System.out.println("Selling Price: " + Sellprice[3]);
System.out.println("Quantity in-hand: " + quanti1[3]);
System.out.print("Enter Quantity: ");
quanti1[3] = be.nextInt();
q2 = quanti1[3] + q1;
q1 = quanti1[3];
quanti1[3] = q2;
} else if (g == (code[4])) {
System.out.println("Product Name: " + Pname[4]);
System.out.println("Description: " + descrip[4]);
System.out.println("Buying Price: " + BuyPrice[4]);
System.out.println("Selling Price: " + Sellprice[4]);
System.out.println("Quantity in-hand: " + quanti1[4]);
System.out.print("Enter Quantity: ");
quanti1[4] = be.nextInt();
q2 = quanti1[4] + q1;
q1 = quanti1[4];
quanti1[4] = q2;
} else if (g == (code[5])) {
System.out.println("Product Name: " + Pname[5]);
System.out.println("Description: " + descrip[5]);
System.out.println("Buying Price: " + BuyPrice[5]);
System.out.println("Selling Price: " + Sellprice[5]);
System.out.println("Quantity in-hand: " + quanti1[5]);
System.out.print("Enter Quantity: ");
quanti1[5] = be.nextInt();
q2 = quanti1[5] + q1;
q1 = quanti1[5];
quanti1[5] = q2;
} else if (g == (code[6])) {
System.out.println("Product Name: " + Pname[6]);
System.out.println("Description: " + descrip[6]);
System.out.println("Buying Price: " + BuyPrice[6]);
System.out.println("Selling Price: " + Sellprice[6]);
System.out.println("Quantity in-hand: " + quanti1[6]);
System.out.print("Enter Quantity: ");
quanti1[6] = be.nextInt();
q2 = quanti1[6] + q1;
q1 = quanti1[6];
quanti1[6] = q2;
} else if (g == (code[7])) {
System.out.println("Product Name: " + Pname[7]);
System.out.println("Description: " + descrip[7]);
System.out.println("Buying Price: " + BuyPrice[7]);
System.out.println("Selling Price: " + Sellprice[7]);
System.out.println("Quantity in-hand: " + quanti1[7]);
System.out.print("Enter Quantity: ");
quanti1[7] = be.nextInt();
q2 = quanti1[7] + q1;
q1 = quanti1[7];
quanti1[7] = q2;
} else if (g == (code[8])) {
System.out.println("Product Name: " + Pname[8]);
System.out.println("Description: " + descrip[8]);
System.out.println("Buying Price: " + BuyPrice[8]);
System.out.println("Selling Price: " + Sellprice[8]);
System.out.println("Quantity in-hand: " + quanti1[8]);
System.out.print("Enter Quantity: ");
quanti1[8] = be.nextInt();
q2 = quanti1[8] + q1;
q1 = quanti1[8];
quanti1[8] = q2;
} else if (g == (code[9])) {
System.out.println("Product Name: " + Pname[9]);
System.out.println("Description: " + descrip[9]);
System.out.println("Buying Price: " + BuyPrice[9]);
System.out.println("Selling Price: " + Sellprice[9]);
System.out.println("Quantity in-hand: " + quanti1[9]);
System.out.print("Enter Quantity: ");
quanti1[9] = be.nextInt();
q2 = quanti1[9] + q1;
q1 = quanti1[9];
quanti1[9] = q2;
}
System.out.println("\ndo you want to stock in another items? (1 - Yes/0 - No)");
h = be.nextInt();
} while (h == 1);
}
if (f == 2) {
System.out.println("----Sell----");
Scanner the = new Scanner(System. in );
System.out.print("Enter Product No.: ");
int co = the.nextInt();
double total;
double C;
double P;
if (co == (code[0])) {
System.out.println("Product Name: " + Pname[0]);
System.out.println("Description: " + descrip[0]);
System.out.println("Quantity in hand: " + quanti1[0]);
System.out.print("Quantity to buy: ");
int quanti2 = the.nextInt();
total = Sellprice[0] * quanti2;
System.out.println("Total: \n" + total);
System.out.print("Pay: ");
P = the.nextDouble();
C = P - total;
System.out.print("Change: " + C);
int quanti3 = quanti1[0] - quanti2;
quanti1[0] = quanti3;
} else if (co == (code[1])) {
System.out.println("Product Name: " + Pname[1]);
System.out.println("Description: " + descrip[1]);
System.out.println("Quantity in hand: " + quanti1[1]);
System.out.print("Quantity to buy: ");
int quanti2 = the.nextInt();
total = Sellprice[1] * quanti2;
System.out.println("Total: " + total);
System.out.print("\nPay: ");
P = the.nextDouble();
C = P - total;
System.out.print("Change: " + C);
int quanti3 = quanti1[1] - quanti2;
quanti1[1] = quanti3;
} else if (co == (code[2])) {
System.out.println("Product Name: " + Pname[2]);
System.out.println("Description: " + descrip[2]);
System.out.println("Quantity in hand: " + quanti1[2]);
System.out.print("Quantity to buy: ");
int quanti2 = the.nextInt();
total = Sellprice[2] * quanti2;
System.out.print("Total: " + total);
System.out.print("\nPay: ");
P = the.nextDouble();
C = P - total;
System.out.print("Change: " + C);
int quanti3 = quanti1[2] - quanti2;
quanti1[2] = quanti3;
} else if (co == (code[3])) {
System.out.println("Product Name: " + Pname[3]);
System.out.println("Description: " + descrip[3]);
System.out.println("Quantity in hand: " + quanti1[3]);
System.out.print("Quantity to buy: ");
int quanti2 = the.nextInt();
total = Sellprice[3] * quanti2;
System.out.print("Total: " + total);
System.out.print("\nPay: ");
P = the.nextDouble();
C = P - total;
System.out.print("Change: " + C);
int quanti3 = quanti1[3] - quanti2;
quanti1[3] = quanti3;
} else if (co == (code[4])) {
System.out.println("Product Name: " + Pname[4]);
System.out.println("Description: " + descrip[4]);
System.out.println("Quantity in hand: " + quanti1[4]);
System.out.print("Quantity to buy: ");
int quanti2 = the.nextInt();
total = Sellprice[4] * quanti2;
System.out.print("Total: " + total);
System.out.print("\nPay: ");
P = the.nextDouble();
C = P - total;
System.out.print("Change: " + C);
int quanti3 = quanti1[4] - quanti2;
quanti1[4] = quanti3;
} else if (co == (code[5])) {
System.out.println("Product Name: " + Pname[5]);
System.out.println("Description: " + descrip[5]);
System.out.println("Quantity in hand: " + quanti1[5]);
System.out.print("Quantity to buy: ");
int quanti2 = the.nextInt();
total = Sellprice[5] * quanti2;
System.out.print("Total: " + total);
System.out.print("\nPay: ");
P = the.nextDouble();
C = P - total;
System.out.print("Change: " + C);
int quanti3 = quanti1[5] - quanti2;
quanti1[5] = quanti3;
} else if (co == (code[6])) {
System.out.println("Product Name: " + Pname[6]);
System.out.println("Description: " + descrip[6]);
System.out.println("Quantity in hand: " + quanti1[6]);
System.out.print("Quantity to buy: ");
int quanti2 = the.nextInt();
total = Sellprice[1] * quanti2;
System.out.print("Total: \n" + total);
System.out.print("Pay: ");
P = the.nextDouble();
C = P - total;
System.out.print("Change: " + C);
int quanti3 = quanti1[6] - quanti2;
quanti1[6] = quanti3;
} else if (co == (code[7])) {
System.out.println("Product Name: " + Pname[7]);
System.out.println("Description: " + descrip[7]);
System.out.println("Quantity in hand: " + quanti1[7]);
System.out.print("Quantity to buy: ");
int quanti2 = the.nextInt();
total = Sellprice[7] * quanti2;
System.out.print("Total: \n" + total);
System.out.print("Pay: ");
P = the.nextDouble();
C = P - total;
System.out.print("Change: " + C);
int quanti3 = quanti1[7] - quanti2;
quanti1[7] = quanti3;
} else if (co == (code[8])) {
System.out.println("Product Name: " + Pname[8]);
System.out.println("Description: " + descrip[8]);
System.out.println("Quantity in hand: " + quanti1[8]);
System.out.print("Quantity to buy: ");
int quanti2 = the.nextInt();
total = Sellprice[8] * quanti2;
System.out.print("Total: \n" + total);
System.out.print("Pay: ");
P = the.nextDouble();
C = P - total;
System.out.print("Change: " + C);
int quanti3 = quanti1[8] - quanti2;
quanti1[8] = quanti3;
} else if (co == (code[9])) {
System.out.println("Product Name: " + Pname[9]);
System.out.println("Description: " + descrip[9]);
System.out.println("Quantity in hand: " + quanti1[9]);
System.out.print("Quantity to buy: ");
int quanti2 = the.nextInt();
total = Sellprice[9] * quanti2;
System.out.print("Total: " + total);
System.out.print("\nPay: ");
P = the.nextDouble();
C = P - total;
System.out.print("Change: " + C);
int quanti3 = quanti1[9] - quanti2;
quanti1[9] = quanti3;
}
}
MMenu();
}
if (a == 3) {
System.out.print("---Report---\n\n");
System.out.println("Products Available\n");
System.out.println("| Product No. | Name | Price | Quantity |");
System.out.println("|" + code[0] + " " + Pname[0] + " " + Sellprice[0] + " " + quanti1[0] + " ");
System.out.println("|" + code[1] + " " + Pname[1] + " " + Sellprice[1] + " " + quanti1[1] + " ");
System.out.println("|" + code[2] + " " + Pname[2] + " " + Sellprice[2] + " " + quanti1[2] + " ");
System.out.println("|" + code[3] + " " + Pname[3] + " " + Sellprice[3] + " " + quanti1[3] + " ");
System.out.println("|" + code[4] + " " + Pname[4] + " " + Sellprice[4] + " " + quanti1[4] + " ");
System.out.println("|" + code[5] + " " + Pname[5] + " " + Sellprice[5] + " " + quanti1[5] + " ");
System.out.println("|" + code[6] + " " + Pname[6] + " " + Sellprice[6] + " " + quanti1[6] + " ");
System.out.println("|" + code[7] + " " + Pname[7] + " " + Sellprice[7] + " " + quanti1[7] + " ");
System.out.println("|" + code[8] + " " + Pname[8] + " " + Sellprice[8] + " " + quanti1[8] + " ");
System.out.println("|" + code[9] + " " + Pname[9] + " " + Sellprice[9] + " " + quanti1[9] + " ");
MMenu();
}
if (a == 4) {
System.out.println("Logging out... \nHave a nice day!");
login();
}
}
}
答案 0 :(得分:0)
import java.util.Scanner;
课程PSS {
public static void main (String [] args)
{
login();
}
public static void login()
{
String user; String pass;
System.out.println ("\n--- LogIn ---\n");
Scanner get = new Scanner (System.in);
do{
System.out.print ("Enter Username: ");
user = get.nextLine();
System.out.print ("Enter Password: ");
pass = get.nextLine();
if (!user.equals ("admin") || !pass.equals("pass"))
System.out.print ("\nInvalid Input\n\n");
} while (!user.equals("admin") || !pass.equals("pass"));
MMenu();
}
public static void MMenu(){
int m = 0;
do{
Scanner is = new Scanner (System.in);
int [] code = new int [10];
String [] Pname = new String [10];
String [] descrip = new String [10];
double [] Sellprice = new double [10];
double [] BuyPrice = new double [10];
int [] quanti1 = new int [10];
System.out.print ("\n--- Main Menu ---\n");
System.out.println ("\n1 - File Maintenance.");
System.out.println ("2 - Transaction.");
System.out.println ("3 - Report.");
System.out.println ("4 - Log-out.");
System.out.println ("Enter Choice: ");
int a = is.nextInt();
if (a == 1)
{
System.out.println ("--- File Maintenance ---\n");
Scanner are = new Scanner (System.in);
System.out.println ("\n(a) - Add Product.");
System.out.println ("(e) - Edit Product.");
System.out.println ("(d) - Delete Product.");
System.out.println ("(b) - Back to Main Menu\n");
System.out.print ("Enter Choice: \n");
char b = are.next().charAt(0);
if (b=='a')
{
int d = 0;
int c = 0;
System.out.println("*****************************");
System.out.println("Add Product ");
Scanner was = new Scanner (System.in);
do {
System.out.println("*****************************");
System.out.print("Product No.: ");
code[c] = was.nextInt();
was.nextLine();
System.out.print("Product Name: ");
Pname[c] = was.nextLine();
System.out.print("Description: ");
descrip[c] = was.nextLine();
System.out.print("Buying Price: ");
BuyPrice[c] = was.nextDouble();
System.out.print("Selling Price: ");
Sellprice[c] = was.nextDouble();
System.out.println("\ndo you want to add more? (1 - Yes/0 - No)");
d = was.nextInt();
c++;
} while (d != 0);
}
if (b=='e')
{
System.out.println ("\nThis page is Under Construction.\n");
}
if (b=='d')
{
System.out.println ("\nThis page is Under Construction.\n");
}
if (b=='b')
{
System.out.println ("\nGoing back to main menu.\n");
}
System.out.println("\ndo you want to to go back to main menu? (1 - Yes/0 - No)");
m = is.nextInt();
}
if (a == 2)
{
System.out.println("*****************************");
System.out.println ("---Transaction---");
Scanner were = new Scanner(System.in);
int f;
System.out.println ("1 - Stock - in");
System.out.println ("2 - Sell Items\n");
System.out.println ("Enter Choice: ");
f = were.nextInt();
if (f==1)
{
System.out.println("----Stock-in----");
Scanner be = new Scanner (System.in);
int q1 = 0;
int q2;
int h;
do
{
System.out.print ("Enter Product No.: ");
int g = be.nextInt();
if (g==(code[0]))
{
System.out.println("Product Name: " + Pname[0]);
System.out.println("Description: " + descrip[0]);
System.out.println("Buying Price: " + BuyPrice[0]);
System.out.println("Selling Price: " + Sellprice[0]);
System.out.println ("Quantity in-hand: " + quanti1[0]);
System.out.print ("Enter Quantity: ");
quanti1[0] = be.nextInt();
q2 = quanti1[0] + q1;
q1 = quanti1[0];
quanti1[0] = q2;
}
else if (g==(code[1]))
{
System.out.println("Product Name: " + Pname[1]);
System.out.println("Description: " + descrip[1]);
System.out.println("Buying Price: " + BuyPrice[1]);
System.out.println("Selling Price: " + Sellprice[1]);
System.out.println ("Quantity in-hand: " + quanti1[1]);
System.out.print ("Enter Quantity: ");
quanti1[1] = be.nextInt();
q2 = quanti1[1] + q1;
q1 = quanti1[1];
quanti1[1] = q2;
}
else if (g==(code[2]))
{
System.out.println("Product Name: " + Pname[2]);
System.out.println("Description: " + descrip[2]);
System.out.println("Buying Price: " + BuyPrice[2]);
System.out.println("Selling Price: " + Sellprice[2]);
System.out.println ("Quantity in-hand: " + quanti1[2]);
System.out.print ("Enter Quantity: ");
quanti1[2] = be.nextInt();
q2 = quanti1[2] + q1;
q1 = quanti1[2];
quanti1[2] = q2;
}
else if (g==(code[3]))
{
System.out.println("Product Name: " + Pname[3]);
System.out.println("Description: " + descrip[3]);
System.out.println("Buying Price: " + BuyPrice[3]);
System.out.println("Selling Price: " + Sellprice[3]);
System.out.println ("Quantity in-hand: " + quanti1[3]);
System.out.print ("Enter Quantity: ");
quanti1[3] = be.nextInt();
q2 = quanti1[3] + q1;
q1 = quanti1[3];
quanti1[3] = q2;
}
else if (g==(code[4]))
{
System.out.println("Product Name: " + Pname[4]);
System.out.println("Description: " + descrip[4]);
System.out.println("Buying Price: " + BuyPrice[4]);
System.out.println("Selling Price: " + Sellprice[4]);
System.out.println ("Quantity in-hand: " + quanti1[4]);
System.out.print ("Enter Quantity: ");
quanti1[4] = be.nextInt();
q2 = quanti1[4] + q1;
q1 = quanti1[4];
quanti1[4] = q2;
}
else if (g==(code[5]))
{
System.out.println("Product Name: " + Pname[5]);
System.out.println("Description: " + descrip[5]);
System.out.println("Buying Price: " + BuyPrice[5]);
System.out.println("Selling Price: " + Sellprice[5]);
System.out.println ("Quantity in-hand: " + quanti1[5]);
System.out.print ("Enter Quantity: ");
quanti1[5] = be.nextInt();
q2 = quanti1[5] + q1;
q1 = quanti1[5];
quanti1[5] = q2;
}
else if (g==(code[6]))
{
System.out.println("Product Name: " + Pname[6]);
System.out.println("Description: " + descrip[6]);
System.out.println("Buying Price: " + BuyPrice[6]);
System.out.println("Selling Price: " + Sellprice[6]);
System.out.println ("Quantity in-hand: " + quanti1[6]);
System.out.print ("Enter Quantity: ");
quanti1[6] = be.nextInt();
q2 = quanti1[6] + q1;
q1 = quanti1[6];
quanti1[6] = q2;
}
else if (g==(code[7]))
{
System.out.println("Product Name: " + Pname[7]);
System.out.println("Description: " + descrip[7]);
System.out.println("Buying Price: " + BuyPrice[7]);
System.out.println("Selling Price: " + Sellprice[7]);
System.out.println ("Quantity in-hand: " + quanti1[7]);
System.out.print ("Enter Quantity: ");
quanti1[7] = be.nextInt();
q2 = quanti1[7] + q1;
q1 = quanti1[7];
quanti1[7] = q2;
}
else if (g==(code[8]))
{
System.out.println("Product Name: " + Pname[8]);
System.out.println("Description: " + descrip[8]);
System.out.println("Buying Price: " + BuyPrice[8]);
System.out.println("Selling Price: " + Sellprice[8]);
System.out.println ("Quantity in-hand: " + quanti1[8]);
System.out.print ("Enter Quantity: ");
quanti1[8] = be.nextInt();
q2 = quanti1[8] + q1;
q1 = quanti1[8];
quanti1[8] = q2;
}
else if (g==(code[9]))
{
System.out.println("Product Name: " + Pname[9]);
System.out.println("Description: " + descrip[9]);
System.out.println("Buying Price: " + BuyPrice[9]);
System.out.println("Selling Price: " + Sellprice[9]);
System.out.println ("Quantity in-hand: " + quanti1[9]);
System.out.print ("Enter Quantity: ");
quanti1[9] = be.nextInt();
q2 = quanti1[9] + q1;
q1 = quanti1[9];
quanti1[9] = q2;
}
System.out.println("\ndo you want to stock in another items? (1 - Yes/0 - No)");
h = be.nextInt();
}while(h==1);
}
if (f==2)
{
System.out.println("----Sell----");
Scanner the = new Scanner (System.in);
System.out.print ("Enter Product No.: ");
int co = the.nextInt();
double total = 0;
double C;
double P;
int p;
double total1 = 0;
double total2;
do
{
if (co==(code[0])){
System.out.println("Product Name: " + Pname[0]);
System.out.println("Description: " + descrip[0]);
System.out.println("Quantity in hand: " + quanti1[0]);
System.out.print("Quantity to buy: ");
int quanti2 = the.nextInt();
total = Sellprice[0]*quanti2;
System.out.println("Total: \n" + total);
int quanti3 = quanti1[0] - quanti2;
quanti1[0] = quanti3;
}
else if (co==(code[1])){
System.out.println("Product Name: " + Pname[1]);
System.out.println("Description: " + descrip[1]);
System.out.println("Quantity in hand: " + quanti1[1]);
System.out.print("Quantity to buy: ");
int quanti2 = the.nextInt();
total = Sellprice[1]*quanti2;
System.out.println("Total: " + total);
System.out.print("\nPay: ");
int quanti3 = quanti1[1] - quanti2;
quanti1[1] = quanti3;
}
else if (co==(code[2])){
System.out.println("Product Name: " + Pname[2]);
System.out.println("Description: " + descrip[2]);
System.out.println("Quantity in hand: " + quanti1[2]);
System.out.print("Quantity to buy: ");
int quanti2 = the.nextInt();
total = Sellprice[2]*quanti2;
System.out.print("Total: " + total);
System.out.print("\nPay: ");
int quanti3 = quanti1[2] - quanti2;
quanti1[2] = quanti3;
}
else if (co==(code[3])){
System.out.println("Product Name: " + Pname[3]);
System.out.println("Description: " + descrip[3]);
System.out.println("Quantity in hand: " + quanti1[3]);
System.out.print("Quantity to buy: ");
int quanti2 = the.nextInt();
total = Sellprice[3]*quanti2;
System.out.print("Total: " + total);
int quanti3 = quanti1[3] - quanti2;
quanti1[3] = quanti3;
}
else if (co==(code[4])){
System.out.println("Product Name: " + Pname[4]);
System.out.println("Description: " + descrip[4]);
System.out.println("Quantity in hand: " + quanti1[4]);
System.out.print("Quantity to buy: ");
int quanti2 = the.nextInt();
total = Sellprice[4]*quanti2;
System.out.print("Total: " + total);
int quanti3 = quanti1[4] - quanti2;
quanti1[4] = quanti3;
}
else if (co==(code[5])){
System.out.println("Product Name: " + Pname[5]);
System.out.println("Description: " + descrip[5]);
System.out.println("Quantity in hand: " + quanti1[5]);
System.out.print("Quantity to buy: ");
int quanti2 = the.nextInt();
total = Sellprice[5]*quanti2;
System.out.print("Total: " + total);
int quanti3 = quanti1[5] - quanti2;
quanti1[5] = quanti3;
}
else if (co==(code[6])){
System.out.println("Product Name: " + Pname[6]);
System.out.println("Description: " + descrip[6]);
System.out.println("Quantity in hand: " + quanti1[6]);
System.out.print("Quantity to buy: ");
int quanti2 = the.nextInt();
total = Sellprice[1]*quanti2;
System.out.print("Total: \n" + total);
int quanti3 = quanti1[6] - quanti2;
quanti1[6] = quanti3;
}
else if (co==(code[7])){
System.out.println("Product Name: " + Pname[7]);
System.out.println("Description: " + descrip[7]);
System.out.println("Quantity in hand: " + quanti1[7]);
System.out.print("Quantity to buy: ");
int quanti2 = the.nextInt();
total = Sellprice[7]*quanti2;
System.out.print("Total: \n" + total);
int quanti3 = quanti1[7] - quanti2;
quanti1[7] = quanti3;
}
else if (co==(code[8])){
System.out.println("Product Name: " + Pname[8]);
System.out.println("Description: " + descrip[8]);
System.out.println("Quantity in hand: " + quanti1[8]);
System.out.print("Quantity to buy: ");
int quanti2 = the.nextInt();
total = Sellprice[8]*quanti2;
System.out.print("Total: \n" + total);
int quanti3 = quanti1[8] - quanti2;
quanti1[8] = quanti3;
}
else if (co==(code[9])){
System.out.println("Product Name: " + Pname[9]);
System.out.println("Description: " + descrip[9]);
System.out.println("Quantity in hand: " + quanti1[9]);
System.out.print("Quantity to buy: ");
int quanti2 = the.nextInt();
total = Sellprice[9]*quanti2;
System.out.print("Total: " + total);
int quanti3 = quanti1[9] - quanti2;
quanti1[9] = quanti3;
}
total2 = total + total1;
total1 = total;
total = total2;
System.out.println("\ndo you want to stock in another items? (1 - Yes/0 - No)");
p = the.nextInt();
}while (p==1);
System.out.println("\nPay: ");
P = the.nextDouble();
C = P - total;
System.out.println("Change: " + C);
}
System.out.println("\ndo you want to to go back to main menu? (1 - Yes/0 - No)");
m = is.nextInt();
}
if (a == 3)
{
System.out.print("---Report---\n\n");
System.out.println ("Products Available\n");
System.out.println ("| Product No. | Name | Price | Quantity |");
for (int k=0; k<10; k++){
System.out.println ("|" + code[k] + " " + Pname[k] + " " + Sellprice[k] + " " + quanti1[k] + " ");
}
System.out.println("\ndo you want to to go back to main menu? (1 - Yes/0 - No)");
m = is.nextInt();
}
if (a == 4)
{
System.out.println ("Logging out... \nHave a nice day!");
login();
}
} while (m==1);
}
}
答案 1 :(得分:0)
你正在调用MMenu();递归地使菜单可以重复打印出来。但是您尝试打印的数组是MMenu()中的局部变量。
public static void MMenu() {
Scanner is = new Scanner(System.in);
int[] code = new int[10]; // these are local variables in
String[] Pname = new String[10];
String[] descrip = new String[10];
double[] Sellprice = new double[10];
double[] BuyPrice = new double[10];
int[] quanti1 = new int[10];
...
do {
System.out.println("*****************************");
System.out.print("Product No.: ");
code[c] = was.nextInt();
was.nextLine();
System.out.print("Product Name: ");
Pname[c] = was.nextLine();
System.out.print("Description: ");
descrip[c] = was.nextLine();
System.out.print("Buying Price: ");
BuyPrice[c] = was.nextDouble();
System.out.print("Selling Price: ");
Sellprice[c] = was.nextDouble();
System.out.println("\ndo you want to add more? (1 - Yes/0 - No)");
d = was.nextInt();
c++;
} while (d != 0);
MMenu(); // this is where recursion happens, there are a lot such examples in your code, get rid of them and use loops
...
}
因此,当您添加产品时,您在MMenu()内部,我们称之为A.产品信息存储在A中的本地数组中。
添加完产品后,再次在A中调用了MMenu(),我们将其称为B.此时,如果尝试打印出阵列,则打印出B中的本地数组,但不打印在A中。这就是你打印出空阵列的原因。
要解决此问题,请使用循环代替递归重新打印菜单。
PS:正如评论中所建议的,您的代码搞砸了,使用类来包装产品信息,还将MMenu分解为几个小方法,使其更模块化,更易于调试