The Official Programming Thread

asad3man

Omniscient
Jul 21, 2011
822
0
22
Karachi
thats simple if it doesnt violate my design in any way i use a reference variable otherwise i use other means

sorry man i live in a part of the world were skype and other stuff like it are blocked and my vpn has expired
I'm sorry. I'm not getting this point on how it does or it doesn't violate your design. :/
 

Newton

Well-known member
May 17, 2009
2,223
0
41
Lahore, Faisalabad
I'm sorry. I'm not getting this point on how it does or it doesn't violate your design. :/
ok i will keep it in the simplest form

My design is as follows

"A location will have a list of employees; and, each employee will have an assigned equipment"

i kept the design this way because it's my personal choice. there are no hard and fast rules to it. it's something that is based on experience and common sense. I only kept it like this because I liked it like this. Once you have your design thought out you can proceed to modeling your classes. I will model classes based on this design below

LOCATION
it is supposed to have a list of employees. so i can give it a reference variable of an array or linked list of type EMPLOYEE.
it is supossed to hhave an IT guy so i made a reference variable of type EMPLOYEE
it will have other reference variables as required by the problem at hand

EMPLOYEE
an employee is working at a location and is assigned an equipment
so i can straight away give it a reference variable of type EQUIPMENT
BUT -> if i give it a reference variable of type LOCATION i am creating kind of a paradox and my code will have unnecessary bugs in it
if i give EMPLOYEE a ref var of LOCATION and LOCATION a ref var of EMPLOYEE how can i create new objects? For example if i am making a LOCATION object without an EMPLOYEE list or without and EMPLOYEE ITguy i will have to add extra code to handle those situations. So to keep it simple for you i just made it as is

i hope this clears your view about my coding style in the example
 

asad3man

Omniscient
Jul 21, 2011
822
0
22
Karachi
i dont know about all of that UML stuff but here is a very basic working example

Equipment
Spoiler: show
Code:
import java.util.Date;


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


/**
 *
 * @author Adnan
 */
public class Equipment
{
    String type;
    String serial;
    String model;
    Boolean warranty;
    String user;
    String location;
    
    public Equipment(String t, String s, String m, Boolean b)
    {
        type = t;
        serial = s;
        model = m;
        warranty = b;
    }
    public String getUser()
    {
        return user;
    }
    public String getLocation()
    {
        return location;
    }
    public String prettyPrint()
    {
        String output = "";
        output += "\nEquipment: " + serial;
        output += "\nAssigned to: " + user;
        return output;
    }
}
Location
Spoiler: show
Code:
import java.util.ArrayList;


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


/**
 *
 * @author Adnan
 */
public class Location
{
    String name;
    int no_of_offices;
    ArrayList<Employee> office_employees;
    Employee ITGuy;
    ArrayList<Equipment> office_equipment;
    
    public Location (String n, int o, Employee IT)
    {
        name = n;
        no_of_offices = o;
        ITGuy = IT;
        office_employees = new ArrayList();
        office_equipment = new ArrayList();
    }
    
    public void addEmployee (Employee em)
    {
        office_employees.add (em);
        em.setLocation(name); //better way to do
    }
    public void addEquipment (Equipment e)
    {
        office_equipment.add (e);
        e.location = name;
    }
    public String prettyPrint()
    {
        String output = "";
        output += "Location: " + name;
        output += "\nNumber of offices = " + no_of_offices;
        output += "\nAmount of equipment = " + office_equipment.size();
        return output;
    }
}
Employee
Spoiler: show
Code:
import java.util.ArrayList;


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


/**
 *
 * @author Adnan
 */
public class Employee
{
    String name;
    char gender;
    String title;
    String department;
    Employee supervisor;
    String location;
    String coordinates;
    Equipment current_equipment;
    ArrayList<Equipment> past_equipment;
    
