Alright let me start off by saying I am a beginner. This might sound stupid but I don't even know how to run my java program to try it out. With that being said I have a problem. I am doing an assignment for school that requires me to write a java program that asks the user to enter either a 1 or 2. If its not a 1 or 2 then the program exits and says please enter a one or two. If its a 1 then it asks for the user to enter two non-negative numbers for the base and height so it can figure the area of the triangle. If the user enters a negative number the program exits and says what number was negative. If its a 2 it asks for a number for radius and calculates the area of a circle. Same deal with the negative. If they enter the right numbers it prints Area of Triangle with base=(number), Height=(number): area. And same for the circle. It says I should use calcTriangleArea and calcCircleArea. Now I have written something that I don't know how to test so I don't know if its right. Can someone maybe tell me if its right and if not where I am wrong.
importjava.until.scanner; class Area { Area() { int number; //Number int b; //Base int h; //Height int r; //Radius //Read number from user scanner in = newScanner(System.in); system.out.print("Please enter either 1 or 2"); number = in.nextInt(); if (number = 1) || (number = 2){ if (number = 1){ system.out.print("Please enter non-negative number for Base"); b = in.nextInt(); system.out.print("Please enter non-negative number for Height"); h = in.nextInt(); system.out.print("Base: " + "b", "Height: " + "h", "Area of Triangle: " + "0.5*b*h"); } elseif (number = 2){ system.out.print("Please enter non-negative number for radius"); r = in.nextInt(); system.out.print("Radius: " + "r," "Area of Circle: " + "3.14*r*r"); } else{ system.out.print("Please enter either 1 or 2! Program exits"); } } public static void man(String args[]) { //declare and instantiate a new object Area obj1 = new Area(); } }