Current location: Hot Scripts Forums » Programming Languages » Everything Java » New to Java - First "real" program!


New to Java - First "real" program!

Reply
  #1 (permalink)  
Old 03-17-04, 10:54 AM
renderstream renderstream is offline
New Member
 
Join Date: Mar 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
New to Java - First "real" program!

Hi, this is my program on calculating an average. I tried to use classes properly, so please if their is some sort of mistake/things i can improve on, please point it out so i can get better

----====================================----

PHP Code:

package developement;

import javax.swing.JOptionPane;

class 
Dev
{
    
    public 
Dev()
    {
        
//making a object called objAverage
        
Average objAverage = new Average();
        
        
objAverage.Getammount();
        
objAverage.Getnumbers();
        
objAverage.Getaverage();        
    }


    public static 
void main(String[] args)
        
    {
        new 
Dev();
        
System.exit(0);
    }

}

class 
Average
{
    
//Variables    
    
int ammount;
    
int array[];
    
int count;
    
String currentnumber;
    
int averageadd=0;
    
int average;
    
    
    
    
//constructor
    
public Average()
    {
    }

    
    
//method that gets the ammount of numbers
    
public int Getammount()
    {
        
//variables
        
String inputammount;
        
        
//get ammount
        
inputammount =JOptionPane.showInputDialog(null,"Enter Ammount of numbers to average","Ammount of numbers"JOptionPane.QUESTION_MESSAGE);
        
        
//convert string to integer
        
ammountInteger.parseInt(inputammount);
        return 
ammount;
        
    }

    
//method which substracts two numbers
    
public int Getnumbers()
    {
        array = new 
int [ammount]; 
        
        
//get numbers
        
for (count=0count<ammount; ++count)
        {
        
currentnumber JOptionPane.showInputDialog("Enter Number:");
        array[
count] = Integer.parseInt(currentnumber);
        
averageadd=averageadd+array[count];
        }
        return 
averageadd;
    }
    
    public 
void Getaverage()
    {
        
averageaverageadd/ammount;
        
String displayaverage;
        
        
//convert to string
        
displayaverageInteger.toString(average);
        
JOptionPane.showMessageDialog(null,"The average of those numbers is: "+displayaverage,"result"JOptionPane.PLAIN_MESSAGE);
        
    }



----====================================----

thanks!

Last edited by renderstream; 03-17-04 at 10:56 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
We need more java talk rooshine Everything Java 4 05-08-04 11:44 PM
Problems launching program on webserver domiflichi ASP 2 03-22-04 11:12 AM
New programmer here... is this program correct? kml21panther C/C++ 3 01-31-04 12:51 AM
Need JAVA expert HELP! 007spy Everything Java 0 01-23-04 03:38 AM
java program hangs up on xp machine shiva Everything Java 2 01-10-04 10:10 AM


All times are GMT -5. The time now is 12:36 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.