java


Calling methods within if statements


So I'm trying to call methods within if statements but I keep getting the error
"incompatible types unexpected return value".
This code is used to be called upon in another class.
public class Tax{
public double s, i;
public calculations(double s, double i){
if (s >=0 && s <=30000) {
return this.lowTax(s, i);
}
else if (s >30000) {
return this.highTax(s, i);
}
}
Then here I have the lowTax and highTax methods with a bunch of print statements.
public double lowTax(double s, double i){
System.out.println("Year 1");
System.out.println("Salary before Tax: " +s);
System.out.println("Tax paid: "+s*20/100);
System.out.println("Salary after tax: "+s*20/100 +s);
public double highTax(double s, double i){
System.out.println("Year 1");
System.out.println("Salary before Tax: " +s);
System.out.println("Tax paid: "+s*50/100 );
System.out.println("Salary after tax: "+s*50/100 +s);
You haven't mentioned the return type of your "calculations" method. It should probably be something like;
public double calculations (double s, double i){...}
I am guessing the methods "lowTax" and "highTax" are returning double values.
Set a return type on your function.
Considering lowTax() and highTax() return a double, your calculations method should look like
public double calculations(double s, double i)
{
...
}
You can't use return, because in constructors, there are no return types. So, if you want to call a method, you do it like JDev said.
if (s >=0 && s <=30000) {
this.lowTax(s, i);
}
else if (s >30000) {
this.highTax(s, i);
}
but, if you wanted to call them with return,
public double calculations(double s, double i){
if (s >=0 && s <=30000) {
return this.lowTax(s, i);
}
else if (s >30000) {
return this.highTax(s, i);
}

Related Links

Java inheritance in Android
Set time and speed complexity
Email Intent sends text file rather than image
named parameters in a subquery in hibernate
Can I replace jaxb.properties with code?
Java Sudoku Generator(easiest solution)
exact way to measure performance on individual methods from inside Java?
DataIntegrityViolationException: could not insert
How to get include url in Filter
JMS - Lookup problem
How do I write a custom JSON deserializer for Gson?
Java httpclient 4.1 how to send post request with configurable port
JList drag CustomObject but drop String
Failed to import Spring security bean configuration file from URL location
JAVA - How to find duplicate values in rows and columns in a 2D Array?
How do I transfer this c ++ for loop into java for loop

Categories

HOME
wso2-am
cookies
isabelle
ngrx
push-notification
rsyslog
installshield
fingerprint
yum
convolution
qore
cross-validation
add
adfs
dacpac
django-simple-history
sms-gateway
contextmenu
crystal-reports-2008
lucene.net
reverse-proxy
intentfilter
realex-payments-api
mmap
rundeck
one-to-many
microsoft-sync-framework
virtualdub
uninstall
fgetcsv
web-api-testing
replaceall
ejabberd-module
dbclient
google-cloud-endpoints-v2
noraui
usbserial
framemaker
amazon-kinesis-kpl
jmonkeyengine
xcode-extension
libraries
streamsets
code-search-engine
sql-server-agent
heightmap
qwt
menuitem
taffy
komodoedit
zip4j
pubmed
rails-routing
statsd
kbuild
quartz-composer
specrun
root-framework
visual-c++-2008
google-feed-api
transmitfile
persist
sigabrt
ubuntu-10.04
bluemix-app-scan
comobject
jmeter-maven-plugin
ruby-2.2
varargs
splash
proj4js
jsapi
tween
winddk
asp.net-dynamic-data
rdtsc
openexr
sgen
expected-exception
uv-mapping
quantlib-swig
eclipse-memory-analyzer
gridcontrol
mqx
eventlistener
hosts-file
dbproviderfactories
osql
dotnethighcharts
fireworks
qt-jambi
gcj
coredump
appender
lang
createwindow
paster
mirah
iweb
exchange-server-2003

Resources

Encrypt Message