Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

i have created the java code as follows but it is not running properly please help me to fix the bug

0 votes
asked Jul 30, 2018 by Murali Krishnamurthy (120 points)
import java.lang.*;
import java.util.*;
public class tnElect
{ public String s[]={"Edappadi","Stalin","Kamal","Rajani","Tamil","Kushbu"};
  public int vote[]=new int[6];
  public int vote1[]=new int[6];
 //
   public void addDetails()
   { for(int i=0;i<s.length;++i)
     {System.out.println("DISPLAY THE CANDIDATE NAMES :");
      System.out.println(s[i]);
      System.out.println("PUT YOUR VOTE AGAINST YOUR CANDIDATE :");
      Scanner buf=new Scanner(System.in);
      vote[i]=buf.nextInt();
     }
    }
 //
   public void dispDetails()
   {  vote1=vote;
      swap(vote1,s.length);
      for(int i=0;i<s.length;++i)
       { if(s[i]=="Edappadi")
           {for(int j=0;j<s.length;++j)
               {if(vote1[1]==vote[j])
                 {System.out.println("EDAPPADI IS OUR NEXT TAMIL NADU CHIEF MINISTER");
                 }
                 break;
               }
            }
//            
        else if(s[i]=="Stalin")
           {for(int j=0;j<s.length;++j)
               {if(vote1[1]==vote[j])
                 {System.out.println("STALIN IS OUR NEXT TAMIL NADU CHIEF MINISTER");
                 }
                 break;
               }
            }
//
            else if(s[i]=="Kamal")
              {for(int j=0;j<s.length;++j)
                  {if(vote1[1]==vote[j])
                    {System.out.println("KAMAL IS OUR NEXT TAMIL NADU CHIEF MINISTER");
                      }
                     break;
                   }
                }
//
            
            else if(s[i]=="Rajani")
              {for(int j=0;j<s.length;++j)
                  {if(vote1[1]==vote[j])
                    {System.out.println("RAJANI IS OUR NEXT TAMIL NADU CHIEF MINISTER");
                      }
                     break;
                   }
              }
         
//
             else if(s[i]=="Tamil")
              {for(int j=0;j<s.length;++j)
                  {if(vote1[1]==vote[j])
                    {System.out.println("TAMIL IS OUR NEXT TAMIL NADU CHIEF MINISTER");
                      }
                     break;
                   }
              }
             
//            
              else if(s[i]=="Kushbu")
                {for(int j=0;j<s.length;++j)
                  {if(vote1[1]==vote[j])
                    {System.out.println("KUSHBU IS OUR NEXT TAMIL NADU CHIEF MINISTER");
                      }
                     break;
                   }
                }
        }
   }
  //
     public void swap(int vote1[],int n)
     { int temp;
         for(int i=0;i< n;++i)
            {for(int j=i+1;j<s.length;++j)
                {if(vote1[i]<vote1[j])
                   { temp=vote1[i];
                      vote1[i]=vote1[j];
                      vote1[j]=temp;
                   }
                }   
            }
     }       
//
    public static void main(String [] args)
    { System.out.println("TAMIL NADU ELECTION RESULTS");
      System.out.println("****************************");
      tnElect te= new tnElect();
      te.addDetails();
      te.dispDetails();
      System.out.println("****************************");
    }
};

1 Answer

0 votes
answered Oct 12, 2018 by anonymous
You should probably briefly explain what the bug is/was. We can't help when we do not know what this piece of code wants to achieve.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...