    public Employee (String n, char g, String t, String d, String c)
    {
        name = n;
        gender = g;
        title = t;
        department = d;
        coordinates = c;
    }
    public void setCurrentEquipment (Equipment e)
    {
        //add a small routine to check if its assigned to another user. remove from him
        if (current_equipment != null)
            past_equipment.add (current_equipment);
        current_equipment = e;
        e.user = name; 
        //you can set the equipment location here too
    }
    public void setLocation (String l)
    {
        location = l;
    }
    public String prettyPrint()
    {
        String output = "";
        output += "Name: " + name;
        output += "\nCurrently assigned: " + current_equipment.serial;
        return output;
    }
}
Main
Spoiler: show
Code:
import static java.lang.Boolean.*;


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


/**
 *
 * @author Adnan
 */
public class InventorySystem
{
    public static void main (String [] args)
    {
        Equipment e1 = new Equipment("Computer", "A123", "X7", TRUE);
        Equipment e2 = new Equipment("Printer", "B123", "A2", FALSE);
        
        Employee em1 = new Employee("Newton", 'M', "Agent47", "Leage of Assassins", "1234");
        
        Location l1 = new Location("Gotham", 1, em1);
        
        em1.setCurrentEquipment(e1);
        l1.addEmployee(em1);
        l1.addEquipment(e1);
        System.out.println (e1.prettyPrint());
        System.out.println (e2.prettyPrint());
        System.out.println (em1.prettyPrint());
        System.out.println (l1.prettyPrint());   
    }
}
all of this is in java and may not cover all the scenarios and may have mistakes and can be improved upon. Just wanted to show you how it might work. Good for OOP starters. If you have any questions just ask
Yaar I am confused more now. What the hell is going on.
Mei khud se bananay betha. Why can't we use setEmployee method in Equipment?
 

Newton

Well-known member
May 17, 2009
2,223
0
41
Lahore, Faisalabad
Yaar I am confused more now. What the hell is going on.
Mei khud se bananay betha. Why can't we use setEmployee method in Equipment?
does the Equipment class have an employee type reference variable? getters and setters are normally for private reference variables mostly

on the other hand you can see that there is a setEquipment method in the employee class.
gets and sets are normally simple and straightforward. what's confusing you about them?
 

asad3man

Omniscient
Jul 21, 2011
822
0
22
Karachi
does the Equipment class have an employee type reference variable? getters and setters are normally for private reference variables mostly

on the other hand you can see that there is a setEquipment method in the employee class.
gets and sets are normally simple and straightforward. what's confusing you about them?
Yaar. I 'm so much confused. Why can't we make setEquipment in employee class. I'm figuring it out. Mera zehn jo kehta hai k wo ban skta, this is my class so far. I'm still working on it. But I'm confused.
Spoiler: show

public class Equipment {
String type;
String num;
int model;
private String user;

Equipment(String type, String Num, int model)
{
this.type=type;
this.num=Num;
this.model=model;
}
public void setEmployee(Employee em)
{
user=em.name;
}

}


 

Newton

Well-known member
May 17, 2009
2,223
0
41
Lahore, Faisalabad
Yaar. I 'm so much confused. Why can't we make setEquipment in employee class. I'm figuring it out. Mera zehn jo kehta hai k wo ban skta, this is my class so far. I'm still working on it. But I'm confused.
Spoiler: show

public class Equipment {
String type;
String num;
int model;
private String user;

Equipment(String type, String Num, int model)
{
this.type=type;
this.num=Num;
this.model=model;
}
public void setEmployee(Employee em)
{
user=em.name;
}

}


aise keh na bhai...yes you can do that. that is perfectly valid
 

staticPointer

PG LEGENDARY
Dec 7, 2012
3,266
0
41
افغانستان
www.pakgamers.com
im trying to connect jdbc with mysql[phpmyadmin]... but the ide is not fetching the data from phpmyadmin ... any one can tell me ??

Spoiler: show





Code:
[COLOR=#ffffff]com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user ''@'localhost' to database 'uni'[/COLOR][COLOR=#ffffff]	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)[/COLOR]
[COLOR=#ffffff]	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)[/COLOR]
[COLOR=#ffffff]	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)[/COLOR]
[COLOR=#ffffff]	at java.lang.reflect.Constructor.newInstance(Unknown Source)[/COLOR]
[COLOR=#ffffff]	at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)[/COLOR]
[COLOR=#ffffff]	at com.mysql.jdbc.Util.getInstance(Util.java:387)[/COLOR]
[COLOR=#ffffff]	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:939)[/COLOR]
[COLOR=#ffffff]	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)[/COLOR]
[COLOR=#ffffff]	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)[/COLOR]
[COLOR=#ffffff]	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871)[/COLOR]
[COLOR=#ffffff]	at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1694)[/COLOR]
[COLOR=#ffffff]	at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1215)[/COLOR]
[COLOR=#ffffff]	at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2255)[/COLOR]
[COLOR=#ffffff]	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2286)[/COLOR]
[COLOR=#ffffff]	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2085)[/COLOR]
[COLOR=#ffffff]	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:795)[/COLOR]
[COLOR=#ffffff]	at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)[/COLOR]
[COLOR=#ffffff]	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)[/COLOR]
[COLOR=#ffffff]	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)[/COLOR]
[COLOR=#ffffff]	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)[/COLOR]
[COLOR=#ffffff]	at java.lang.reflect.Constructor.newInstance(Unknown Source)[/COLOR]
[COLOR=#ffffff]	at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)[/COLOR]
[COLOR=#ffffff]	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400)[/COLOR]
[COLOR=#ffffff]	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:327)[/COLOR]
[COLOR=#ffffff]	at java.sql.DriverManager.getConnection(Unknown Source)[/COLOR]
[COLOR=#ffffff]	at java.sql.DriverManager.getConnection(Unknown Source)[/COLOR]
[COLOR=#ffffff]	at jdbc.Driver.main(Driver.java:11)[/COLOR]
 

Newton

Well-known member
May 17, 2009
2,223
0
41
Lahore, Faisalabad

EternalBlizzard

Lazy guy :s
Moderator
Oct 29, 2011
2,732
1,195
129
Attractor Field Beta
I implemented Dijkstra's pathfinding algorithm in OpenGL in Java. Just thought i'd share some images with ya guys..
The brown tiles are walls (impassable) The blue ones are water require more cost to move through. The yellow ones are the source and destination. The algorithm finds the shortest path between any two nodes/points. One of its use is in 2d tile based RPG games.
Spoiler: show





EDIT:- I'll encourage you guys to post things like this if you have done them. That way everyone can get to know who has done work in which area... i dunno about others, would be helpful for me atleast xDD
 

Attachments

Last edited:

staticPointer

PG LEGENDARY
Dec 7, 2012
3,266
0
41
افغانستان
www.pakgamers.com
I implemented Dijkstra's pathfinding algorithm in OpenGL in Java. Just thought i'd share some images with ya guys..
The brown tiles are walls (impassable) The blue ones are water require more cost to move through. The yellow ones are the source and destination. The algorithm finds the shortest path between any two nodes/points. One of its use is in 2d tile based RPG games.
Spoiler: show





wooooowwww thats soo cool man .. how did u changed the eclipse console background colors man ??? tell me
 

EternalBlizzard

Lazy guy :s
Moderator
Oct 29, 2011
2,732
1,195
129
Attractor Field Beta
wooooowwww thats soo cool man .. how did u changed the eclipse console background colors man ??? tell me
Use this site to get the plugin
The Eclipse Color Theme Plugin - Eclipse Color Themes

Then go to Window > Preference >General > appearance
and play around with the options... The syntax coloring is customized tho, i didn't found anything like that of Visual Studio so simple and dark just like i want.. so i customized it.
 
Last edited:

asad3man

Omniscient
Jul 21, 2011
822
0
22
Karachi
Well I find lost myself in OOP paradigm. :( Concepts are all clear but I don't know what to implement,m how to implement, why to implement. :(
Somebody help me please.
I ahve been handed over the project either pacman , circuit desinger or intergration solver.
 

EternalBlizzard

Lazy guy :s
Moderator
Oct 29, 2011
2,732
1,195
129
Attractor Field Beta
Well I find lost myself in OOP paradigm. :( Concepts are all clear but I don't know what to implement,m how to implement, why to implement. :(
Somebody help me please.
I ahve been handed over the project either pacman , circuit desinger or intergration solver.
When you start solving think of the core structure of the program. Take pacman as an example. Suppose you are creating the map for pacman, take that work in separate class, now take the actual game functionality like managing scores and eating the balls etc in a separate class. Try to see what's common in classes, make a super class for that simple.
 

Newton

Well-known member
May 17, 2009
2,223
0
41
Lahore, Faisalabad
a better explanation is to make
  • a map class which has some representation of a map and methods to move through the map
  • a character class which will represent an ingame character and how it can use the map class' navigation methods
  • a pacman class which will be a child class of the character class which will move him through the map (using input), count score, calculate death senarios etc
  • an enemy class which will be a child class of the character class which will move them through the map randomly
  • a main class which will have the main method and create the objects of pacman, enemy and map and govern the flow of the game through the other classes


for a circuit designer you may have
  • A component class which has the most bacis information of a component (# of connections, VIR ratings, etc)
  • An individual class (child class of component) for each specific type of component (Resister, capacitor, battery etc). this class will have specific component details as per its parent class along with methods (V=IR etc)
  • A node class which will represent a connection between 2 or more components.
  • A main (circuit) class which will have a collection of components and nodes and would be able to perform various functions like KCL, KVL etc


PS : these are very crude examples of how you can develop a solution model. there will be much more refined ways of doing this. coming up with a good model comes with experience and practice so dont worry if this seems difficult to you in the start :)
 

asad3man

Omniscient
Jul 21, 2011
822
0
22
Karachi
a better explanation is to make
  • a map class which has some representation of a map and methods to move through the map
  • a character class which will represent an ingame character and how it can use the map class' navigation methods
  • a pacman class which will be a child class of the character class which will move him through the map (using input), count score, calculate death senarios etc
  • an enemy class which will be a child class of the character class which will move them through the map randomly
  • a main class which will have the main method and create the objects of pacman, enemy and map and govern the flow of the game through the other classes


for a circuit designer you may have
  • A component class which has the most bacis information of a component (# of connections, VIR ratings, etc)
  • An individual class (child class of component) for each specific type of component (Resister, capacitor, battery etc). this class will have specific component details as per its parent class along with methods (V=IR etc)
  • A node class which will represent a connection between 2 or more components.
  • A main (circuit) class which will have a collection of components and nodes and would be able to perform various functions like KCL, KVL etc


PS : these are very crude examples of how you can develop a solution model. there will be much more refined ways of doing this. coming up with a good model comes with experience and practice so dont worry if this seems difficult to you in the start :)
Man. Now take map class. How can I design a Map. you kidding? I don't even understand anything right here. :(

- - - Updated - - -

When you start solving think of the core structure of the program. Take pacman as an example. Suppose you are creating the map for pacman, take that work in separate class, now take the actual game functionality like managing scores and eating the balls etc in a separate class. Try to see what's common in classes, make a super class for that simple.
Didn't understand anything. :(
 

EternalBlizzard

Lazy guy :s
Moderator
Oct 29, 2011
2,732
1,195
129
Attractor Field Beta
^ lol, how to make the map class is for you to decide. Now your question changed. You have to search that on your own. Graphics will surely be involved so either you'll have to use a graphics library or develop it on windows forms/ swing/awt depending on the language you are using.

The main point was to be able to understand what classes do i have to make and what will be the relationship between them like Newton did. When you are able to do that, rest is just research material you can find easily on the internet.
 

Newton

Well-known member
May 17, 2009
2,223
0
41
Lahore, Faisalabad
Man. Now take map class. How can I design a Map. you kidding? I don't even understand anything right here. :(
that entirely depends on your approach towards programming. for a very basic solution i would
  1. take a piece of paper and a pencil
  2. sketch a pacman map on it
  3. brain storm what possible way i can represent it in my code
  4. i may use a 2D array of 1s and 0s where 1s will represent a wall and 0s represent an open space
  5. navigation methods can use the 0/1s to allow or block movement


11111
10011
11001
10001
11111


color up the 1s only in the above table and you will get how i represented a map
 
General chit-chat
Help Users
We have disabled traderscore and are working on a fix. There was a bug with the plugin | Click for Discord
  • No one is chatting at the moment.
    Necrokiller Necrokiller: Alan wake 2 is yet to recover it's development costs. Due to no physical release and no steam...