• Post Reply Bookmark Topic Watch Topic
  • New Topic

Method to add and multiply integers  RSS feed

 
Scott Howie
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
 
Guillermo Ishi
Ranch Hand
Posts: 789
C++ Linux Python
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Ok here's what I have so far

 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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.
 
Campbell Ritchie
Marshal
Posts: 56576
172
  • Mark post as helpful
  • send pies
  • 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.
 
joey parkker
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this may helps you



 
Campbell Ritchie
Marshal
Posts: 56576
172
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!