battle programmers alliance

battle programminga forum for elite programmerswith extreme will powerto sharpen theire skills
 
HomeCalendarFAQSearchMemberlistUsergroupsRegisterLog in
Search
 
 

Display results as :
 
Rechercher Advanced Search
Latest topics
» mini A.I puzzles
Mon Apr 23, 2018 11:38 am by Moti Barski

» java and MySQL
Sun Apr 15, 2018 8:57 pm by Moti Barski

» java convert string to unicode
Sun Mar 25, 2018 8:40 pm by Admin

» java eclipse oxygen grimoire
Sat Mar 24, 2018 8:31 pm by Admin

» problem java dynamic web
Sat Mar 24, 2018 6:10 am by Admin

» auto programming dev
Wed Mar 14, 2018 8:42 pm by Admin

» JAVA design patterns
Wed Mar 07, 2018 9:53 pm by Admin

» vb.net morse ear with net lingo beef up:
Sun Mar 04, 2018 10:30 pm by Moti Barski

» java concept input output class
Tue Feb 20, 2018 7:21 pm by Admin

April 2018
SunMonTueWedThuFriSat
1234567
891011121314
15161718192021
22232425262728
2930     
CalendarCalendar
Social bookmarking
Social bookmarking digg  Social bookmarking delicious  Social bookmarking reddit  Social bookmarking stumbleupon  Social bookmarking slashdot  Social bookmarking yahoo  Social bookmarking google  Social bookmarking blogmarks  Social bookmarking live      

Bookmark and share the address of battle programmers alliance on your social bookmarking website
Share | 
 

 auto programming dev

Go down 
AuthorMessage
Admin
Admin
avatar

Posts : 105
Join date : 2011-08-01

PostSubject: auto programming dev   Tue Jan 09, 2018 5:03 pm


_________________
kurayami no kagi  _____    
Back to top Go down
View user profile https://yotamarker.justforum.net
Admin
Admin
avatar

Posts : 105
Join date : 2011-08-01

PostSubject: deck build Auto program puzzle   Fri Jan 19, 2018 6:42 pm

card class :
Code:

package gambit;

public class Card {
 String type, color;
 int level;
 public void printCard() {
 
 switch (level) {
 case 1:System.out.println("Ace of " + type);break;
 case 11:System.out.println("prince of " + type);break;
 case 12:System.out.println("queen of " + type);break;
 case 13:System.out.println("king of " + type);break;
 default:System.out.println(color + " " + type + " level " + level);break;
 }
 }
}
deck class :

Code:

package gambit;

public class Deck {
 Card[] cards = new Card[52];
 public void initDeck() {
 for (int i = 0; i < 13; i++) {
 cards[i] = new Card();
 cards[i].type = "clubs";
 cards[i].color = "black";
 cards[i].level = i+1;
 }
 for (int i = 13; i < 26; i++) {
 cards[i] = new Card();
 cards[i].type = "hearts";
 cards[i].color = "red";
 cards[i].level = i-12;
 }
 for (int i = 26; i < 39; i++) {
 cards[i] = new Card();
 cards[i].type = "spades";
 cards[i].color = "black";
 cards[i].level = i-25;
 }
 for (int i = 39; i < 52; i++) {
 cards[i] = new Card();
 cards[i].type = "diamonds";
 cards[i].color = "red";
 cards[i].level = i-38;
 }
 }
 public void printDeck() {
 for (int i = 0; i < 52; i++) {
 cards[i].printCard();
 }
 
 }
}
Main class : (set as public static void main)
Code:

package gambit;

public class Main {

 public static void main(String[] args) {
 // TODO Auto-generated method stub
 Deck d1 = new Deck();
 d1.initDeck();
 d1.printDeck();
 }

}


_________________
kurayami no kagi  _____    
Back to top Go down
View user profile https://yotamarker.justforum.net
Admin
Admin
avatar

Posts : 105
Join date : 2011-08-01

PostSubject: Re: auto programming dev   Wed Jan 24, 2018 8:25 pm

class with constructor getter and setter

Code:
package morseCodePackage;

public class morseCode {
   private String user; // click on var and type alt + shift + s then select generate getters setters
   public String getUser() {
      return user;
   }
   public void setUser(String user) {
      this.user = user;
   }
   private static String lastMsg;
   public morseCode(String user) {this.user = user;} // I'm a constructor, use this. if the param names are
   // the same as the classes
   public String toMorse(String msg) {lastMsg = code(msg);return this.user + " " + this.lastMsg;}
   public String toHuman(String msg) {return this.user + " " + decoder(msg);}
   public static String code(String msg) {
      char[] arr = msg.toCharArray();
      String result ="";
      for (int i = 0; i < arr.length; i++) {
         
         result += charToMorse(arr[i]);
      }
      return result;
   }
   private static String charToMorse(char x) {
      String result="";
      switch (x) {
      case 'a': result = "*-";break;
      case 'b': result = "-***";break;
      case 'c': result = "-*-*";break;
      case 'd': result = "-**";break;
      case 'e': result = "*";break;
      case 'f': result = "**-*";break;
      case 'g': result = "--*";break;
      case 'h': result = "****";break;
      case 'i': result = "**";break;
      case 'j': result = "*---";break;
      case 'k': result = "-*-";break;
      case 'l': result = "*-**";break;
      case 'm': result = "--";break;
      case 'n': result = "-*";break;
      case 'o': result = "---";break;
      case 'p': result = "*--*";break;
      case 'q': result = "--*-";break;
      case 'r': result = "*-*";break;
      case 's': result = "***";break;
      case 't': result = "-";break;
      case 'u': result = "**-";break;
      case 'v': result = "***-";break;
      case 'w': result = "*--";break;
      case 'x': result = "-**-";break;
      case 'y': result = "-*--";break;
      case 'z': result = "--**";break;
      case '0': result = "-----";break;
      case '1': result = "*----";break;
      case '2': result = "**---";break;
      case '3': result = "***--";break;
      case '4': result = "****-";break;
      case '5': result = "*****";break;
      case '6': result = "-****";break;
      case '7': result = "--***";break;
      case '8': result = "---**";break;
      case '9': result = "----*";break;
      case '.': result = "*-*-*-";break;
      case ',': result = "--**--";break;
      case '?': result = "**--**";break;
      case ' ': result = "/";break;
      
      default:
         break;
      }
      return result + "/";
   }
   public static String decoder(String msg) {
      
      String morseChr ="";
      String result = "";
      char[] arr = msg.toCharArray();
      for (int i = 0; i < arr.length; i++) {
         if(arr[i]!='/') {morseChr += arr[i];}
         else {result += morseCharToChar(morseChr);morseChr="";}
      }
      result = result.replaceAll("  ", " ");
      return result;
   }
   private static char morseCharToChar(String x) {
      char result='@';
      switch (x) {
      case "*-": result = 'a';break;
      case "-***": result = 'b';break;
      case "-*-*": result = 'c';break;
      case "-**": result = 'd';break;
      case "*": result = 'e';break;
      case "**-*": result ='f' ;break;
      case "--*": result = 'g';break;
      case "****": result = 'h';break;
      case "**": result = 'i';break;
      case "*---": result = 'j';break;
      case "-*-": result = 'k';break;
      case "*-**": result = 'l';break;
      case "--": result = 'm';break;
      case "-*": result = 'n';break;
      case "---": result = 'o';break;
      case "*--*": result = 'p';break;
      case "--*-": result = 'q';break;
      case "*-*": result = 'r';break;
      case "***": result = 's';break;
      case "-": result = 't';break;
      case "**-": result = 'u';break;
      case "***-": result = 'v';break;
      case "*--": result = 'w';break;
      case "-**-": result = 'x';break;
      case "-*--": result = 'y';break;
      case "--**": result = 'z';break;
      case "-----": result = '0';break;
      case "*----": result = '1';break;
      case "**---": result = '2';break;
      case "***--": result = '3';break;
      case "****-": result = '4';break;
      case "*****": result = '5';break;
      case "-****": result = '6';break;
      case "--***": result = '7';break;
      case "---**": result = '8';break;
      case "----*": result = '9';break;
      case "*-*-*-": result = '.';break;
      case "--**--": result =',' ;break;
      case "**--**": result = '?';break;
      case "/": result = ' ';break;
      
      default:
         break;
      }
      if(result == '@') {result = ' ';}
      return result;
   }
   public static void describeME() {System.out.println("I'm a class that can code and decode morse code");}
}
main :
Code:
package morseCodePackage;

public class Main {

   public static void main(String[] args) {
      // TODO Auto-generated method stub
      System.out.println(morseCode.code("hadouken"));
      System.out.println(morseCode.code("over 9000"));
      String n1 = morseCode.code("hadouken");
      System.out.println(morseCode.decoder(n1));
      morseCode mc1 = new morseCode("moti");
      System.out.println(mc1.toMorse("souryuken"));
      System.out.println(mc1.toHuman("****/*-/-**/---/**-/-*-/*/-*/"));
      morseCode.describeME();
   }

}




