Knights of the Pixel Table
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Showing you all my code

3 posters

Go down

Showing you all my code Empty Showing you all my code

Post by _Dr.A Wed Feb 26, 2014 10:33 pm

This is just going to be a short little question. Simply put, would you all like to see some of the code I've written for a small program for school or just some random program I've made recently. This would be not necessarily, or only, be for anyone who knows java programming, but rather, to give you all an idea of what some smaller code looks like, if you don't already know.

Now, I have no idea if this is a good idea or not, or if anyone is even interested. But hey, you all could have some fun attempting to interpret/figure out what is going on.

Anyway, let me know your all's opinions down below.

~_Dr.A out!~ :3
_Dr.A
_Dr.A

Posts : 56
Join date : 2014-01-21
Age : 26
Location : Arkansas

Back to top Go down

Showing you all my code Empty Re: Showing you all my code

Post by Zitzabis Wed Feb 26, 2014 10:51 pm

Yeah! I'd like to see the code and program. I understand the layout of Java code so if you can, I'd like to see the project files.
Zitzabis
Zitzabis

Posts : 138
Join date : 2014-01-24
Location : Australia/Papua New Guinea

Back to top Go down

Showing you all my code Empty Re: Showing you all my code

Post by _Dr.A Wed Feb 26, 2014 10:53 pm

Well, just let me know specifics on how you want to see it. For instance, I could just copy and paste the code into a response one here.
_Dr.A
_Dr.A

Posts : 56
Join date : 2014-01-21
Age : 26
Location : Arkansas

Back to top Go down

Showing you all my code Empty Re: Showing you all my code

Post by Zitzabis Wed Feb 26, 2014 10:57 pm

Hmmm...that might be best actually.
Zitzabis
Zitzabis

Posts : 138
Join date : 2014-01-24
Location : Australia/Papua New Guinea

Back to top Go down

Showing you all my code Empty Re: Showing you all my code

Post by _Dr.A Wed Feb 26, 2014 10:59 pm

Ok, the one I'm going to send is of a dueling calculator for Yu-Gi-Oh. It has two class files, so I'll send them in two consecutive responses.
_Dr.A
_Dr.A

Posts : 56
Join date : 2014-01-21
Age : 26
Location : Arkansas

Back to top Go down

Showing you all my code Empty Re: Showing you all my code

Post by _Dr.A Wed Feb 26, 2014 11:00 pm

package duelingcalc;

import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;


public class DuelingCalc {

public static ArrayList contents = new ArrayList();
public static ImageIcon icon = new ImageIcon("C://");
public static String[] listOptions = {"DP", "SP", "M1", "::CALCULATE::", "BP", "M2", "EP"};
public static ArrayList phaseShow = new ArrayList();
public static void main(String[] args) {

int start = JOptionPane.showConfirmDialog(null, "Would you like to duel?");
switch(start){
case 0: playerOne();
case 1: System.exit(0);
case 2: System.exit(0);
}

}

public static void playerOne(){

String playerOneName = JOptionPane.showInputDialog(null, "Enter the name of player one:");
contents.add(playerOneName);
String holder1 = JOptionPane.showInputDialog(null, "Enter the LP of player one:");
int playerOneLP = Integer.parseInt(holder1);
contents.add(playerOneLP);
playerTwo();

}

public static void playerTwo(){

String playerTwoName = JOptionPane.showInputDialog(null, "Enter the name of player two:");
contents.add(playerTwoName);
String holder2 = JOptionPane.showInputDialog(null, "Enter the LP of player two:");
int playerTwoLP = Integer.parseInt(holder2);
contents.add(playerTwoLP);
duelingCalcPhases.phaseChooser();

}

}
_Dr.A
_Dr.A

Posts : 56
Join date : 2014-01-21
Age : 26
Location : Arkansas

Back to top Go down

Showing you all my code Empty Re: Showing you all my code

Post by _Dr.A Wed Feb 26, 2014 11:01 pm

package duelingcalc;

import javax.swing.JOptionPane;

