User talk:Descasenas

import java.util.Scanner;

public class Activity01{ static Scanner sc=new Scanner(System.in); public static void main( String[] args ){ int ans; do{ System.out.print("Enter time in 24-hr format (hh mm): ");

int hh = sc.nextInt; int mm = sc.nextInt;

String am = "A.M."; String pm = "P.M.";

if (mm < 60 && mm >= 00) { if (hh > 12 && hh <= 24){ hh = hh - 12; System.out.println("It's " + hh +":" + mm + " " +pm); }	else if (hh <= 12 && hh > 00) {			System.out.println("It's "+ hh +":"+ mm + " "+ am); System.out.println("\n"); }	else {			System.out.println("\n"); System.out.println("Error: invalid time value.\nEnter a valid one.\n"); } }			System.out.println("Continue to input another time? [1=y | 0=n]"); ans= sc.nextInt; } while(ans==1); } }

sample02
import java.io.*; import java.lang.System.*; import java.util.*;

public class Activity02{ static Scanner sc=new Scanner(System.in); public static void main(String args[] ) {	String num;

System.out.print("Enter an array of characters (30 max): "); num=sc.next; deleteRepeats(num,num.length); } public static void deleteRepeats(String num,int size) {	System.out.print("\nString:" + num); System.out.println("\nSize:" + size); System.out.println("\n");

char[] delnum = new char[30]; delnum= num.toCharArray; System.out.println("\nAfter deleting the repeating characters ...\n " );

for(int i=0; i<size; i++){ for(int j=i+1;j<size;j++) {			if(delnum[i]==delnum[j]) {				for(int k=j; k<size-1;k++){ delnum[k] = delnum[k+1]; }j--; size--; }}}			System.out.print("String:");

for (int l=0; l<size; l++){ System.out.print(delnum[l]); }				System.out.print("\nSize:" + size);

System.out.println("\n\n\n"); }			}

sample03
import java.io.*; import java.util.*; import java.lang.*;

public class Activity03 { static Scanner sc = new Scanner(System.in);

public static void main(String args[]) {		char d[][]={ {'1','2','3'}, {'4','5','6'}, {'7','8','9'} };

int length = 0; length = d.length; int j;		int a;		int y;		char z;

String f;

System.out.println("This is a tic-tac-toe game. This game requires two players."); System.out.println("Player 1 will be marked as 'X' and Player 2 will be marked by 'O'."); System.out.println("Whosever first creates a 3-X or 3-O lines wins."); System.out.println("\n\n");

for(j=0;j<length;j++) {

for(a=0;a<length;a++) {			System.out.print(""+d [j] [a]); }			System.out.println("\n\n"); }

for (y=0;y<5;y++) {				if(d[0][0]=='X' && d[0][2]=='X'				||d[1][0]=='X' && d[1][1]=='X' && d[1][2]=='X'				||d[2][0]=='X' && d[2][1]=='X' && d[2][2]=='X'				||d[0][0]=='X' && d[1][0]=='X' && d[2][0]=='X'				||d[0][1]=='X' && d[1][1]=='X' && d[2][1]=='X'				||d[0][2]=='X' && d[1][2]=='X' && d[2][2]=='X'				||d[2][0]=='X' && d[1][1]=='X' && d[2][2]=='X'				||d[2][0]=='X' && d[1][1]=='X' && d[0][2]=='X') {				System.out.println("Player 1 wins the game!."); break; }			else if(d[0][0]=='O' && d[0][2]=='O'				||d[1][0]=='O' && d[1][1]=='O' && d[1][2]=='O'				||d[2][0]=='O' && d[2][1]=='O' && d[2][2]=='O'				||d[0][0]=='O' && d[1][0]=='O' && d[2][0]=='O'				||d[0][1]=='O' && d[1][1]=='O' && d[2][1]=='O'				||d[0][2]=='O' && d[1][2]=='O' && d[2][2]=='O'				||d[2][0]=='O' && d[1][1]=='O' && d[2][2]=='O'				||d[2][0]=='O' && d[1][1]=='O' && d[0][2]=='O') {				System.out.println("Player 2 wins the game!."); break; }

System.out.print("Player 1, It's your turn. Choose a position in the board:  "); f=sc.nextLine; z=f.charAt(0); System.out.print("\n\n");

for (j=0; j<length; j++) {						for (a=0;a<length;a++) {							if(z==d[j][a]) d[j][a]='X'; }					}

for (j=0; j<length; j++) {						for (a=0;a<length;a++) {							System.out.print(""+d [j] [a]); }							System.out.println("\n\n"); }

System.out.print("Player 2, It's your turn. Choose a position in the board:  "); f=sc.nextLine; z=f.charAt(0); System.out.println("\n\n");

for (j=0;j<length;j++) {									for (a=0;a<length;a++) {											if(z==d[j][a]) d[j][a]='O'; }								}

for(j=0; j<length; j++) {										for (a=0;a<length;a++) {												System.out.print(""+d [j] [a]); }												System.out.print("\n\n");

}					}

}			}

sample04
import java.lang.*; import java.util.*; import java.io.*; import javax.swing.*;

public class Activity04{ public static void main (String args[]) throws java.io.IOException { int posNum[] = new int [100]; int negNum[] = new int [100]; int count; int i; int temp; int num=16;

Scanner sc = new Scanner (System.in); System.out.print("Enter 16 numbers [duplicates allowed]."+"\n"); for (i=0; i=1) posNum[temp]++; else negNum[-temp]++; } System.out.println("\t"+"N"+"\t\t\t"+"Count"); for (i=posNum.length-1;i>0;i--) { if (posNum[i] !=0) System.out.println("\t"+ i +"\t\t\t"+posNum[i]); } for (i=0; i0) {			num=num*-1; den=Math.abs(den); }		else if (den<0&&num<0) {			num=Math.abs(num); den=Math.abs(den); }

if (num%9==0&&den%9==0) {			num=num/9; den=den/9; }

if (num%8==0&&den%8==0) {			num=num/8; den=den/8; }

if (num%7==0&&den%7==0) {			num=num/7; den=den/7; }

if (num%6==0&&den%6==0) {			num=num/6; den=den/6; }

if (num%5==0&&den%5==0) {			num=num/5; den=den/5; }

if (num%4==0&&den%4==0) {			num=num/4; den=den/4; }

if (num%3==0&&den%3==0) {			num=num/3; den=den/3; }

if (num%2==0&&den%2==0) {			num=num/2; den=den/2; }

numerator = num; denominator = den; } public void getNum{ System.out.println(numerator+"/"+denominator); } } public class RationalTest{ public static void main (String jArgs[]){

Rational dz = new Rational(-10,2); dz.normalization; dz.getNum;

} }

sample06
public class RightTriangle{

private Point vertexA, vertexB, vertexC;

public RightTriangle{ vertexA = new Point(1,4); vertexB = new Point(1,1); vertexC = new Point(4,1); }

public RightTriangle(Point a, Point b, Point c){ vertexA = a;				vertexB = b;				vertexC = c;				}

public void setA(Point a){ vertexA = a;				}

public void setB(Point b){ vertexB = b;				}

public void setC(Point c){ vertexC = c;				}

public Point getA{ return vertexA; }

public Point getB{ return vertexB; }

public Point getC{ return vertexC; }

public void validate{ Point a = this.getA, b = this.getB, c = this.getC; if(a.equals(c) || a.equals(b) || b.equals(c) || b.getX != a.getX || b.getY != c.getY){ a.setX(1); a.setY(4); a.setX(1); a.setY(1); a.setX(4); a.setY(1); this.setA(a); this.setB(b); } }

public int getHeight{ validate; return Math.abs(this.getA.getY - this.getB.getY); }

public int getBase{ validate; return Math.abs(this.getB.getY - this.getC.getX); }

public double getArea{ validate; return (0.5 * this.getBase * this.getHeight); } } import java.io.*; public class Point{

private int x, y;

public Point{ x= 1; y =1; }

public Point(int x, int y){ this.x = x; this.y = y; }

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

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

public int getX{ return this.x; }

public int getY{ return this.y; }

public int getQuadrant{ int x = this.getX; int y = this.getY; int quadrant;

if(x > 0 && y > 0){ quadrant = 1; }else if(x < 0 && y > 0){ quadrant = 2; }else if(x < 0 && y < 0){ quadrant = 3; }else if(x > 0 && y < 0){ quadrant = 4; }else{ quadrant = 0; }

return quadrant; }

public boolean equals(Object obj){ boolean ok = false;

if(obj instanceof Point){ Point p = (Point)obj; if(p.getX == this.getX && p.getY == this.getY){ ok = true; } } return ok; } } import java.util.*; public class RightTriangleTest{

public static void main(String[] args){ Scanner read = new Scanner(System.in); Point a, b, c;

System.out.printf("Enter vertex A coordintates : "); a = new Point(read.nextInt, read.nextInt); System.out.printf("Enter vertex B coordinates : " ); b = new Point(read.nextInt, read.nextInt); System.out.printf("Enter vertex C coordinates : " ); c = new Point(read.nextInt, read.nextInt);

RightTriangle t = new RightTriangle(a, b, c);

System.out.println("\nVertex A : Quadrant " + t.getA.getQuadrant); System.out.println("Vertex B : Quadrant " + t.getB.getQuadrant); System.out.println("Vertex C : Quadrant " + t.getC.getQuadrant);

System.out.println("\nHeight : " + t.getHeight); System.out.println("Base  : " + t.getBase); System.out.println("Area  : " + t.getArea); System.out.println(""); System.out.println("");

} }

sample07
import java.io.*;

public class Date{ private int day, month, year;

public Date{ day = 1; month = 1; year = 1900; }

public Date(int day, int month, int year){ this.day = day; this.month = month; this.year = year; checkDate; }

public void setDay(int day){ this.day = day; checkDate; }

public void setMonth(int month){ this.month = month; checkDate; }

public void setYear(int year){ this.year = year; checkDate; }

public int getDay{ return this.day; }

public int getMonth{ return this.month; }

public int getYear{ return this.year; }

private void checkDate{ if(month == 4 || month == 6 || month == 9 || month == 11){ if(day < 0 || day > 30){ day = 1; } }else if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12){ if(day < 0 || day > 31){ day = 1; } }else if(month == 2){ if(year % 100 == 0 && year % 400 == 0){ if(day < 0 || day > 29){ day = 1; } }else if(year % 4 == 0){ if(day < 0 || day > 29){ day = 1; } }else{ if(day < 0 || day > 28){ day = 1; } } }else{ month=1; } }

public String toString{ checkDate; return this.getDay+"/"+this.getMonth+"/"+this.getYear; } } import java.io.*;

public class Worker{ private String firstname, lastname; private Date birthdate, hiredate;

public Worker{ firstname = ""; lastname = ""; birthdate = new Date; hiredate = new Date; }

public Worker(String fname, String lname, Date b, Date h){ firstname = fname; lastname = lname; birthdate = b; hiredate = h; }

public void setFirstname(String fname){ firstname = fname; }

public void setLastname(String lname){ lastname = lname; }

public void setBirthdate(Date d){ birthdate = d; }

public void setHiredate(Date d){ hiredate = d; }

public String getFirstname{ return firstname; }

public String getLastname{ return lastname; }

public Date getBirthdate{ return birthdate; }

public Date getHiredate{ return hiredate; }

public void display{ System.out.println("Firstname : " + firstname); System.out.println("Lastname : " + lastname); System.out.println("Birthdate : " + birthdate); System.out.println("Hiredate : " + hiredate); } }

import java.io.*; import java.util.*;

public class WorkerTest{

public static void main(String[] args){

Date birthdate, hiredate; Scanner input= new Scanner(System.in); Worker a = new Worker;

System.out.print("Enter firstname : "); a.setFirstname(input.next);

Scanner input1= new Scanner(System.in); System.out.print("Enter lastname : "); a.setLastname(input1.next); Scanner input2= new Scanner(System.in);

System.out.println("");

System.out.print("Enter birthdate [dd mm yy] : "); a.setBirthdate(new Date(input2.nextInt, input2.nextInt, input2.nextInt)); Scanner input3= new Scanner(System.in); System.out.print("Enter hiredate [dd mm yy] : "); a.setHiredate(new Date(input3.nextInt, input3.nextInt, input3.nextInt));

System.out.print("\n"); System.out.println(" OUTPUT : \n");

a.display; System.out.print("\n"); } }

/* * To change this template, choose Tools | Templates * and open the template in the editor. */

import javax.microedition.midlet.*; import javax.microedition.lcdui.*;

Descasenas (talk) 10:45, 27 July 2011 (UTC)calcu-d
/* * To change this template, choose Tools | Templates * and open the template in the editor. */

import javax.microedition.midlet.*; import javax.microedition.lcdui.*;

/** * @author L14x18w38 */ public class Calculator extends MIDlet implements CommandListener, ItemCommandListener {

Display Screen; Form calculators = new Form("Calculator"); Command back = new Command("Back", Command.BACK, 1); TextField displayer = new TextField("", "", 36, TextField.ANY); StringItem buttons[] = new StringItem[10]; StringItem operator[] = new StringItem[10]; String key; String temp; String temp2; int counter=0; float answer; double p=0,m=0,d=0,t=0; double x=0,y=0;

public Calculator { //display calculators.append(displayer);

//buttons for (int i = 1; i < 10; i++) { key = "      " + i + "       "; buttons[i] = new StringItem(null, key, Item.BUTTON); buttons[i].setDefaultCommand(List.SELECT_COMMAND); buttons[i].setItemCommandListener(this); calculators.append(buttons[i]); }

//Operators operator[0] = new StringItem(null, "    "+ "  0    " +"   ", Item.BUTTON); operator[0].setDefaultCommand(List.SELECT_COMMAND); operator[0].setItemCommandListener(this); calculators.append(operator[0]);

operator[1] = new StringItem(null, "   "+ "   +" +"       ", Item.BUTTON); operator[1].setDefaultCommand(List.SELECT_COMMAND); operator[1].setItemCommandListener(this); calculators.append(operator[1]);

operator[2] = new StringItem(null, "   "+ "    -" +"       ", Item.BUTTON); operator[2].setDefaultCommand(List.SELECT_COMMAND); operator[2].setItemCommandListener(this); calculators.append(operator[2]);

operator[3] = new StringItem(null, "    "+ "   *" +"       ", Item.BUTTON); operator[3].setDefaultCommand(List.SELECT_COMMAND); operator[3].setItemCommandListener(this); calculators.append(operator[3]);

operator[4] = new StringItem(null, "    "+ "   /" +"       ", Item.BUTTON); operator[4].setDefaultCommand(List.SELECT_COMMAND); operator[4].setItemCommandListener(this); calculators.append(operator[4]);

operator[5] = new StringItem(null, "     "+ "  =" +"      ", Item.BUTTON); operator[5].setDefaultCommand(List.SELECT_COMMAND); operator[5].setItemCommandListener(this); calculators.append(operator[5]);

operator[6] = new StringItem(null, "     "+ "  C" +"      ", Item.BUTTON); operator[6].setDefaultCommand(List.SELECT_COMMAND); operator[6].setItemCommandListener(this); calculators.append(operator[6]);

//Prefered Sizes displayer.setPreferredSize(300, 5);

//Commands calculators.addCommand(back); calculators.setCommandListener(this); }

public void startApp { Screen = Display.getDisplay(this); Screen.setCurrent(calculators);

}

public void pauseApp { }

public void destroyApp(boolean unconditional) { }

public void commandAction(Command c, Item i) { //OPERATIONS

if (c==List.SELECT_COMMAND && i==operator[1]) {           temp = displayer.getString; x = Double.parseDouble(temp); displayer.setString(""); counter = 1; }         if (c==List.SELECT_COMMAND && i==operator[2]) {           temp = displayer.getString; x = Double.parseDouble(temp); displayer.setString(""); counter = 2; }         if (c==List.SELECT_COMMAND && i==operator[3]) {           temp = displayer.getString; x = Double.parseDouble(temp); displayer.setString(""); counter = 3; }         if (c==List.SELECT_COMMAND && i==operator[4]) {           temp = displayer.getString; x = Double.parseDouble(temp); displayer.setString(""); counter = 4; }

if (c==List.SELECT_COMMAND && i==operator[5]) {           temp2 = displayer.getString; y = Double.parseDouble(temp2); if (counter==1) {           p = x + y;            answer = (int) p;            displayer.setString((int)answer+""); counter = 0; }

if (counter==2) {           p = x - y;            answer = (int) p;            displayer.setString((int)answer+""); counter = 0; }

if (counter==3) {           p = x * y;            answer = (int) p;            displayer.setString((int)answer+""); counter = 0; }

if (counter==4) {           p = x / y;            answer = (float) p;            displayer.setString(answer+""); counter = 0; }

} //numbers if (c==List.SELECT_COMMAND && i==buttons[1]) {           temp = displayer.getString+"1"; displayer.setString(temp); }

if (c==List.SELECT_COMMAND && i==buttons[2]) {           temp = displayer.getString+"2"; displayer.setString(temp); }

if (c==List.SELECT_COMMAND && i==buttons[3]) {           temp = displayer.getString+"3"; displayer.setString(temp); }

if (c==List.SELECT_COMMAND && i==buttons[4]) {           temp = displayer.getString+"4"; displayer.setString(temp); }

if (c==List.SELECT_COMMAND && i==buttons[5]) {           temp = displayer.getString+"5"; displayer.setString(temp); }

if (c==List.SELECT_COMMAND && i==buttons[6]) {           temp = displayer.getString+"6"; displayer.setString(temp); }

if (c==List.SELECT_COMMAND && i==buttons[7]) {           temp = displayer.getString+"7"; displayer.setString(temp); }

if (c==List.SELECT_COMMAND && i==buttons[8]) {           temp = displayer.getString+"8"; displayer.setString(temp); }

if (c==List.SELECT_COMMAND && i==buttons[9]) {           temp = displayer.getString+"9"; displayer.setString(temp); }

if (c==List.SELECT_COMMAND && i==operator[0]) {           temp = displayer.getString+"0"; displayer.setString(temp); }

if (c==List.SELECT_COMMAND && i==operator[6]) {           temp = displayer.getLabel; displayer.setString(temp); }

}

public void commandAction(Command command, Displayable arg1) { if (command == back) {           destroyApp(true); notifyDestroyed;

}

} } -- chookstogo.java /* * To change this template, choose Tools | Templates * and open the template in the editor. */

import javax.microedition.midlet.*; import javax.microedition.lcdui.*;

/** * @author L14X18W37 */ public class ChooksToGo extends MIDlet implements CommandListener{

private Display screen; Alert alert = new Alert("Welcome to Chooks To Go", "", null, AlertType.ALARM); Form imageForm = imageForm = new Form("Welcome to Chooks To Go"); private Alert game_Over; private Alert next_Level;

//commands Command instruction = new Command("Instructions", Command.OK, 0); Command start_Game = new Command("Start Game", Command.OK, 1); Command end = new Command("Exit", Command.OK,3);

public ChooksToGo{

//adding commands alert.addCommand(instruction); alert.addCommand(start_Game); alert.addCommand(end); alert.setCommandListener(this);

try {

Image img = Image.createImage("/Title.png"); ImageItem image = new ImageItem("", img, Item.LAYOUT_CENTER, ""); imageForm.append(image); //imageForm.set(-5, image);

}       catch (Exception e){ e.printStackTrace; }   }

/*public void startGame{ temp = new GameEngine(this); gameEngine = new GameEngine(this); screen.setCurrent(gameEngine); }*/

/*public void gameOver{

screen.setCurrent(game_Over); }*/

public void startApp { screen = Display.getDisplay(this); screen.setCurrent(imageForm); screen.setCurrent(alert); }

public void pauseApp { }

public void destroyApp(boolean unconditional) { }

public void commandAction(Command c, Displayable d) {

if(c == end){

destroyApp(true); notifyDestroyed; }

else if(c == instruction){

destroyApp(true); notifyDestroyed; }

else if(c == start_Game){

destroyApp(true); notifyDestroyed; }   } }

gamenidlet.java /* * To change this template, choose Tools | Templates * and open the template in the editor. */

import javax.microedition.lcdui.*; import javax.microedition.midlet.*;

/** * @author Administrator */ public class GameMidlet extends MIDlet implements CommandListener {

private Display screen; private Alert alrtGameOver; private Alert alrtNextLevel; private List listMenu; private GameEngine gameEngine; GameEngine temp;

private Command exit; private Command start;

public GameMidlet{ //commands exit = new Command("Exit", Command.EXIT,0); start = new Command("Start",Command.OK,0);

alrtGameOver = new Alert("Touch Me Not","Game Over!", null, AlertType.ALARM); alrtGameOver.setTimeout(Alert.FOREVER); alrtGameOver.addCommand(exit); alrtGameOver.setCommandListener(this);

alrtNextLevel = new Alert("Touch Me Not","", null, AlertType.ALARM); alrtNextLevel.setTimeout(Alert.FOREVER); alrtNextLevel.addCommand(start); alrtNextLevel.setCommandListener(this);

listMenu = new List("Touch Me Not", List.IMPLICIT); listMenu.append("Instructions", null); listMenu.append("New Game", null); listMenu.setCommandListener(this);

}

public void gameOver{ screen.setCurrent(alrtGameOver); }

public void startGame{ //temp = new GameEngine(this); gameEngine = new GameEngine(this); screen.setCurrent(gameEngine); }

public void showNextLevel(int level){ temp = gameEngine; alrtNextLevel.setString("Level "+level); alrtNextLevel.setTimeout(Alert.FOREVER); screen.setCurrent(alrtNextLevel); gameEngine= null;

}

public void startApp { screen = Display.getDisplay(this); screen.setCurrent(listMenu); }

public void pauseApp { }

public void destroyApp(boolean unconditional) {

}

public void commandAction(Command c, Displayable d) { if(c == List.SELECT_COMMAND){ if(listMenu.getSelectedIndex == 0){ //alert for instructions }           else if( listMenu.getSelectedIndex == 1){ startGame; }

}

if(c == exit && d == alrtGameOver){ screen.setCurrent(listMenu); }

if(c==start && d== alrtNextLevel){ gameEngine = temp; screen.setCurrent(gameEngine); gameEngine.setDelay(30); gameEngine.getGameLevel.randomTheObjects; }   } } ---