_________________
kurayami no kagi  _____    
Back to top Go down
View user profile https://yotamarker.justforum.net
Admin
Admin
avatar

Posts : 105
Join date : 2011-08-01

PostSubject: polymorphism   Wed Jan 31, 2018 9:22 pm


_________________
kurayami no kagi  _____    
Back to top Go down
View user profile https://yotamarker.justforum.net
Admin
Admin
avatar

Posts : 105
Join date : 2011-08-01

PostSubject: Re: auto programming dev   Wed Jan 31, 2018 9:27 pm

singleton is a object that can be created only x amount of times, usually once.
used for objects like server connection and rare game objects.

singleton class :
Code:
package singleton;

public class Singleton {
   private static Singleton singleton; // array this to get x number of singletons enabled
   private Singleton() {
      System.out.println("new singleton instace has been created");
   }
   public static Singleton newInstance() {
      if(singleton == null) {
         singleton = new Singleton();
      }
      return singleton;
   }
}

summoning the singleton object :

Code:
package singleton;

public class Main {

   public static void main(String[] args) {
      // TODO Auto-generated method stub
      Singleton sing1 = Singleton.newInstance(); // can only create 1, all others point to the same object
      
      
   }

}


_________________
kurayami no kagi  _____    
Back to top Go down
View user profile https://yotamarker.justforum.net
Admin
Admin
avatar

Posts : 105
Join date : 2011-08-01

PostSubject: morphing the deck class into a singleton   Wed Jan 31, 2018 9:31 pm

Code:
package singleton;

public class Deck {
   private static Deck singleton;
   private Card[] cards = new Card[52];
   private Deck() {
      initDeck();
      System.out.println("new singleton instace has been created");
   }
   public static Deck newInstance() {
      if(singleton == null) {
         singleton = new Deck();
      }
      return singleton;
   }
    public void initDeck() {
    for (int i = 0; i < 13; i++) {
    cards[i] = new Card();
    cards[i].type = "clubs";
    cards[i].color = "black";
    cards[i].level = i+1;
    }
    for (int i = 13; i < 26; i++) {
    cards[i] = new Card();
    cards[i].type = "hearts";
    cards[i].color = "red";
    cards[i].level = i-12;
    }
    for (int i = 26; i < 39; i++) {
    cards[i] = new Card();
    cards[i].type = "spades";
    cards[i].color = "black";
    cards[i].level = i-25;
    }
    for (int i = 39; i < 52; i++) {
    cards[i] = new Card();
    cards[i].type = "diamonds";
    cards[i].color = "red";
    cards[i].level = i-38;
    }
    }
    public void printDeck() {
    for (int i = 0; i < 52; i++) {
    cards[i].printCard();
    }
   
    }
}

summoning a singleton Deck object (itch turn ichido(one time)) :

Code:
package singleton;

public class Main {

   public static void main(String[] args) {
      // TODO Auto-generated method stub
      Deck sing1 = Deck.newInstance(); // can only create 1, all others point to the same object
      
      
   }

}


_________________
kurayami no kagi  _____    
Back to top Go down
View user profile https://yotamarker.justforum.net
Admin
Admin
avatar

Posts : 105
Join date : 2011-08-01

PostSubject: Re: auto programming dev   Wed Jan 31, 2018 10:45 pm


_________________
kurayami no kagi  _____    
Back to top Go down
View user profile https://yotamarker.justforum.net
Moti Barski

avatar

Posts : 111
Join date : 2011-08-02

PostSubject: Re: auto programming dev   Mon Feb 05, 2018 9:48 am

an abs class doesn't have to have a constructor.

Code:
public abstract class AbsShape {
   public abstract int Area();
}

2nd class :
Code:

import java.util.regex.Matcher;

public class Square extends AbsShape{
   private int side;
   
   public int getSide() {
      return side;
   }

   public void setSide(int side) {
      this.side = side;
   }

   public Square(int side) {
      super();
      this.side = side;
   }

   @Override
   public int Area() {
      // TODO Auto-generated method stub
      return (int)Math.pow(side, 2); // powe ^
   }

}

Code:
public class Main {

   public static void main(String[] args) {
      // TODO Auto-generated method stub
      AbsShape ribua = new Square(5);
      System.out.println("area: " + ribua.Area());
   }

}
Back to top Go down
View user profile
Moti Barski

