Showing posts with label programmer. Show all posts
Showing posts with label programmer. Show all posts

Friday, October 21, 2011

how am i supposed to move on?

three weeks earlier
well, the story is as follows:
i spent A LOT of time trying to solve a problem with C
if learning programming requires practicing
how am i supposed to improve my programming skills if i can't solve some kind of impossible-solution-looking problems??
within the time i was practicing, there was a problem which looked at the beginning so hard to got it and also there were some following problems related to that one and they looked much much much harder.
the thing is that i couldn't till now solve that damn problem
how am i supposed to learn if nothing seems as normal as programming >.<
and how am i supposed to move on if i'm stuck for almost a month and half still trying to solve that issue?
i'm really confused
and this really depressed me that i'm starting to hate the whole programming thing if i couldn't move a little single step forward.

any suggestions/strategies to follow??
or am i just a stupid person and not made for programming. *Whisper* i'm really scared of being that >.<

sometimes it really gets so hard to figure it out
and makes me feel im totally stuck and can't go any longer
when should i worry about my improvement way and when shouldn't i?
there must be some points. i can't make sure that i'm on the right track
i don't want to fail solving a problem which i already passed the level of.
it feels bad. i experienced that many times
don't feel like skipping any problems facing me to be sure that i'm doing well
=(

Wednesday, August 3, 2011

Do you want to share? =D

I've got a book called 'C Programming: A Modern Approach', it's the text book students of C Programming use for refering. Since weeks back I've been reading this book to recall my knowledge in C and trying to catch some more information & experience. The main point now is 'Arrays section'. I've never learn arrays in C. I was only dealing with arrays in Java and they really look much nicer in Java than in C lols..
Anyway, there is a problem I was hitting on since couple of days and til now there is no answer.

let me show it to you:
/* Checks number for repeated digits */
#include<stdio.h>

#define TRUE 1;
#define FALSE 0;

typedef int Bool;

main()
{
    Bool digit_seen[10]={0};
    int digit;
    long int n;

    printf("Enter a number: ");
    scanf("%d", &n);

    while (n > 0)
    {
        digit=n%10;
        if (digit_seen[digit])
            break;
        digit_seen[digit] = TRUE;
        n /= 10;
    }

    if (n > 0)
        printf("Repeated digit\n\n");
    else
        printf("No repeated digit\n\n");

    return 0;
}

To be honest I spent a long period to understand that code. I didn't start solving the problem until I got the idea about it =D
anyway, I want to share the question with you guys, I think it's fun for all of us to think and try to come with a solution or an idea about how the answer code will be.

Here's the exercise:
Modify the repdigit.c program (The above program) so that it shows which digits (if any) were repeated:
Enter a number: 93977
Repeated digit(s): 7 9

didn't figure it out yet but I'm still trying. Here's what I went through so far:
#include<stdio.h>

#define TRUE 1;
#define FALSE 0;

typedef int Bool;

main()
{
    Bool digit_seen[10]={0};
    Bool repeated_digit[10];
    int digit;
    long int n;

    printf("Enter a number: ");
    scanf("%d", &n);

    while (n > 0)
    {
        digit=n%10;
        if (digit_seen[digit])
            {repeated_digit[digit]=digit;
            }

        digit_seen[digit] = TRUE;
        n /= 10;
    }

    if (repeated_digit[digit])
        {printf("Repeated digit\n\n");
        printf("%d", repeated_digit[digit]);}
    else
        {printf("No repeated digit\n\n");
        printf("%d", n);}
    return 0;
}
it's a wrong answer and I've been changing it from the beginning to now =D

enjoy it =)

peace~

Monday, May 23, 2011

It's starting again!

The feeling when I don't know what to do or where to go next!
I was kind of lost the last few weeks, where nothing appears good to me. I supposed to keep working on Java because that's what I was wanting to. But eventually everything seemed to be non-worthy. I need some refreshing I think.

I was reading this page today: http://www.cprogramming.com/whyc.html am I going back to C programming? Maybe

