Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java import javax. swing. JOptionPane; class Calc BMI 1private String name; //--

ID: 3607255 • Letter: J

Question

Java

import javax. swing. JOptionPane; class Calc BMI 1private String name; //----LINE 6 /1-LINE 7 private int w private int h; private double BMI //-LINE 9 11---LINE 10 public Calc-BMI () public calc-BMI ( String newName public calcBMI ( !nt neww , int newH) { w = newi ; h = newH ; public Calc_BMI String newName, int newW, int newH) ( name-"No name yet"I/--LINE 13 ) //LINE 14 > 11-LINE 15 //- LINE 16 //--- LINE 17 //--- LINE 18 ) { name= newName; } // { name -newName; w newW ; h = newH ; BMI -BMI(); } public void Calc_BMI String newName, int neww, int newH) 1I { name = newName; w = neww; h = newH; BMI = BMI(); } public void setW int new)wneww; public void setA( int newH ) { h = newH; } public void getR( int myw ) { myW = w; } public void getE( int myH ) { myH = h; } /1----LINE 21 LINE 22 1--LINE 23 //----LINE 24 public double BMI ( ) { BMI = ( w * 703) / ( hth ); return BMI:) //-- LINE 26 lic void writeout () //-- LINE 28 //-- LINE 29 +Height-"+ hBMI-"+this.BMILINE 30 System.out.print ("Name:"+ name, Weight-"+ w //-- LINE 33 /LINE 34 //-LINE 35 //-- LINE 36 public void writeOut String fmt) JoptionPane.showMessageDialog (null, "o/P format-" fmt +"nName name "nWeight- "w + " Height= " + h + " BM1= " + (int) BMI () ) ; public class MID DEMO Calc BMI /LINE 40 LINE 41 public static void main( String args) string t = "Calculate BMI for weight & height "; System.out.print t calc BMI b = new Calc BMI( "John Goodman", 170, 69 ); { //---- LINE 43 /-- LINE 44 LINE 45 / b.writeout b.writeout "GUI" //LINE 46

Explanation / Answer

Hi, the following are answers to your queries. Hope it helps.

Please rate this answer.

Q10:10
In the example, there are 2 different class definitions - Calc_BMI and MID_DEMO_Calc_BMI.
Java mandates that only one class in a single Java file can be declared with "public" access specifier.

So if the other class - Calc_BMI is too declared as "public", a compile-time error is shown.

Q10:11
The name of the Java file must be same as the class that has been declared as "public".

In this example, the file has been saved as "DEMO_Calc_BMI", as this is the class that has been declared as "public" and also it contains the main method.

If the file is saved as "Calc_BMI.java", there will be compilation error (see Q10.10) and also, it will not execute as it doesnt contain the main method

Q10:12
In line #6, we are importing the JOptionPane class to display a dialog on the screen.

If the import statement is deleted, a compilation error is displayed about missing symbol in Line# 34

Q10:13
NO

A main method is the entry point for a Java application. If the main method is missing, JRE will display an error during execution.


Q10.14
The methods between the line #13-16, are known as constructors.

The constructor methods are used to create objects of the class. These methods can be include different parameters; however they will NOT return values.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote