Java 菜单不运行时执行';无法正确打印

Java 菜单不运行时执行';无法正确打印,java,printing,Java,Printing,因此,我试图在使用某些方法时创建一个do-while菜单问题是我的菜单在输出部分打印。让我解释一下,我选择打印每个进程的第一个选项,在第一个进程完成后,它打印菜单,而不是在所有七(7)个进程完成后打印菜单。另外,我在另一个代码上有相同的菜单,它工作得很好。请找人帮忙。谢谢大家! import java.io.IOException; import java.util.Scanner; public class CristopherMunizProg1 extends Thread {

因此,我试图在使用某些方法时创建一个do-while菜单问题是我的菜单在输出部分打印。让我解释一下,我选择打印每个进程的第一个选项,在第一个进程完成后,它打印菜单,而不是在所有七(7)个进程完成后打印菜单。另外,我在另一个代码上有相同的菜单,它工作得很好。请找人帮忙。谢谢大家!

import java.io.IOException;
import java.util.Scanner;
public class CristopherMunizProg1 extends Thread {
    
    static String completedProcesses[] = new String[9999];
    static int completed = 0;
    String processName;
    String myDependencies[];
    double budNeeded;//--------------------------------
    static double budget;//--------------------------------
    static Scanner input = new Scanner(System.in);//--------------------------------
    static String[] names = {"P1", "P2", "P3", "P4", "P5", "P6", "P7"};//--------------------------------

    public CristopherMunizProg1(String pname, String md[], double bN) {//--------------------------------
        // TODO Auto-generated constructor stub
        
        super();
        processName = pname;
        myDependencies = md;
        budNeeded = bN;//--------------------------------
        
    }
    
    public void run()
    {

        returnWhenDependenciesMet();
        System.out.printf(processName + " started with a required budget of $%,.2f %n", budNeeded);
        completed();
    }
   
    void returnWhenDependenciesMet()
    {
        boolean finished = false;
        if (myDependencies.length > 0)
        {
            while (!finished)
            {
                finished = true;
                for (int i = 0; i < myDependencies.length; i++)
                {
                    if (!isInFinished(myDependencies[i]))
                    {
                        finished = false;
                    }
                }
            }
        }   
    }
   
    boolean isInFinished(String p)
    {
        boolean finished = false;
        for (int i = 0; i < completedProcesses.length; i++)
        {
            if (p.equals(completedProcesses[i]))
            {
                finished = true;
            }
        }
        return finished;
    }
   
    synchronized void completed()
    {
        
        System.out.println(processName + " finished");
        budget = budget - budNeeded; //--------------------------------
        System.out.printf("\tAvailable Budget: $%,.2f %n", budget);//--------------------------------
        completed++;
        completedProcesses[completed - 1] = processName;
 
    }
    
    static void editName() {
        
        int optionName;
        String newName;
        System.out.println("Which Process Name Would You Like to Change? (1-7) ");
        optionName = input.nextInt();
        
        switch (optionName) {
        
        case 1: 
            
            System.out.println("Insert New Name for Process P1: ");
            newName = input.next();
            names[0] = newName;
            break;
            
        case 2: 
            
            System.out.println("Insert New Name for Process P2: ");
            newName = input.next();
            names[1] = newName;
            break;
            
        case 3: 
            
            System.out.println("Insert New Name for Process P3: ");
            newName = input.next();
            names[2] = newName;
            break;
            
        case 4: 
            
            System.out.println("Insert New Name for Process P4: ");
            newName = input.next();
            names[3] = newName;
            break;
            
        case 5: 
            
            System.out.println("Insert New Name for Process P5: ");
            newName = input.next();
            names[4] = newName;
            break;
        
        case 6: 
            
            System.out.println("Insert New Name for Process P6: ");
            newName = input.next();
            names[5] = newName;
            break;
        
        case 7: 
            
            System.out.println("Insert New Name for Process P7: ");
            newName = input.next();
            names[6] = newName;
            break;
        }
        
        
    }


    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        
        int option;
        
        do {
            
            //Menu
            System.out.print("\n      MENU     \n");
            System.out.print("\n1. Start Processes");
            System.out.print("\n2. Edit Process Name\n");
            System.out.print("3. Edit Process Dependencies\n");
            System.out.print("4. Edit Process Budget\n");
            System.out.print("5. Exit\n");
            System.out.print("<Selection> ");
         
            option = input.nextInt();
            input.nextLine();
                     
            if (option==1) {
                
                System.out.print("Enter Available Budget: ");
                budget = input.nextDouble();
                input.nextLine();

                CristopherMunizProg1 p1 = new CristopherMunizProg1(names[0], new String[]{}, 10000);
                CristopherMunizProg1 p2 = new CristopherMunizProg1(names[1], new String[]{}, 20000);
                CristopherMunizProg1 p3 = new CristopherMunizProg1(names[2], new String[]{}, 30000);
                CristopherMunizProg1 p4 = new CristopherMunizProg1(names[3], new String[]{"P1", "P3"}, 40000);
                CristopherMunizProg1 p5 = new CristopherMunizProg1(names[4], new String[]{"P2", "P3"}, 50000);
                CristopherMunizProg1 p6 = new CristopherMunizProg1(names[5], new String[]{"P5"}, 60000);
                CristopherMunizProg1 p7 = new CristopherMunizProg1(names[6], new String[]{"P4", "P6"}, 70000);
                        p1.start();
                        p2.start();
                        p3.start();
                        p4.start();
                        p5.start();
                        p6.start();
                        p7.start();
            }
            
            if (option==2) {
                editName();

            }
            
            if (option==3) {
                //editDep();

            }
            
            if (option==4) {
                //editBudget();
    
            }
            
            if (option==5) {
                System.out.println("\nGoodbye!");
            }
        }while(option!=5);
        
    }

}
import java.io.IOException;
导入java.util.Scanner;
公共类CristoHermunizProg1扩展线程{
静态字符串CompletedProcess[]=新字符串[9999];
静态int completed=0;
字符串进程名;
字符串myDependencies[];
需要双倍的压力//--------------------------------
静态双预算//--------------------------------
静态扫描仪输入=新扫描仪(System.in)//--------------------------------
静态字符串[]名称={“P1”、“P2”、“P3”、“P4”、“P5”、“P6”、“P7”}//--------------------------------
公共CristopherMunizProg1(字符串pname,字符串md[],双bN){//--------------------------------
//TODO自动生成的构造函数存根
超级();
processName=pname;
myDependencies=md;
b=bN//--------------------------------
}
公开募捐
{
当独立设置()时返回;
System.out.printf(processName+“开始时所需预算为$%,.2f%n”,需要);
已完成();
}
void returnWhenDependenciesMet()
{
布尔完成=假;
如果(myDependencies.length>0)
{
当(!完成)
{
完成=正确;
对于(int i=0;i