peace~

Wednesday, April 27, 2011

sorry!!!

sorry for not posting anything lately
i don't know what i'm going to do next =(

Monday, January 10, 2011

get Sum and Average program (Open Source)

Hi,
I've just finished writing this code, it's not a new idea but good and exciting one =P

here it is:


//@ Simple program to get the sum and average for a number of values grouped in an array <---
//@ Author: 'Liberty' <---
//@ Date: Monday, January 10 2011 12:40 AM <---
//@ ########################## <---


import javax.swing.JOptionPane;
public class getSumAndAverage {
public static void main (String args []) {

// declaring variables and arrays
int num, t, x=0, i=0, count=0;
Double [] nums={};
Double ave=0.0, sum=0.0;
String s, message;
String [] ss={};

JOptionPane pane=new JOptionPane();

while(x==0) {

s=pane.showInputDialog("Enter how many numbers you want to operate\n\n");
num=Integer.parseInt(s);
ss=new String[num];
nums=new Double[num]; // getting the amount of elements wanted to be operated on and setting num as the array elements number

do {

for (i=0; i<num; i++) {
count++;
ss[i]=pane.showInputDialog("Enter a number: \n\nsum= "+sum+"\naverage= "+ave);
nums[i]=Double.parseDouble(ss[i]);
sum+=nums[i];
ave=sum/count; // numbers are added one by one, sum and average are being evaluated
}

// final result after entering all the elements
message="sum and average of your numbers:";
pane.showMessageDialog(null,message+"\nSum : "+sum+"\nAverage : "+ave,"result",JOptionPane.INFORMATION_MESSAGE);

// giving the user options to perform other operations
if (i==num) {
t=pane.showConfirmDialog(null,"Do another opertion? (The same number of entries)\n\n'No' for different number of entries\n'Cancel' for exit","Another operation?",JOptionPane.INFORMATION_MESSAGE);
if (t==JOptionPane.YES_OPTION) {
i=0;
x=1;
sum=0.0;
ave=0.0;
count=0; // resetting variables to initial values
}

else if(t==JOptionPane.NO_OPTION) {
x=0;
i=0;
sum=0.0;
ave=0.0;
count=0;
}

else {
pane.showMessageDialog(null,"Thank You!");
System.exit(0);
}
}
} // closing bracket of do while
while (x==1);

} // end of while
} // end of main class
} // end of getSumAndAverage class




Amasi, I've written comments this time XD


people, wish me luck =P


peace & all good stuff =)


liberty~

Sunday, December 19, 2010

Creating Frames [Java Tutorial]

This tutorial was completely written by ME


||..~


The tutorial will be talking about GUI (Graphical User Interface) in java programming language. we all know that java is a OOP language. it means that we can design interfaces for the software we develop, so that the user could interact much easily with it. That's what graphical interfaces aimed to.

let's write a code to show a window, or a FRAME as we call it in Java, and see how the code will look like:

import javax.swing.*;

public class JFrameTest {

    public static void main (String [] args) {

     JFrame f = new JFrame();

    }
       
}

now we've already created our frame.
let's take it line by line:


import javax.swing.*; 
this line is concerned for calling the package (javax.swing) which contains the JFrame component. simply, the frame cannot be created without including this package.

public class JFrameTest {
creating the class and name it as JFrameTest

public static void main (String [] args) {
this line is understood perfectly. If you are already taking tuts on GUI then it's probably not needed to explain.

JFrame f = new JFrame();
Here comes creating the frame and give it the name of f .

JFrame : the class name

f : creating the object (frame)

new : key word used for creating the frame which we gave f as the name of it .

JFrame : the constructor -followed by ' () ' and a ' ; ' , which has to be named the same as the class name .

and the last two lines are the closing brackets for JFrameTest and main classes.


||..~


if you run the code, nothing will show up. Because the frame is hidden and need to be visible. in this case, we need to set some attributes to the frame, at lease to make it visible. 
so what we do?
look at the following:

import javax.swing.*;

public class JFrameTest {

    public static void main (String [] args) {
     JFrame f = new JFrame();

     f.setVisible(true);

     }
    
} 

One line was added.


f.setVisible(true);
so this is the code responsible for making the frame VISIBLE

 (the object name) f [dot] (the method) setVisible ([the boolean value] true ) in between the brackets () 
of course we don't forget the semi colon ; 



||..~


Now let's add some other features to our frame .
Here goes the code :

import javax.swing.*;

public class JFrameTest {

    public static void main (String [] args) {

     JFrame f = new JFrame("Testing the Frame");

     f.setVisible(true);

     f.setSize(300,200);

     f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      }
    
}

3 more things were added. let's pick them up one by one .


First one was giving the frame a title : "Testing the frame"
we mentioned it in between the brackets in the same line of creating the frame. this looks simple. note that title has to be in between Double Quotes " "


Next thing


f.setSize(300,200);
setting the size of the frame by adding the arguments in between the brackets (WIDTH , HEIGHT);
we set 300 as the width, 200 as the height.


Last one


f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this is a very useful line. well, it is a must in every frame we create. (may be some exceptions in higher levels)

this line is used for terminating the program. if we click on the (x) button, the program will still running, even though the frame disappears , the operation will still ON.
so we should include that code to stop the program when wanted to.

 (frame name) f [dot] (method name, which is.. ) setDefaultCloseOperation (in between the brackets) we call the class name which is JFrame [dot] (the method) CLOSE_ON_EXIT  
and remember all the time, the semi colon ;

(note: java is case sensitive. keep that in mind) 


||..~


and that's all i guess. I don't know how I was doing. just hoping I covered everything well and hope my words make you get the basic idea .


*comments will be very welcome*

wish you peace, and all good stuff =)

liberty~

Sunday, December 12, 2010

Hard work must start!

When somebody is about to fail a semester, that makes it a must to start serious work, isn't it? In my case, I have to mention my poor performance in study which I didn't seriously think that I may be in kind of an immediate position, lol XD
So yes, I'm in a critical situation unfortunately. I didn't want it to go this way but I was kind of out of control. I came to Muscat determined to study and learn, and to be stronger, not to be a failure. But in some way I got out of the track planned in my mind and found myself looking for extra and extra work.

Anyway, I must improve my progress in  a way or another, otherwise it will be so frustrating. My bad performance has stop right away, so in order to do that, I went to the college library to get some books. My first problem is the lack I have in understanding. Some courses I can say that I'm falling off. I thought to step forward in order to overcome my weak understanding by going to the library and get some books to help my out -I sound depressed about me as a bad understander dont I? well that's ok!

Basically, at the beginning of the semester, the assembly language course was ok, I was doing well, or is it what I thought? lol :p
Yea, as a beginning, the assembly language course is no doubt, HARD and tough! Yes it is, so I had two books for this course. One is 'Microprocessor and its applications', the other is 'Digital design'. The first wasn't the one I looked for but it serves the purpose. But actually it is very good book. I was kindly lost in assembly language and this helped me a little bit to be honest.

Well let's say that this is snapshot of a new beginning. In the further days I'm gonna make you know if I'm going well or........ hope not! I want everything to be alright, because you know there are two things I look for, One: to not fail. Two: to not learn nothing. Number two is the diamond for me. I'm a programmer, not yet a real programmer but I badly want to be. I don't want to pass this year with minimum knowledge. I hope it to get the other way round.

Yep, that's it for now. I'll try my best at least to not blame myself later and I'll try to not fail. I'm in a bad situation but I know that it is not too late. I still can handle it!

thanks for reading :)

Special thanks to my friend for helping me picking up the books ;p

liberty~

Monday, December 6, 2010

I'm still here!

This is for telling that I'm still ALIVE!!!!!

XD

peace and all good stuff~

Liberty :)

Thursday, October 28, 2010

FOSS Presentation in HCT!

The presentation will be on
Saturday, 
30 October 2010, 
12 pm
in the Auditorium.

please Attend

Tuesday, October 19, 2010

Joined FOSS Group!

Yesterday I've met Ms. Asma AL Marhooby to inquire about the Free Open Source Software Group. I got so interested when she was talking about the activities the group would implement. Actually I found that very useful for programmers who want to improve their skills. The main thing is that the group will be concerned in practicing, discussions, and any sort of activities on Open Source softwares.

She gave me a set of hot headlines about that: for instance, we eventually may make our own Open Source software, isn't that interesting!? ^^
I'm so excited, my favorite word recently XD!

ummmmm, yea, but still students who joined the group not allowing the activities to get started, we still need some more members having skills in programming so that we can start.

Not forcing anyone XD, but anyhow, when feel like joining the FOSS group, go to room N238 and talk to Ms. Asma AL Marhooby.

Good luck

Friday, October 15, 2010

Counter-simple Java programm [Open Source]

Hello,
I wrote a code today, I was trying to do something I never did. Well, it's not that impressive but I'm happy I did it myself XD

take a look:

//October 15 2010 Friday
//5:26 pm
//by:Liberty
//www.hctlife.com
/* **************** */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class test extends JFrame {
    private JButton button;
    private JLabel label;
    int i=0;
   
    public test(){
        super("Counter");
       
        Container container=getContentPane();
        container.setLayout(new FlowLayout() );
       
        button=new JButton("Click");
        container.add(button);
       
        label=new JLabel("count : 0");
        container.add(label);
       
        ButtonHandler handler=new ButtonHandler();
        button.addActionListener(handler);
       
        setSize(200,70);
        setVisible(true);
        setLocation(100,100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
   
    public static void main (String args []){
        test app=new test();
    }
   
    private class ButtonHandler implements ActionListener{
        public void actionPerformed (ActionEvent event){
            i++;
            label.setText("count : "+ i);
       
        }
    }
}

That's it.

Monday, October 11, 2010

GUI classes really started! (excited :D)

Today I had the first class in GUI programming. I had this course begun before, but today was the real go. Previous classes were only theoretical and, for sure, boring! but GUIs' is just exciting. I'm so excited ^^

This was the first program we had:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Login extends JFrame {
private JLabel uid,pwd;
private JTextField tuid;
private JPasswordField tpwd;
private JButton bok;

public Login() {
super ("Windows Login");

Container container = getContentPane();
container.setLayout(new FlowLayout() );

uid = new JLabel ("User ID");
container.add(uid);

tuid = new JTextField(10);
container.add(tuid);

pwd = new JLabel ("Password");
container.add(pwd);

tpwd = new JPasswordField(10);
container.add(tpwd);

bok = new JButton ("Login");
container.add(bok);

ButtonHandler handler=new ButtonHandler();
bok.addActionListener(handler);

setSize(400,100);
setVisible(true);
}

public static void main (String args [] ) {
Login application=new Login();

application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

private class ButtonHandler implements ActionListener{
public void actionPerformed (ActionEvent event){

String msg;

if ( (tuid.getText().equals("admin") ) && (tpwd.getText().equals("hct") ) )
{
msg="Login Successful";
}
else
{
msg="Login Failed";
}
JOptionPane.showMessageDialog(null,msg);
}

}
}

It's not too long as some students looked at it, it's just the way it is! <-- anyone get the point?? no problem.
I'm looking forward for further classes, I think they're gonna be more and more exciting, can't wait XD.
Mr. Anand is a good teacher. I like the way he teaches. Hope I could him teaching me next semester@@

Anyway, see you later :)

Thursday, October 7, 2010

Ambitious HCT Programmer

Came from Salalah to HCT this semester for Bachelor Degree. I'm staying in Muscat only till summer semester, so I'll do my best to gain as much as possible of knowledge in Programming this year. Wish me luck !

And this is enough as the first post in the Blog.


good luck for all :>