Welcome to Dream.In.Code
Become a Java Expert!

Join 149,719 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,278 people online right now. Registration is fast and FREE... Join Now!




program to calculate average

 
Reply to this topicStart new topic

program to calculate average, need help, i'm lost don't know what to do???

elielobt
2 Feb, 2007 - 02:58 PM
Post #1

New D.I.C Head
*

Joined: 2 Feb, 2007
Posts: 8


My Contributions
trying to get average of the numbers : 85,90,95,78,82.. I'm still learning java, it's my first two weeks i nclass and it is HARD.....


public class averageNumber
{
public static void main (String[] args)
{
int score = 0;
int sum = 1;
int count = -1;
double average;
while (score >= 0)
{
count++;
sum = sum + score;
}
sum = sum - score - 1;
System.out.println("count: " + count + ", sum: " + sum);
average = (double)sum/(double)count;
System.out.println("average: " + average);
} // end of main
}
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Program To Calculate Average
2 Feb, 2007 - 03:26 PM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,350



Thanked: 51 times
Dream Kudos: 25
My Contributions
What exactly is the problem you are encountering? Please provide a description for our members, as well as posing any error messages you are receiving.

Upon first glance, your application does not prompt the user to enter any information for the score, nor does it take that information from a file. You do not have an array with those numbers either. Are you specifically trying to average the numbers you indicated, or have the user enter the information?
User is online!Profile CardPM
+Quote Post

codeninja
RE: Program To Calculate Average
16 Feb, 2007 - 08:46 AM
Post #3

New D.I.C Head
*

Joined: 16 Feb, 2007
Posts: 44


My Contributions
This demonstrates a few formulas executed upon the start of the program.

CODE

class callit
{

public static void main (String args[]){






System.out.println("__________________________");









//output from classes by creating and object


//turns it from a class to a new object
System.out.println("To calculate the momentum we use mv");
momenTUM ac = new momenTUM();
ac.display();

System.out.println("__________________________");
System.out.println(" To calculate the speed of light we use e=mcc");
lightSPEED ab= new lightSPEED();
ab.display();


System.out.println("__________________________");

}

}



//* Abstract class personAB - write a description of the class here

//This is the superclass in this file
abstract class theCalculator
{
//The abstract class makes every class in this file have a display method.
abstract void display();
//abstract float calculateMe();
}
    


//This is a subclass of personAB
//Because it is a subclass it has to have a display() method
class momenTUM extends theCalculator{



//float calculateMe(){
float m=4;
float v=2;
float mv=m*v;

//return(mv);
//}

void display(){
momenTUM mt= new momenTUM();
System.out.println(m+" is the mass");
System.out.println(v+" is the speed");
System.out.println(mv+" is the momentum");
//System.out.println(mt.calculateMe());

}
}
//E=mc≤
class lightSPEED extends theCalculator{



//float calculateMe(){
float m=3;
float c=299792458;
float cc=(c*c)*m;
//return(mv);
//return(cc);
//}

void display(){
lightSPEED ls= new lightSPEED();
System.out.println(cc+" is the energy");
System.out.println(c+" is the speed of light");
System.out.println(m+" is the mass of the object");
//System.out.println(ls.calculateMe());

}
}









Now this does not allow for user input if you need that start a new post. But this shows basic math logic.

CN
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 04:48AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month