public class duelingCalcPhases extends DuelingCalc{


public static void phaseChooser(){

phaseShow.add("You are in your draw phase.");
int phases = JOptionPane.showOptionDialog(null, (String)contents.get(0)+"'s LP: "+contents.get(1)+" ~ "+(String)contents.get(2)+"'s LP: "+contents.get(3)+" *What would you like to do?*", " Select an option:", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, icon, listOptions, -1);
switch(phases){
case 0: DP();
case 1: SP();
case 2: M1();
case 3: calculate();
case 4: BP();
case 5: M2();
case 6: EP();
}

}

public static void DP(){
phaseShow.set(0, "You are in your draw phase.");
phase();
}

public static void SP(){
phaseShow.set(0, "You are in your standby phase.");
phase();
}

public static void M1(){
phaseShow.set(0, "You are in your main phase 1.");
phase();
}

public static void BP(){
phaseShow.set(0, "You are in your battle phase.");
phase();
}

public static void M2(){
phaseShow.set(0, "You are in your main phase 2.");
phase();
}

public static void EP(){
phaseShow.set(0, "This is your end phase.");
phase();
}

private static void phase(){

int Phase = JOptionPane.showOptionDialog(null, (String)contents.get(0)+"'s LP: "+contents.get(1)+" ~ "+(String)contents.get(2)+"'s LP: "+contents.get(3)+" "+phaseShow, " Select an option:", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, icon, listOptions, -1);
switch(Phase){
case 0: DP();
case 1: SP();
case 2: M1();
case 3: calculate();
case 4: BP();
case 5: M2();
case 6: EP();
}
if(Phase == JOptionPane.CLOSED_OPTION){
System.exit(0);
}

}

public static void calculate(){

String[] playerCalcChoose = {(String)contents.get(0), (String)contents.get(2)};
int Phase = JOptionPane.showOptionDialog(null, "Calculate "+contents.get(0)+" or "+contents.get(2)+"'s life points?", " Select an option:", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, icon, playerCalcChoose, -1);
switch(Phase){
case 0: P1();
case 1: P2();
}
if(Phase == JOptionPane.CLOSED_OPTION){
System.exit(0);
}

}

public static void P1(){

String[] calcP1 = {"Add", "Subtract"};
int P1Calc = JOptionPane.showOptionDialog(null, " Add or Subtract?", " Select an option:", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, icon, calcP1, -1);
switch(P1Calc){
case 0: P1add(P1Calc);
case 1: P1sub(P1Calc);

}
if(P1Calc == JOptionPane.CLOSED_OPTION){
System.exit(0);
}

}
public static void P1add(int P1Calc){
String addHolder = JOptionPane.showInputDialog(null, "Input the number to add:");
int add = Integer.parseInt(addHolder);
contents.set(1, (int)contents.get(1)+add);
phase();
}
public static void P1sub(int P1Calc){
String subHolder = JOptionPane.showInputDialog(null, "Input the number to add:");
int sub = Integer.parseInt(subHolder);
contents.set(1, (int)contents.get(1)-sub);
phase();
}

public static void P2(){

String[] calcP2 = {"Add", "Subtract"};
int P2Calc = JOptionPane.showOptionDialog(null, " Add or Subtract?", " Select an option:", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, icon, calcP2, -1);
switch(P2Calc){
case 0: P2add(P2Calc);
case 1: P2sub(P2Calc);
}
if(P2Calc == JOptionPane.CLOSED_OPTION){
System.exit(0);
}

}
public static void P2add(int P2Calc){
String addHolder2 = JOptionPane.showInputDialog(null, "Input the number to add:");
int add2 = Integer.parseInt(addHolder2);
contents.set(3, (int)contents.get(3)+add2);
phase();
}
public static void P2sub(int P2Calc){
String subHolder2 = JOptionPane.showInputDialog(null, "Input the number to add:");
int sub2 = Integer.parseInt(subHolder2);
contents.set(3, (int)contents.get(3)-sub2);
phase();
}

}
_Dr.A
_Dr.A

Posts : 56
Join date : 2014-01-21
Age : 26
Location : Arkansas

Back to top Go down

Showing you all my code Empty Re: Showing you all my code

Post by _Dr.A Wed Feb 26, 2014 11:01 pm

ta-da
_Dr.A
_Dr.A

Posts : 56
Join date : 2014-01-21
Age : 26
Location : Arkansas

Back to top Go down

Showing you all my code Empty Re: Showing you all my code

Post by Rabid Wed Feb 26, 2014 11:43 pm

Well, now I feel stupid. LOL
Rabid
Rabid

Posts : 100
Join date : 2014-01-24

Back to top Go down

Showing you all my code Empty Re: Showing you all my code

Post by _Dr.A Wed Feb 26, 2014 11:48 pm

Nah, you're not stupid. But it actually is a little easier to follow if it's in the IDE I use for writing code
_Dr.A
_Dr.A

Posts : 56
Join date : 2014-01-21
Age : 26
Location : Arkansas

Back to top Go down

Showing you all my code Empty Re: Showing you all my code

Post by Rabid Wed Feb 26, 2014 11:52 pm

Yeah, I only know a couple things of code. Simple true or false statements, very basic stuff.
Rabid
Rabid

Posts : 100
Join date : 2014-01-24

Back to top Go down

Showing you all my code Empty Re: Showing you all my code

Post by Zitzabis Thu Feb 27, 2014 6:47 pm

Yeah, your code is different to what I've learnt. Well, your techniques are. I'm not seeing any if, else or if else statements. Plus, I don't understand some of the tools from JOptions. But that just depends on one's knowledge of that specific areas. I understand the I/O tool fairly well, but not this! Razz
Zitzabis
Zitzabis

Posts : 138
Join date : 2014-01-24
Location : Australia/Papua New Guinea

Back to top Go down

Showing you all my code Empty Re: Showing you all my code

Post by _Dr.A Thu Feb 27, 2014 9:56 pm

Ah, yes. There are some cases there where I used switch and case, but possibly could have used if and elses. I just prefer using that, at least when dealing with JOptionPane
_Dr.A
_Dr.A

Posts : 56
Join date : 2014-01-21
Age : 26
Location : Arkansas

Back to top Go down

Showing you all my code Empty Re: Showing you all my code

Post by _Dr.A Thu Feb 27, 2014 10:10 pm

ArrayLists, I also used ArrayLists a bit
_Dr.A
_Dr.A

Posts : 56
Join date : 2014-01-21
Age : 26
Location : Arkansas

Back to top Go down

Showing you all my code Empty Re: Showing you all my code

Post by Zitzabis Fri Feb 28, 2014 8:53 am

I have only heard of ArrayLists. Don't know too much about them.

I also have a project suggestions that I'll talk to you about maybe tomorrow. I plan to Skype you.
Zitzabis
Zitzabis

Posts : 138
Join date : 2014-01-24
Location : Australia/Papua New Guinea

Back to top Go down

Showing you all my code Empty Re: Showing you all my code

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum