java - How to call a method without using parameters -
i'm not sure how phone call method without parameters or why it. variables aren't declared yet i'll after. the programme supposed take user input on dog's weight , convert kg if come in in lb calculate amount of nutrient feed dog.
import javax.swing.joptionpane; import java.util.scanner; public class hakesgraemea2q1{ public static void main(string args[]) { double weightconversion = convertlbtokg() double weightinlb = } public static double convertlbtokg(double weightinlb) { homecoming weightinlb * 0.454; } public static double readweight() { scanner keyboard = new scanner(system.in); string userinput = keyboard.nextline(); system.out.println("do want come in weight in kg or lb?, come in k kg or p lb "); if (userinput == "p"){ system.out.println("enter dogs weight in lb's:"); homecoming math.round(keyboard.nextdouble() * weightconversion)/ 4f; }else if (userinput == "k"){ system.out.println("enter dogs weight in kg's:"); homecoming math.round(keyboard.nextdouble())/4f; }else{ system.out.println("i can't understant choice; assuming kg:"); homecoming math.round(keyboard.nextdouble())/4f; } } public static double computefoodamount(double weightinkg) { if (weightinkg < 9.0){ homecoming weightinkg * 0.22; }else if (9.0 <= weightinkg && weightinkg < 32.0){ homecoming weightinkg * 0.18; }else if (32.0 <= weightinkg && weightinkg < 45.0){ homecoming weightinkg * 0.13; }else{ homecoming weightinkg * 0.09; } } }
if method without parameters, have set of empty brackets, such
double weight = readweight();
you utilize method without parameters if don't foresee said method having varying inputs. parameters inputs function, bunch of stuff happens , value returned. if inputs going same, no matter case, there may not utilize parameter. example, in readweight method, don't have external input coming function, having no parameters makes sense. convertlbtokg method requires external input when method called because have convert weight right unit of measurement, homecoming back.
java methods parameters
No comments:
Post a Comment