Week #8 Challenge: Java

  • (6 Pages)
  • +
  • « First
  • 4
  • 5
  • 6

77 Replies - 16161 Views - Last Post: 18 October 2011 - 12:42 PM

#76 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: Week #8 Challenge: Java

Posted 24 May 2010 - 09:05 PM

View PostLetMeFinclOut, on 22 February 2010 - 08:13 PM, said:

I've also never been a fan of Java (though strangely enough, I've taken a liking to C#). But VBScript!? ...Cobal!? ...BASIC!?!?


Resistance is futile. You will be assimilated. :D
Was This Post Helpful? 2
  • +
  • -

#77 stallone  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-November 10

Re: Week #8 Challenge: Java

Posted 25 November 2010 - 08:09 PM

A BASIC JAVA BASE CONVERSION PROGRAM available for download at http://sourceforge.n...ects/burakaltr/

It works for float point Numbers..

import javax.naming.directory.SchemaViolationException;
import javax.print.attribute.SupportedValuesAttribute;
import java.math.*;
import java.util.Scanner;
class baseConvert   {
    public static void main(String[] args) 
    {
            double tab2,num,onluk,num2,tabson,
           k;
                      double tab1,i;
            
            double[] dig=new double[100];
            double[] tab2lik=new double[100];
            int[] tab2likint=new int[100];
while(true){
            Scanner in = new Scanner(System.in);
            System.out.println("  ");

                         System.out.println(" enter base 1 ");
                         tab1 = in.nextDouble();

                         
                         System.out.println(" enter base 2 ");
                         tab2 = in.nextDouble();       
                         
                         
                         System.out.println(" enter number 1 ");
                         num = in.nextDouble();
                         for(int i1=0;i1<=19;i1++)
                         {
                        	 tab2lik[i1]=0;dig[i1]=0;
                         }
                         onluk=0;
                         num2=num;
                         k=0;
                         for(int i1=0;i1<=19;i1++)
                         {
                        	 k=k+1;
                        	dig[i1]=num % 10;
                        	//if(dig[i1]<0){dig[i1]=dig[i1]+10;}
                        	num=(num-dig[i1])/10;
                                  
                         }
                                      
                      
                         onluk=0;
                    
                         i=0;
                         for(int i1=0;i1<=k;i1++)
                         {
                        	 i=Math.pow(tab1,i1);
                        	 
                        	 
                         	 onluk=dig[i1]*(i)+onluk;
                                                 	                	 
                         }   
                         if(tab1==10){
                    		 onluk=num2;
                    	 }
                    	 if(num2<10){
                     		onluk=num2;
                     }
                          tabson=0;
 
                         for(int i1=0;i1<=k;i1++)
                         {
                        	 tab2lik[i1]=onluk % tab2;
                           	 onluk=((onluk-tab2lik[i1])) 
                    ;
                        	 onluk=onluk/tab2;
                           
                          
                         }  	 
   
                       tabson=0;
                       System.out.println(num2+" in base "+tab1+" = "+" in base "+ tab2+" equals the number below :");
                  	    
                         
                     for( int i1=50;i1>=0;i1--)
                        {
                      	  tab2likint[i1]= (int) tab2lik[i1];
                    	 
                    	 System.out.print("" + tab2likint[i1] );
                        	 
                      
                        }  	 
                            
                            }}}             

