• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Method to add and multiply integers

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys, been given this as a college exercise and not quite sure where to start.

Develop a method that accepts as data input three integer numbers,
calculates the sum and the product of the numbers,
and displays the sum and product.

Any help would be greatly appreciated.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I would start at step one, which is ...

Develop a method that accepts as data input three integer numbers



How do you "accept as data input" of an integer?

Henry
 
Ranch Hand
Posts: 789
Python C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Show your best attempt so far so we can see where you're at.


 
Scott Howie
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok here's what I have so far

 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Valiant first attempt, but unfortunately this won't compile and it doesn't seem to be in line with the assignment.
The method sumTotal() doesn't accept anything as input, nor does it display the result.
For more information on how to pass information to a method, please have a look at this tutorial.
You did get the calculation of the sum right, so points for that! The assignment also speaks of calculating the product which would require the use of a different operator, but is otherwise similar.
This tutorial explains the available operators.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

How much Java® have you been taught? It would be helpful to know what sort of level they expect you to work at. To continue from what Jelle said, a totalling method is a good thing. You can pass its result to a displaying method. As a general rule of thumb, the smaller a method is, the better.

Style thing: please delete every underscore character because Java® style is only to use underscores in test method names, constant names and package names.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this may helps you



 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

I am afraid that program does not help the OP very much. It shows some very out of date practice, poor exception handling and poor identifiers. It also does not answer the original question in the thread title.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic