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~
Programmer, psp/ds/pc & mmo gamer, pink hater & other stuff girl
Showing posts with label Open Source. Show all posts
Showing posts with label Open Source. Show all posts
Monday, January 10, 2011
Thursday, October 28, 2010
FOSS Presentation in HCT!
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
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:
That's it.
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.
Subscribe to:
Posts (Atom)