Uncategorized

Compilation Failed Usercode Question & Answer Guide (With Explanation)

Students often encounter this when studying fundamental concepts.

What This Question Is About

This question relates to compilation failed usercode and requires a structured academic response.

How to Approach This Question

Structure your response with introduction, analysis, and conclusion.

Key Explanation

This topic involves compilation failed usercode. A strong answer should include explanation, application, and examples.

Original Question

Compilation Failed: ———————————————————————- /usercode/zyLabsUnitTest.java:9: error: constructor HealthProfile in class HealthProfile cannot be applied to given types; HealthProfile hp = new HealthProfile(); ^ required: String,int,double,int found: no arguments reason: actual and formal argument lists differ in length 1 error Health Profile Class: public class HealthProfile { private String name; private int age; private double weight; // in pounds private int height; // in inches // Constructor public HealthProfile(String name, int age, double weight, int height) { this.name = name; this.age = age; this.weight = weight; this.height = height; } // Method to calculate BMI public double calculateBMI() { return (weight / (height * height)) * 703; } // Method to calculate BMI Category public String calculateCategory() { double bmi = calculateBMI(); if (bmi < 18.5) { return "Underweight"; } else if (bmi < 25) { return "Normal"; } else if (bmi < 30) { return "Overweight"; } else { return "Obese"; } } // Method to calculate Maximum Heart Rate public int calculateMaxHR() { return 220 - age; } // Getter and Setter methods public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public double getWeight() { return weight; } public void setWeight(double weight) { this.weight = weight; } public int getHeight() { return height; } // Method to set height using feet and inches public void setHeight(int feet, int inches) { this.height = feet * 12 + inches; } } Main Class: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (true) { System.out.print("Enter name or X to quit: "); String name = scanner.nextLine(); if (name.equalsIgnoreCase("X")) { break; } System.out.print("Enter age: "); int age = scanner.nextInt(); System.out.print("Enter weight: "); double weight = scanner.nextDouble(); System.out.print("Enter height - feet: "); int feet = scanner.nextInt(); System.out.print("Enter height - inches: "); int inches = scanner.nextInt(); scanner.nextLine(); // Consume the leftover newline // Create a HealthProfile object HealthProfile profile = new HealthProfile(name, age, weight, 0); profile.setHeight(feet, inches); // Display the health profile System.out.printf("Health Profile for %s%n", profile.getName()); System.out.printf("BMI: %.1f%n", profile.calculateBMI()); System.out.printf("BMI Category: %s%n", profile.calculateCategory()); System.out.printf("Max heart rate: %d%n", profile.calculateMaxHR()); } scanner.close(); } }

 
******CLICK ORDER NOW BELOW AND OUR WRITERS WILL WRITE AN ANSWER TO THIS ASSIGNMENT OR ANY OTHER ASSIGNMENT, DISCUSSION, ESSAY, HOMEWORK OR QUESTION YOU MAY HAVE. OUR PAPERS ARE PLAGIARISM FREE*******."