Tuesday, July 7, 2009

intrprog blog july 7,2009

Today, we our hands on exercise. My performance was bad and it is really depressing. I didn't think that it would be so hard that a question would take a lot of time to do. In the end, I had only answered one. And it was wrong. It was so sudden that a lot of hard question were given to us in a short amount of time. I do hope there would still be a chance to recover that 20% I've lost =( .

Friday, July 3, 2009

My first encounters with java

Actually, the first time I met java was only this summer. It was because I saw the flyer that was distributed in our course's pre-confirmation orientation. It was a java short course program held in Lasalle. It was a 5hrs session that last for a week.

Without having any background in java, we were ask to figureout how to swap 3 variables. All of us took alot of time to figure it out. So here's the code that I was able to make.

public class Swapper
{
public static void main (String [] args)
{
int nA=20;
int nB=30;
int nC=0;

System.out.println("Before swapping****");
System.out.println("nA="+nA);
System.out.println("nB="+nB);

/*write your code to swap the values of nA
and nB*/

nC=nA;
nA=nB;
nB=nC;

System.out.println("After swapping****");
System.out.println("nA="+nA);
System.out.println("nB="+nB);
}
}

I forgot the arragements of what we did frst, but here are the things we also did.

1)
public class VariableTester
{
public static void main (String [] args)
{
int nA=20;
double dB=30.03;
String sC="Hello World";
char cD= 'a';

System.out.println( "the variable nA="+nA);
System.out.println( "the variable dB="+dB);
System.out.println( "the variable sC="+sC);
System.out.println( "the variable cD="+cD);
}
}

2)
public class Circle
{
public static void main( String[] args)
{
double dRad= 2.5;
double dPi= 3.1416;
double dCir= 2 * dPi * dRad;

System.out.println("The circumference of a circle given a radius of " + dRad +" is " + dCir);
}
}

3)

public class Matematiks
{
public static void main (String [] args)
{
int nA=5;
int nB=2;
int sumResult=nA+nB;
int difResult=nA-nB;
int prodResult=nA*nB;
int divResult=nA/nB;
int moddivResult=nA%nB;
nA++;
int incResult=nA++;
nB--;
int decResult=nB;

System.out.println("Sum of nA "+
"and nB=" + sumResult);
System.out.println("Difference of nA "+
"and nB=" + difResult);
System.out.println("Product of nA "+
"and nB=" + prodResult);
System.out.println("Division of nA "+
"and nB=" + divResult);
System.out.println("Modulardivision of nA "+
"and nB=" + moddivResult);
System.out.println("Increase of nA "+
"and nB=" + incResult);
System.out.println("Decrease of nA "+
"and nB=" + decResult);


}
}

4)
public class Convert
{
public static void main (String[]args)
{
int nMin=60;
int nHr=5 ;
int nResult= nHr * nMin;
System.out.println("Conversion of nHr "+
"and nMin =" + nResult+ "minutes");
}
}

5)
import java.util.Scanner;
public class GreetMe
{
public static void main(String[]args)
{
Scanner scanKeyBoard = new Scanner(System.in);
System.out.print("Enter your nickname;");
String sUserInput = scanKeyBoard.next();
System.out.println("Hello " + sUserInput + " , Have a Good Day");
}
}

=) .... sharing lang po hehe! first time ko po magprogramming super daming lumabas na error minsan pa nga po 22 errors 0_0 .Kaya nga po nakatulong din sakin ung short corz nung summer.

Using replace ; replaceFirst ; replaceAll

I would like to share the programs i did in the intprog on july,2,2009.
So here it is:

The Censor activity
import java.util.Scanner;
public class Aa
{
public static void main(String [] args)
{
System.out.println("Enter your string");
Scanner a= new Scanner(System.in);
String z=a.nextLine();
String letter=z.replaceAll("ateneo", "****");
System.out.println(letter);
}
}
While I was in the lab, I also tried applying the replaceFirst method and because of that I learned how to use the backslash quotation mark from our prof, thanks sir! I didn't think that it was possible to write a quatation mark within a string.

import java.util.Scanner;
public class ReplaceFirst
{
public static void main(String [] args)
{
System.out.println("Type \"i love lasalle\"");
System.out.println("Enter your sentence");
Scanner a= new Scanner(System.in);
String z=a.nextLine();
String letter=z.replaceFirst("i","You");
System.out.println(letter);
}
}

After doing the replaceFirst, i decided to do the replace, but unfortunately i wasn't able to save it. So this is the code that i think i did, i don't know if it's correct because I still haven't downloaded the jcreator.

import java.util.Scanner;
public class Replace
{
public static void main(String [] args)
{
System.out.println("I'll change all \"i \" you enter into \" a\"");
System.out.println("Enter your sentence");
Scanner a= new Scanner(System.in);
String z=a.nextLine();
String letter=z.replace("i","a");
System.out.println(letter);
}
}

Aside using the replaceAll, we were asked to use the PolygonVisualizer. Unfortunately, i didn't get it. I starting to think that the lessons are getting harder for me. =<

//sir pasensya na lng ung sa tabs yaw mag work d2 sa syt e.

Tuesday, June 30, 2009

intrprog blog june 30,2009

Today we had a new lesson in intrprog. Its about using Math.sqrt and Math.pow. I also found out that the site java.sun.com is very useful because it has API that can help us alot in programming.
So far i could still catch up with the lessons. But i'm really wondering why my codes are very long while some have very short codes. Because of this i think that i really have to learn how to minimize my codes.

Here's the activities i made...

import java.util.Scanner;
public class Abc
{
public static void main(String [] args)
{
System.out.println("Enter your name");
Scanner x= new Scanner(System.in);
String a=x.nextLine();

System.out.println("Enter 1st grade");
Scanner y= new Scanner(System.in);
double b=y.nextDouble();

System.out.println("Enter 2nd grade");
Scanner z= new Scanner(System.in);
double c=z.nextDouble();

System.out.println("Enter 3rd grade");
Scanner w= new Scanner(System.in);
double d=w.nextDouble();

double e = (b+c+d)/3.0;
System.out.println( a + ", your average score is:" + e);
}
}


import java.util.Scanner;
public class Abcde
{
public static void main(String [] args)
{
System.out.println("Enter a");
Scanner x= new Scanner(System.in);
double y=x.nextDouble();
double a= Math.pow(y,2);

System.out.println("Enter b");
int z=x.nextInt();
double b= Math.pow(z,2);

double w= a+b;
double c= Math.sqrt(w);

System.out.println("Letter c is " + c );
}
}

import java.util.Scanner;
public class Abcd
{
public static void main(String [] args)
{
System.out.println("Enter a");
Scanner x= new Scanner(System.in);
double y=x.nextDouble();
double a= Math.pow(y,2);

System.out.println("Enter b");
int z=x.nextInt();
double b= Math.pow(z,2);

double w= a+b;
double c= Math.sqrt(w);

System.out.println("Letter c is " + c );
}
}

Saturday, June 27, 2009

The Hello World


"hello world" was the first program that I did in intprog class.

its actually very simple

public class Hello
{
public static void main (String[]args)
{
System.out.println("Hello World");
}
}

After writing that in the notepad, you have to type Hello.java .<-- i often forget this
the outcome of the screen must have a "Hello World" written on it.

note:
" " - is for strings
' ' - for char
true or false- Boolean
System.out.println- will be shown on the next line
System.out.print- will be on the same line

I learned that this is very important.. knowing the use of modulo and division.
given: n=12345

n/10=1234
n/100=123
n/1000=12
n/10000=1

n%10=5
n%100=45
n%1000=345
n%10000=2345

Honestly, this was very confusing and i didn't think that it was possible for a program to find the middle number in a given.Although the solution was given by our prof Mr.Inventado, I tried doing it.
so here's what i did

public class Mid
{
public static void main(String [] Args)
{
int n=12345;
int mid;
mid= (n/100)%10;
System.out.println ( " With the given number:" + n);
System.out.println ( " the middle number is: " + mid);
}
}
i also learned that % and / can also be used in converting military time to standard time.
Here's the solution from our intrprog prof , Mr. Inventatdo.

public class Time
{
public static void main(String [] Args)
{
int giv=1545;
int hr= giv/100%12;
int min= giv%100;
String zero= min<10? "0": " " ; System.out.println ( hr + " : " + zero + min);
}
}

lessons from intrpog

hi everyone, i created this blog so that i can share what i learned in our intrprog class.

Intrprg
Lesson
Lesson #1
Java
one thing that I can remember in java would be the acronyms WORA .
it means
W-write
O-once
R-run
A-anywhere
I was amaze that the java was named because of an Oak tree that stood outside their office.
Lesson #2
In learning java, there are three operations we must remember.
Arithmetic Operation
arithmetic is similar to math. It has addition , subtraction, division , multiplication and modulo division. See the next line.
+ , - , / , * , %
what differ is that in arithmetic operation and math, is that you have to use that given symbol in order for it to function. We can't use an "x" or a "point" for multiplication. It should be asterisk "*".
Relational Operations
Relational is comparing 2 numbers with the use of the operations. " > . < . == , != , ≥ ,≤"
and the outcome of that, true or false , is known as Boolean.
Logical Operations
Logical operations was similar to our lesson in physics and it was confusing.
but when our prof discussed it, i realized that it is only easy.
I learned 3 logical operations in out intprog,
|| -or
&&- and
!- not
|| - if one is true then all are true
&& - if one is false then all is false
! - the opposite
Lesson #3
How to make a flowchart.
I learned that in making a flowchart, each shaped has it own usage. A Terminal shape tells you where the flowchart begins and ends . A parallelogram is used to show input or output. The rectangle is used to show a process, task, or operation. A diamond shape is for the decision that commonly asks a question. And to complete the flowchart,we need lines with arrows to determine the flow through the chart

2 sites given by our prof that are useful in making flowcharts
  1. my.lovelycharts.com
  2. http://www.gliffy.com/