avatar

Posts : 111
Join date : 2011-08-02

PostSubject: abstract class   Mon Feb 05, 2018 9:50 am

an abstract class doesn't have to have a constructor.

Code:
public abstract class BaseClass {
   protected int x = 100; // visible to this base class and sub classes(that extend it)
   protected int y = 150;
   
   public int getX() {
      return x;
   }

   public void setX(int x) {
      this.x = x;
   }

   public int getY() {
      return y;
   }

   public void setY(int y) {
      this.y = y;
   }

   public abstract void AbstractMethode();
   
}

derived class :
Code:
public class DerivedClass extends BaseClass{
   
   @Override
   public void AbstractMethode() {this.x++;this.y++;}
}

main :
Code:
public class Main {

   public static void main(String[] args) {
      BaseClass patamon = new DerivedClass();
      patamon.AbstractMethode();
      System.out.println(patamon.getX() + " " + patamon.getY());
   }

}

output : 101 151

nani mo gissei nashi ni nani mo eru koto ga dekinai

Back to top Go down
View user profile
Moti Barski

avatar

Posts : 111
Join date : 2011-08-02

PostSubject: java interface jutsu   Mon Feb 05, 2018 9:54 am

an interface is like an item an object class can be equiped with.
interface contains methode signatures that has to be implemented in your object class.

right click the project folder in the package explorer window, interface.

Code:
public interface MyCalc {
   public int Add(int x, int y);
   public int subtract(int x, int y);
   public int Multiple(int x, int y);
   public int div(int x, int y);
}


2nd interface :

Code:
public interface MyCalc2 {
   public int Multiple(int x, int y);
   public int sum(int ... sigma);
}

create a class and add implements MyCalc,MyCalc2.
next click the error line under the class name and click add unimplemented methods.
finnally fill in the methodes body.
to get :

Code:
public class MainClass implements MyCalc,MyCalc2 {

   @Override
   public int sum(int... sigma) {
      // TODO Auto-generated method stub
      int result = 0;
      for (int i = 0; i < sigma.length; i++) {
         result += sigma[i];
      }
      return result;
   }

   @Override
   public int Add(int x, int y) {
      // TODO Auto-generated method stub
      return x+y;
   }

   @Override
   public int subtract(int x, int y) {
      // TODO Auto-generated method stub
      return x-y;
   }

   @Override
   public int Multiple(int x, int y) {
      // TODO Auto-generated method stub
      return x*y;
   }

   @Override
   public int div(int x, int y) {
      // TODO Auto-generated method stub
      return x/y;
   }

}

and creat some main class to test MainClass

pirat

Back to top Go down
View user profile
Moti Barski

avatar

Posts : 111
Join date : 2011-08-02

PostSubject: link extra   Mon Feb 12, 2018 7:54 am

Back to top Go down
View user profile
Admin
Admin
avatar

Posts : 105
Join date : 2011-08-01

PostSubject: Re: auto programming dev   Wed Mar 14, 2018 8:42 pm



(concept) summoning requests from cmds :
token class (the above pattern) :
Code:
import java.util.HashSet;
import java.util.Scanner;

public class TokenClass {
   private static HashSet<String> CMDs = new HashSet<>();
   // AGI, goals
   public static void enable(String cmd, String skill) {CMDs.add(cmd+" " + skill);}
   public static void disable(String cmd, String skill) {CMDs.remove(cmd+" " + skill);}
   public static boolean isAble(String cmd, String skill) {return CMDs.contains(cmd+" " + skill);}
//   public static void enableWithGoalBundle(String bundle, String cmd, String skill) {
//      CMDs.add(bundle + " " + cmd + " " + skill);
//      }
   public void Activate(String cmd, String g) {
      if(isAble(cmd, g)) {
         switch (g) {
         case "create":
            Scanner s1 = new Scanner(System.in);System.out.println("enter name");
            String x = s1.next();
            System.out.println("enter field_value_field_value...");
            String y = s1.next();
            y= y.replaceAll("_", " ");
            JsonCRUDA.create(x, y);
            break;

         default:
            break;
         }
      }
      else {System.out.println("unAble to do that");}
   }
}

JSON Create Remove Update Delete Add

Code:
import org.json.JSONArray;
import org.json.JSONObject;

public class JsonCRUDA{
   private static JSONObject cars = new JSONObject();
   public static JSONObject getCars() {
      return cars;
   }

   public static boolean create(String name, String attributes) {
      // TODO Auto-generated method stub
      String[] strArr = attributes.split(" ");
      cars.put(name, new JSONArray());
      cars.getJSONArray(name).put(new JSONObject());
      for (int i = 0; i < strArr.length / 2; i++) {
         cars.getJSONArray(name).getJSONObject(0).put(strArr[i*2], strArr[i*2+1]);
      }
      System.out.println(cars);
      
      return false;
   }

   public static String Read(String name, String Id, String field) {
      // TODO Auto-generated method stub
      String result="";
      JSONArray jArr = cars.getJSONArray(name);
        for (Object object : jArr) {
          if(((JSONObject)object).get("id").equals(Id))
          {result = ((JSONObject)object).get(field).toString();break;}
        }
      return result;
   }

   public static boolean Update(String name, String Id, String field, String newVal) {
      // TODO Auto-generated method stub
      JSONArray jArr = cars.getJSONArray(name);
        for (Object object : jArr) {
          if(((JSONObject)object).get("id").equals(Id))
          {((JSONObject)object).put(field, newVal);break;}
         
        }
        System.out.println(cars);
      return false;
   }

   public static boolean delete(String name) {
      // TODO Auto-generated method stub
      cars.remove(name);
      System.out.println(cars);
      return false;
   }

   public static boolean Add(String name, String attributes) {
      // TODO Auto-generated method stub
      String[] strArr = attributes.split(" ");
      cars.put(name, new JSONArray());
      cars.getJSONArray(name).put(new JSONObject());
      for (int i = 0; i < strArr.length / 2; i++) {
         cars.getJSONArray(name).put(new JSONObject().put(strArr[i*2], strArr[i*2+1]));
      }
      System.out.println(cars);
      return false;
   }

}

Json Print class :
Code:
import org.json.JSONArray;
import org.json.JSONObject;

public class printJson {
   public static void print(JSONObject x) {System.out.println(x);}
   public static void printCarJsonSum(JSONObject x) {
      double sum=0;
       for(String s : x.keySet()) {
           JSONArray jArr = x.getJSONArray(s);
           for (Object object : jArr) {
               sum += ((JSONObject)object).getDouble("price")*((JSONObject)object).getDouble("quantity");
           }
         }
       System.out.println(sum);
   }
}

Main :
Code:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import org.json.JSONArray;
import org.json.JSONObject;

public class main {

  public static void main(String[] args) {
     TokenClass tokenClass = new TokenClass();
     tokenClass.enable("secratary", "create");//init
     tokenClass.Activate("secratary", "create");
    
     //String path = "C:\\Users\\Lenovo\\eclipse-workspace\\Json\\writeDepottest2.json"; //"C:\\Users\\Lenovo\\Desktop\\HW\\writeDepottest.json";
      //JsonCRUDA carSys = new JsonCRUDA();
     JsonCRUDA.create("delorean", "price 30000 id flaxCapacitor quantity 1");
     JsonCRUDA.Add("nightRider", "price 1000 id wheel quantity 4");
     JsonCRUDA.delete("nightRider");
     JsonCRUDA.create("nightRider", "price 1000 id wheel quantity 4");
      System.out.println(JsonCRUDA.Read("delorean", "flaxCapacitor", "price"));
      JsonCRUDA.Update("delorean", "flaxCapacitor", "price", "60000");
      printJson.print(JsonCRUDA.getCars());
      printJson.printCarJsonSum(JsonCRUDA.getCars());
//      FileWriter fWriter;
//      try {
//        fWriter = new FileWriter(path);
//        fWriter.write(cars.toString());
//        fWriter.close();
//       
//      }
//      catch (IOException e) {
//        // TODO Auto-generated catch block
//        e.printStackTrace();
//      }
  }
  }

the project isn't clean or complete (cost time) but the concept is there (HADOUKEN )

_________________
kurayami no kagi  _____    
Back to top Go down
View user profile https://yotamarker.justforum.net
 
auto programming dev
Back to top 
Page 1 of 1
 Similar topics
-
» How to add auto-resize
» Command for auto populated text verification.
» Cedar Nyx's Auto Mug Formatter (For FEXP/FEXNA/FEDE)
» Auto Add to Cart
» Does Firefox Webdriver support Auto-complete feature?

Permissions in this forum:You cannot reply to topics in this forum
battle programmers alliance :: battle programming alliance :: chit chat-
Jump to: