Question
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.
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-enterStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started