Justin Z 2019-05-23 00:37 采纳率: 33.3%
浏览 625
已结题

对明星表白的程序,switch语句用的不知道对不对?

要求做一个对明星表白的程序,最后两个类不知道怎么用?然后三个程序也不知道是不是调用的对。求大佬们看看第二个语句哪里错了!谢谢

public class Asst3
{
    public static void main(String[] args)
    {
        CelebStalker s=new CelebStalker();
        s.play();
    }
}

import java.util.Scanner;
import java.util.Random;

public class CelebStalker
{
    // final instance variables


    // non-final instance variables
    int guardPos;

    public CelebStalker()
    {
        // method body
            public void explain()
    {
        // method body

        System.out.println("Stalk a Celebraity");
        System.out.print("==================");
        System.out.println("You have to find and seduce your ideal celebrity. Now.");


    }


    public void play()
    {
        // method body
       Scanner scan = new Scanner (System.in);

        System.out.println("Would you like to play Stalk a Celeb?");

        String Choice_Will = scan.nextLine();//change here
        if (Choice_Will == True)
         {
            System.out.println("True/False, do you want to stalk a male celebrity?");
            String male = scan.nextLine();
            if (male = true)
               {
                  Random rand = new Random();
                  int Num_Male = rand.nextInt(10);
                  System.out.println("You are stalking" + celebrity.getCelebrity[Num_Male]);
               }
            else
               {
                  Random rand = new Random();
                  int Num_FeMale = rand.nextInt(10);
                  System.out.println("You are stalking" + celebrity.getCelebrity[Num_FeMale]);
               }

               int pos_guard;//give random position to guard
               Random generator = new Random();
               pos_guard = generator.nextInt(numStreets);
               while (pos_guard == currentStreet.CelebrityBot)
               {
                  Random generator = new Random();
                  pos_guard = generator.nextInt(numStreet.CelebrityBot);
               }
               guardPos = pos_guard;

               System.out.println("You are in street #" + currentStreet.CelebrityBot + ".");
               //the following part will show to show your love;
               Random r1 = new Random();
               int Num_Right = r1.nextInt(9);

               Random r2 = new Random();
               int Num_Left = r2.nextInt(9);

               Random r3 = new Random();
               int Num_Ahead = r3.nextInt(9);

               Random r4 = new Random();
               int Num_Behind = r4.nextInt(9);
               System.out.println("To your left is #" +left.CelebrityBot[Num_Left] + ",", "to your right is #" + right.CelebrityBot[Num_Right] + "ahead is #" + ahead.CelebrityBot[Num_Ahead] + "and behind is #" + behind.CelebrityBot[Num_Behind]); 



         }



               char ch;//ch is the choice;
               System.out.println("Would you like to Walk(w), Shout(s), Reset(r), Quit(q)?");
               ch = scan.nextLine();
               switch (ch) {
               case "s":
               //"shout" function is declared later.
               int shout;
               if (shout == guardPos)
               {
                  int dazed = MAX_DAZED_MOVES.tryWalk;// "dazed" is the time of dazed;
                  System.out.println("You haved dazed for next two moves.");
                  if (currentStreet.tryWalk == celePos)
                  {
                     System.out.println("Sorry, you are failed to see your star.");
                  }
                  else
                  {
                  int i = 0;
                  int h = 0;     
                     if (shout == celePos.CelebrityBot)
                     {
                       for(i = 0; i<= 3; i++)
                       {
                        char[] outcome = {"SUCCESS", "FAILURE"};
                        Random r = new Random();
                        char Outcome_R = r.nextLine(2);
                        char Outcome_Result = outcome[Outcome_R];
                        System.out.println("You have declared your love" + i + "/3" + "times and shouted in empty streets" +  h  + "times.");//print out the random result of shouting to the cele;
                        }
                     }
                     else
                     {
                        for(h = 0; h <= 3; h++)
                        {
                           System.out.println("You have declared your love" + i + "/3" + "times and shouted in empty streets" +  h  + "times.");
                        }
                     }


                 }

               }                                
               else
               {
                   if (shout == celePos.CelebrityBot)
                     {
                        for(i = 0; i<= 3; i++)
                        {
                        char[] outcome = {"SUCCESS", "FAILURE"};
                        Random r = new Random();
                        char Outcome_R = rand.nextLine(2);
                        char Outcome_Result = outcome[Outcome_R];
                        System.out.println("You have declared your love" + i + "/3" + "times and shouted in empty streets" +  h  + "times.");   
                        }
                     }
                  else
                  {
                   for(h = 0; h <= 3; h++)
                        {
                           System.out.println("You have declared your love" + i + "/3" + "times and shouted in empty streets" +  h  + "times.");
                        }

                  }

               }


               //"walk" function will be illustrated;
               case "w":
                  System.out.println("Which street would you like to walk into? " + currentStreet.trywalk);
                  Street_Num = scan.nextInt;
                  if (Street_Num = nextIs.nextStreet)
                  {
                     if (Street_Num = guardPos)
                     {
                        System.out.println("Sorry, You are dazed within 2 moves and do not know where you are!");
                     }
                     else
                     {
                        if (Street_Num = celePos)
                        {
                           if (dazedRemaining != 0)
                           {
                              System.out.println("Sorry, you are failed!");
                           }
                        }
                        else
                        {
                           System.out.println("Walk successfully, but you are still alone!");
                           //this part should be more statemnet to make it continue;
                        }
                     }

               }

               //"quit" function will be illustrated;
               case "q":
                  System.out.println("Quit Selected");


               //"Reset" function will be illstrated;
               case "r":
               Reset reset = new Reset();
               Reset = CelebrityBot.reset;

               default :
               System.out.println("Impossible Command!");

        } 
        else
        {
        System.out.println("0 Moves.");      
        }

    }
     public void setTracing(boolean onOff)
    {
           onOff = onOff.setTracing;
           tracing = onOff;
    }


    public void trace(String message)
    { 
        if(tracing)
        {
            System.out.println("CelebStalker: " + message);
        }
    }





  • 写回答

3条回答 默认 最新

  • Yoezzz 2019-05-23 18:30
    关注

    你提需求我给你写一个算了,这么乱的代码!

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