I don't understand which object I should put inside the identifier for Wind beaufort = new Wind(___);. The first line of code here is the constructor and the second is the class
import java.util.Scanner; public class WindSpeedCalc { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Wind speed in km/h: "); double kmH = scanner.nextDouble(); Wind wind = new Wind(kmH); System.out.printf("The wind speed is equivalent to %.2f knots to two decimal places\n", wind.calculateKnots()); Wind beaufort = new Wind(idkk); System.out.printf("The wind speed ranks around a %.1f on the Beaufort Scale\n", wind.calculateB()); System.out.print(wind.analyzeWind()); } } This is the class that connects to the constructor above. I don't believe there is anything wrong with this one.
public class Wind { double kmH; final double KM_IN_MI = 1.852; public Wind(double speedKmH) { kmH = speedKmH; } public double calculateKnots() { double knots = kmH / KM_IN_MI; return knots; } public int calculateB() { double mS = kmH / 3.6; double pow = 2.0 / 3.0; int b = (int)Math.round(Math.pow((mS / 0.836), pow)); if(b > 12) b = 12; return b; } public String analyzeWind() { String s = ""; if(kmH < 2) s = "Wind is calm"; else if (kmH > 120) s = "European storm"; else s = "Moderate to strong wind"; return s; } } https://stackoverflow.com/questions/66823674/which-object-do-i-use March 27, 2021 at 04:08AM
没有评论:
发表评论