public class Convertor {
public static void  main(String args[]){
while(true){
		  	  String SV,SV2;
		  	 char CONVTD[]=new char[100];char TEXT[] = new char[100];
		  	 double TOTCONVA = 0,TOTCONVB = 0;double SB,DB;
		  	char[] CONVTD2=new char[100];
		  	int POWDET = 0,T,PREC,NEXT,i,j,k,I = 0,t = 0,DUMMY,K = 0;
		  	int FRACT[]=new int[100];
		  	 char d;
		  	int WHOLE[]=new int[100];  	  
		  	int INTEG[]=new int[100];	  
		  	    	double TOTCONV,P,SBTOTCONVA,LEFTA,PROD;
		  	    	double[]CONVTDA=new double[100];
	    	Scanner in=new Scanner(System.in);	    	System.out.println(" ");

	    	System.out.println("Enter SB: ");
	    	SB=(int) in.nextDouble();
	    	System.out.println("Enter DB: ");
	    	DB=in.nextDouble();
	    	System.out.println("Enter SOURCE VARIABLE: ");
	    	SV=in.next();
	    	SV2=SV;   for(i=0;i<100;i++)	 TEXT[i]='0';
;	  
	 for(i=0;i<SV2.length();i++) {  
		 
		 
		int intg=(int)(SV2.charAt(i)); 
	 // if((intg>=97)&&(intg<=122)) )
	  if((intg>=97) &&(intg<=122)){ 	

	   
		// if( (int)(SV.charAt(i))>=97 )&&( (int)( SV.charAt(i))<=122)
		 
		 d=SV2.charAt(i);
		 
		 SV2.replace(SV.charAt(i),(char) (d-32));}
//	System.out.print(SV2);			 
	 }
			 			 

	 for(i=0;i<SV2.length()-1;i++){
	  if((0<=SB) &&(9>=SB)) 	{
	    	if((int)SV2.charAt(i)>=SB+48)System.out.println("DIGITAL VIOLATION");}
	  
	    	
	   if(10<=SB){
	   
		   if( (int)(SV2.charAt(i))>=SB+55)System.out.println("DIGITAL VIOLATION");
	   }}

	 
	      PREC= 40;
	      K=0;
	      TOTCONV=0;
	      TOTCONVA=0;
	      TOTCONVB=0;
	      POWDET=SV2.indexOf('.');

  		 /* d=(char)(SV2.charAt(i)); 
  		   int intg = (int)d;*/
  		  for(i=0;i<POWDET;i++) { 
  			d=(char)(SV2.charAt(i)); 
   		   int intg = (int)d;
  			  
	      if(intg>=48&&(intg<=57))WHOLE[i]=intg-48;
	      if( intg>=65&&(intg<=90))WHOLE[i]=(int)SV2.charAt(i)-55;
	    	TOTCONVA=(double)(TOTCONVA+WHOLE[i]*Math.pow(SB*1., POWDET-1));
	    	if(SV2.charAt(i)=='.')break;
	    		  }

	    for(i=POWDET+1;i<SV2.length();i++){	
	    
	    	
	    	K=K+1;  		
	    	int  intg1=(int)(SV2.charAt(i)); 

	    	if(intg1>=48 && (intg1<=57))FRACT[i]=intg1-48;
	    	
	    		    	if(intg1>=65&&intg1<=90)FRACT[i]=intg1-55;

	    	 P=Math.pow(SB, -K*1.);TOTCONVB=TOTCONVB+FRACT[i]*P;	}
		LEFTA=TOTCONVA;
	 for(i=0;i<SV2.length();i++){
    	if(0<=LEFTA&&LEFTA<=DB-1){
    		t=i;
    	break;
    	}
    	if(Math.pow(DB,i)<=LEFTA&& LEFTA<=Math.pow(DB,i+1)-1){
    	                                        t=i;
break;}
 }
for(j=t;j>=0;j--){
CONVTDA[j]=(LEFTA % DB);System.out.println(CONVTDA[j]);
	 LEFTA=((LEFTA-(LEFTA%DB))) ;
	 LEFTA=(LEFTA/DB);//System.out.println((int)LEFTA);
if(CONVTDA[j]>=0&&(CONVTDA[j])<=9)CONVTD[j]=(char)(CONVTDA[j]+48)	;
if(CONVTDA[j]>=10&&(CONVTDA[j])<=35)CONVTD[j]=(char)(CONVTDA[j]+55);
 

//CONVTD[j]=(char) ((int)(CONVTDA[j])+48);
//System.out.print(CONVTD[j]);


}
  for(j=0;j<t+1;j++)TEXT[j]=(char)CONVTD[j];
	 
 NEXT=t+1;
 TEXT[NEXT]='.';
 NEXT=NEXT+1;
 T=0;
 for(j=0;j<PREC;j++){
	 PROD=TOTCONVB*DB;
	 INTEG[j]=(int)PROD;
	 T=T+1;
	 PROD=TOTCONVB*DB;
	 if(INTEG[j]>=0&&INTEG[j]<=9)CONVTD2[j]=(char)(INTEG[j]+48);
 	 
	 if(INTEG[j]>=10&&INTEG[j]<=35)CONVTD2[j]=(char)(INTEG[j]+55);
	 if(TOTCONVB-INTEG[j]==0)break;
	 TOTCONVB=DB*TOTCONVB-INTEG[j];
	  }
 for(j=0;j<T-1;j++)TEXT[NEXT+j]=CONVTD2[j];
 
 for(i=NEXT+j;i<40;i++)TEXT[i]=' ';
 
 for(j=0;j<40;j++)System.out.print(TEXT[j]);
		}}}








Was This Post Helpful? 0
  • +
  • -

#78 burhanaras  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-October 11

Re: Week #8 Challenge: Java

Posted 18 October 2011 - 12:42 PM

Hi guys, here is avery cool robot program. I opens Notepad and types text that you want. Have fun.
(for full source code: http://burhanaras.blogspot.com)

/**
 * 
 */
package paket;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.io.IOException;

/**
 * @author Burhan ARAS
 *
 */
public class RobotMain {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws AWTException 
	 * @throws InterruptedException 
	 */
	static Robot robot = null;
	
	public RobotMain() throws AWTException{
		
	}
	public static void main(String[] args) throws IOException, AWTException, InterruptedException {
		// TODO Auto-generated method stub
		robot = new Robot();
		openProgram("notepad.exe");
		writeToNotePad("Selamun Aleykum, dude.");
		
	}
	
	private static void writeToNotePad(String string	) throws AWTException, InterruptedException {
		writeToNotePad(string,1,CharacterCase.NORMAL);
	}

	private static void writeToNotePad(String string, double timestamp,
			CharacterCase charcase) throws AWTException, InterruptedException {
		// TODO Auto-generated method stub
		
		
		// time to type
		for(char c : string.toCharArray()){
			
			//uppercase or lowercase?
			boolean isOnCapsLock = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
			switch (charcase) {
				case NORMAL : 
					if(Character.isUpperCase(c) && !isOnCapsLock ){
						robot.keyPress(KeyEvent.VK_CAPS_LOCK);
					}else if (Character.isLowerCase(c) && isOnCapsLock){
						robot.keyPress(KeyEvent.VK_CAPS_LOCK);
					}
					break;
				case LOWERCASE: 
					if(isOnCapsLock) robot.keyPress(KeyEvent.VK_CAPS_LOCK);System.out.println(2);
					break;
				case UPPERCASE:
					if(!isOnCapsLock) robot.keyPress(KeyEvent.VK_CAPS_LOCK);System.out.println(3);
					break;
				default:break;

			}
			
			typeKey(c);
			Thread.sleep((long)(timestamp * 1000));
		}
		

	}

	private static void typeKey(char c) throws AWTException {
		// TODO Auto-generated method stub
		
		switch(c){
			case 'a' :
			case 'A' : robot.keyPress(KeyEvent.VK_A);break;
			case 'b' :
			case 'B' : robot.keyPress(KeyEvent.VK_B)/>;break;
			case 'c' :
			case 'C' : robot.keyPress(KeyEvent.VK_C);break;
			case 'd' :
			case 'D' : robot.keyPress(KeyEvent.VK_D);break;
			case 'e' :
			case 'E' : robot.keyPress(KeyEvent.VK_E);break;
			case 'f' :
			case 'F' : robot.keyPress(KeyEvent.VK_F);break;
			case 'g' :
			case 'G' : robot.keyPress(KeyEvent.VK_G);break;
			case 'h' :
			case 'H' : robot.keyPress(KeyEvent.VK_H);break;
			case 'i' :
			case 'I' : robot.keyPress(KeyEvent.VK_I);break;
			case 'j' :
			case 'J' : robot.keyPress(KeyEvent.VK_J);break;
			case 'k' :
			case 'K' : robot.keyPress(KeyEvent.VK_K);break;
			case 'l' :
			case 'L' : robot.keyPress(KeyEvent.VK_L);break;
			case 'm' :
			case 'M' : robot.keyPress(KeyEvent.VK_M);break;
			case 'n' :
			case 'N' : robot.keyPress(KeyEvent.VK_N);break;
			case 'o' :
			case 'O' : robot.keyPress(KeyEvent.VK_O);break;
			case 'p' :
			case 'P' : robot.keyPress(KeyEvent.VK_P);break;
			case 'q' :
			case 'Q' : robot.keyPress(KeyEvent.VK_Q);break;
			case 'r' :
			case 'R' : robot.keyPress(KeyEvent.VK_R);break;
			case 's' :
			case 'S' : robot.keyPress(KeyEvent.VK_S);break;
			case 't' :
			case 'T' : robot.keyPress(KeyEvent.VK_T);break;
			case 'u' :
			case 'U' : robot.keyPress(KeyEvent.VK_U);break;
			case 'v' :
			case 'V' : robot.keyPress(KeyEvent.VK_V);break;
			case 'w' :
			case 'W' : robot.keyPress(KeyEvent.VK_W);break;
			case 'x' :
			case 'X' : robot.keyPress(KeyEvent.VK_X);break;
			case 'y' :
			case 'Y' : robot.keyPress(KeyEvent.VK_Y);break;
			case 'z' :
			case 'Z' : robot.keyPress(KeyEvent.VK_Z);break;
			case ' ' : robot.keyPress(KeyEvent.VK_SPACE);break;
			case '.' : robot.keyPress(KeyEvent.VK_PERIOD);break;
			case ',' : robot.keyPress(KeyEvent.VK_COMMA);break;
			case ';' : robot.keyPress(KeyEvent.VK_SEMICOLON);break;
			case ':' : robot.keyPress(KeyEvent.VK_COLON);break;
			case '!' : robot.keyPress(KeyEvent.VK_EXCLAMATION_MARK);break;
			
			
		}
	}

	private static void openProgram(String pgm) throws IOException{
		Runtime.getRuntime().exec(pgm);	
	}
}


Was This Post Helpful? 0
  • +
  • -

  • (6 Pages)
  • +
  • « First
  • 4
  • 5
  • 6