I just recently started to learn about methods. I'm not that good with them nor do I fully understand them. This program I am writing is a simple program its asks the user if they want to convert pounds to kilograms or kilograms to pounds. In this assignment we are required to have 4 methods: The main method, P2k(pounds to kilos method), K2P, and a method that prints the results. I am not sure how to properly call the methods into the main method Here is my code if anyone can help me out.
package weightconversion; import java.util.Scanner; /** * * @author Zach */ public class WeightConversion { //Create global conversion rate public static final double CONVERSION_RATE =2.204; /** * @param args the command line arguments */ public static void main(String[] args) { //Declare variables int nChoice=0; //the user will choose pounds or kilos. Scanner input = new Scanner (System.in); //Used to read input double dP2K=0; //Converted pounds to kilos double dK2P=0; //Converted kilos to pounds double dPounds=0; //variable for pounds double dKilos=0; //variable for kilos double dWeight=0; //Weight variable double dConvertedWeight=0; //variable for weight converted //Display weight conversion System.out.println("WEIGHT CONVERSION"); //Displays pounds to kilos System.out.println("1." + "Pounds to kilograms"); //Displays kilos to pounds System.out.println("2." + "Kilograms to pounds"); //Prompt user to select type of conversion System.out.print("Please select the type of conversion" + " you would like to make:"); //Record input nChoice = input.nextInt(); //Prompt user to enter pounds if (nChoice == 1) { //Prompt user to enter pounds System.out.print("Please enter the pounds:"); //Record input dPounds = input.nextDouble(); //Calls method P2k with parameter dPounds dConvertedWeight = P2K(dPounds); } else if (nChoice == 2){ //Promp user to enter kilos System.out.print("Please enter the kilograms:"); //Record input dKilos = input.nextDouble(); //Calls method K2P with parameter dKilos dConvertedWeight = K2P (dKilos); } //What happens if user incorrectly enters wrong integer else //Tell user they need to run program again System.out.println("Error: Invalid conversion selection," + "Please run the program again. " ); dWeight = dPounds + dWeight; dWeight = dKilos + dWeight; } //Converts pounds to kilograms public static double P2K(double dPounds){ double dConvertedPounds = 0; //The converted pounds dConvertedPounds = dPounds/CONVERSION_RATE; //Formula return dConvertedPounds; //Retrun statement } public static double K2P(double dKilos){ double dConvertedKilos = 0; //The converted kilos dConvertedKilos = dKilos/CONVERSION_RATE; //Formula return dConvertedKilos; //Return statement } public static void PrintResults(dConvertedWeight,nChoice,dWeight){ } }
Im getting an error code for the last method saying it can not find the symbol, I know i'm doing it incorrectly, but not sure how to properly write it.