Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is the code: import java.util.Scanner; public class A0Q1 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int Items = scanner.nextInt();

Here is the code:

import java.util.Scanner;

public class A0Q1

{

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

int Items = scanner.nextInt();

scanner.nextLine();

for (int i = 0; i <= Items; i++) {

String line = scanner.nextLine();

String[] parts = line.split(" ");

String name = parts[0];

int SHU = Integer.parseInt(parts[1]);

double Price1 = Double.parseDouble(parts[2]);

double Price2 = Double.parseDouble(parts[3]);

double Price3 = Double.parseDouble(parts[4]);

String warning = "mild";

if (SHU > 10000 && SHU < 1000000) {

warning = "hot!";

} else if (SHU >= 1000000) {

warning = "DANGER!!!";

}

System.out.printf("%s Wings cost $%.2f/$%.2f/$%.2f and have %d Scovilles (%s) ",

name, Price1, Price2, Price3, SHU, warning);

}

}

}

and here are the inputs:

7 Spicy 8000 7 12 20 Hot 15000 7 12 20 Dangerous 20000 8 13 22 HabaneroArrow 350000 12 20 27 SmokeyChipotle 7500 10 18 25 TropicalSunburn 50000 12 20 27 MadHatter 350000 12 20 27

and the codio shows :

Spicy Wings cost $7.00/$12.00/$20.00 and have 8000 Scovilles (mild) Hot Wings cost $7.00/$12.00/$20.00 and have 15000 Scovilles (hot!)

Dangerous Wings cost $8.00/$13.00/$22.00 and have 20000 Scovilles (hot!)

HabaneroArrow Wings cost $12.00/$20.00/$27.00 and have 350000 Scovilles (hot!)

SmokeyChipotle Wings cost $10.00/$18.00/$25.00 and have 7500 Scovilles (mild)

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 4 out of bounds for length 4 at A0Q1.main(A0Q1.java:17)

I can not find where the wrong is.:(

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions

Question

Use the trapezoidal rule with n = 8 to approximate S cos(x) X dx

Answered: 1 week ago

Question

=+ a. How does this change affect the incentives for working?

Answered: 1 week ago