Untitled

مسابقة بلغة الجافا لفريقين
mail@pastecode.io avatar
unknown
plain_text
a year ago
3.7 kB
4
Indexable
Never
package javaapplication20;

import java.util.Scanner;
import javax.swing.JOptionPane;
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
 */

/**
 *
 * @author attasam
 */
public class JavaApplication20 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        
        
          int numPlayers=2,counter=0;
          String t=" ",info=" ",info2=" ";
          char stop='0';
       
         
         
        

             
                 
               
                
                
                  
         String names[]=new String[numPlayers];///اسماء اللاعبين
         int score[]=new int[numPlayers];///درجات اللاعبين
         int res[]=new int[numPlayers];////لحفظ درجات اللاعبين
        
         for(int i=0; i<names.length; i++){
            
             names[i]=JOptionPane.showInputDialog(" ادخل اسم اللاعب"+(i+1));
             
                  }
          
                 
            while(stop=='0'){
                info2="";
                for(int m=0;m<names.length;m++){
                 
                    do{
                        score[m]=Integer.parseInt(JOptionPane.showInputDialog(" ادخل درجة اللاعب"+" "+ names[m]));
                    }while(score[m]<0 || score[m]>10);
                     
                res[m]+=score[m];
                info2+=names[m]+"  "+res[m]+'\n';
                
                   
               
                    
                 
                  
                  
                
            }     
                
                 JOptionPane.showMessageDialog(null, info2);
                 counter=0;
                
                 if(res[0]>=10 || res[1]>10){
                     counter++;
                     if(res[0]==res[1]){
                         
                     }
                     else{
                         stop='1';   
                            break;
                     }
                 }
                 System.out.println(counter+"  1= "+res[0]+"    2= "+res[1]);
                
                    
                      
                 if(counter==0){
                      int c;
                do{
                      c=Integer.parseInt(JOptionPane.showInputDialog(" هل تريد الانهاء اضغط صفر"));
                }while(c<0);
                   
                    if(c==0)
                        stop='1';
                    else
                         stop='0';
                 } 
                 
               
                
                     
                   
                    
                   
                
            }
            if(res[0]>res[1]){
                
                t="The winner team is "+names[0] +" => "+res[0];
            }
            else{
                 t="The winner team is "+names[1] +" => "+res[1];
            }
            if(res[0]==res[1])
                t="تعادل";
            
             for(int k=0; k<res.length;k++){
             
              
               info +=""+names[k]+" "+res[k]+"\n";
            
             
         }
        
                
                

           
             
         JOptionPane.showMessageDialog(null, info+t);
                
             
            
         
       
    }
    
}