Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Im getting an error when running the code however I have the correct output just a mismatch error. Please help I added a screenshot of

Im getting an error when running the code however I have the correct output just a mismatch error. Please help I added a screenshot of the error.image text in transcribed

import java.util.Scanner;

public class Project_31 {

public static void main(String[] args) {

// Scanner (input) Open

Scanner input = new Scanner(System.in);

// Yarn Name

String yarnName;

System.out.print("Enter the name of the yarn specified by your pattern. ");

yarnName = input.nextLine:();

// Yarn Balls

int yarnBalls;

System.out.print("Enter the number of balls of " + yarnName + " that are required. ");

yarnBalls = input.nextInt();

// Conditional Statement Positive Number

while (yarnBalls

System.out.print("The number of balls must be positive. Please re-enter. ");

yarnBalls = input.nextInt();

}

// Yarn Yards

double yarnYards;

System.out.print("Enter the number of yards per ball of " + yarnName + ". ");

yarnYards = input.nextDouble();

// Conditional Statement Positive Number

while (yarnYards

System.out.print("The number of yards must be positive. Please re-enter. ");

yarnYards = input.nextDouble();

}

// Sub Yarn Name

String subYarnName;

System.out.print("Enter the name of the substitute yarn. ");

subYarnName = input.nextLine();

// Sub Yarn Yards

double subYarnYards;

System.out.print("Enter the number of yards of " + subYarnName + ". ");

subYarnYards = input.nextDouble();

// Conditional Statement Positive Number

while (subYarnYards

System.out.print("The number of yards must be positive. Please re-enter. ");

subYarnYards = input.nextDouble();

}

// Sub Yarn Balls

int subYarnBalls;

subYarnBalls = (int) Math.ceil(((double) (yarnYards * yarnBalls) / subYarnYards));

System.out.print("You should purchase " + subYarnBalls + " balls of " + subYarnName + " instead of " + yarnBalls

+ " balls of " + yarnName + ". ");

// Scanner (input) Close

input.close();

}

}

2: Negative check 2 ^ Chunky Alpaca -2. Input 50 Big and Fluffy 40 Your output The number of balls must be positive. Please re-enter. Exception in thread "main" java.util. InputMismatchException at java.base/java.util.Scanner.throwFor (Scanner.java:939) at java.base/java.util.Scanner.next (Scanner.java:1594) at java.base/java.util.Scanner.nextDouble (Scanner.java:2564) at Project_3.main (Project_3.java:30) Your output does not contain The number of yards must be positive. Please re-enter

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

Database Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions

Question

research proposal request what permission must you request

Answered: 1 week ago

Question

Create a Fishbone diagram with the problem being coal "mine safety

Answered: 1 week ago

Question

1. How might volunteering help the employer and the employee?

Answered: 1 week ago