Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-22-2008, 08:38 AM
Member
 
Join Date: Jan 2008
Posts: 9
chitwood is on a distinguished road
sum,product,average program
How do i write a java program that will ask fdor 5 numbers to be inputted from an input dialog box and display the sum = ?,the product =, and the average = altogether in the same program using those 5 numbers?????

I need to get this written and submitted before 12:000am on the 23,2008 of jan. I am in an introductory programming class in college and I have never written any programs except for the ones in the book, that actually work with my help.



I would appreciate any assistance with this matter



Thanks,


Michael Chitwood
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-22-2008, 11:55 PM
gibsonrocker800's Avatar
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
What have you got so far? In the future, please don't post an assignment asking people to do it. Give us the code you've come up with so far, and ask any questions. You didn't really specify what you are having trouble with.
__________________
//Haha javac, can't see me now, can ya?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-23-2008, 01:49 AM
Member
 
Join Date: Jan 2008
Posts: 9
chitwood is on a distinguished road
that is the problem I have no clue how to get started!
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-23-2008, 01:51 AM
Member
 
Join Date: Jan 2008
Posts: 9
chitwood is on a distinguished road
import javax.swing.JOptionPane;

public class SumProductAverage {
public static void main(String [] args) {
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-23-2008, 01:59 AM
Member
 
Join Date: Jan 2008
Posts: 9
chitwood is on a distinguished road
Thanks for the advise, but I know nothing about programming in Java or any other language for that matter. You can say that I am green. I have just started this class and this is the first programming language that I have been introduced to. We are using the Book Fundamentals First: Introduction to Java Programming by Y. Daniel Liang. What I have posted is all that I can think of on how to get started. I dont understand if what I have is right, or even if it is roght where to go to from here. The assigment is for us to create an input dialog box with 5 different numbers and the end product has to tell the sum, product, and average.

Thanks

Chitwood
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 01-23-2008, 01:59 AM
gibsonrocker800's Avatar
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
Ok well, you could do it this way, but i prefer a more object-oriented approach. Basically, what i mean is that i would prefer to make a class in which i can construct a new object that calls for the 5 numbers, and there are methods in this class for doing each operation. If you want to get more sophisticated and practical, you can have it call for any amount of numbers (through use of arrays), but don't worry about that yet. So Ok, i'll set up the structure for you and see if you can figure out the method definitions.

Code:
public class MathData { private int a; private int b; private int c; private int d; private int e; public MathData(int a1, int b1, int c1, int d1, int e1) { a = a1; b = b1; c = c1; d = d1; e = e1; } public int findSum() { //code goes here } public int findProduct() { //code goes here } public int findAverage() { //code goes here } }
Ok so i've set up the class for you. See if you can write the code for the methods.
__________________
//Haha javac, can't see me now, can ya?
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 01-24-2008, 06:10 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
Everything you need for your program can be found at the Sun tutorials. After that, you just need a little mathematical logic.

Btw, please do not PM staff with code/logic issues. Other members are not off limits, so long as they approve of your PMs. But often, staff are busy manning the forum helms - besides you can get a lot of feedback from the forums vs. PMs.

Provided the code you PMed:
Code:
import javax.swing.JOptionPane; public class MathData1 { public static void main(String[] args) { JOptionPane.showInputDialog(null, "Enter Integer 1", "Input Dialog", JOptionPane.QUESTION_MESSAGE); JOptionPane.showInputDialog(null, "Enter Integer 2", "Input Dialog", JOptionPane.QUESTION_MESSAGE); JOptionPane.showInputDialog(null, "Enter Integer 3", "Input Dialog", JOptionPane.QUESTION_MESSAGE); JOptionPane.showInputDialog(null, "Enter Integer 4", "Input Dialog", JOptionPane.QUESTION_MESSAGE); JOptionPane.showInputDialog(null, "Enter Integer 5", "Input Dialog", JOptionPane.QUESTION_MESSAGE); // Convert string to int int intValue = Integer.parseInt(intString); //Obtain Sum sum = "int 1" + "int 2" + "int 3" + "int 4" + "int 5"; JOptionPane.showMessageDialog(null, "Sum" JOptionPane.INFORMATION_MESSAGE); } }
one way to do what you need is declare some variables for your different ints. Also, sum is not declared in your program and yet you try and set it, you can't set what doesn't exist! When computing your sum, do not compute Strings - this is math, remember? compute integers.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 01-24-2008, 06:18 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
Btw, you can also incorporate gibson's class into the code you PMed me. That is, if you know how to instantiate objects, given the correct constructor and make calls to the class's methods. His code can make the concept of what you're trying to accomplish clearer via its OO characteristics.

I'll get you started on one integer.
Code:
... String sOne = JOptionPane.showInputDialog(null, "Enter Integer 1", "Input Dialog", JOptionPane.QUESTION_MESSAGE); ... MathData md = new MathData(sOne, ......); JOptionPane.showMessage(null, md.findSum()); ...
You've got less than an hour... get crackin!
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)

Last edited by CaptainMorgan : 01-24-2008 at 06:21 AM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate Average sthack99 New To Java 4 06-13-2008 12:09 PM
Adding Plugin Dependency for Feature-based Product abiieez SWT / JFace 2 05-27-2008 09:02 PM
can anyone help me to integrate license manager to a java product shwetatalikoti NetBeans 0 10-29-2007 06:34 AM
get the average and maximum score Eric Advanced Java 2 07-01-2007 05:15 AM
Calculate average age for women and men? Legoland New To Java 3 04-18-2007 11:38 AM


All times are GMT +3. The time now is 08:13 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org