In: Computer Science
I am struggling with this java code
Objectives: Your program will be graded according to the rubric below. Please review each objective before submitting your work so you don’t lose points. 1. Create a new project and class in Eclipse and add the main method. (10 points)
2. Construct a Scanner to read input from the keyboard. (10 points)
3. Use the Scanner to read the name, number of balls, and yards per ball of a yarn type specified by a pattern. Prompt the user to input this data as shown in the example below, and store the data in variables. (15 points)
4. Use the Scanner to read the name and yards per ball of a substitute yarn. Prompt the user to input this data, and store the data in variables. (10 points)
5. Use conditional statements to check that each numerical input is a positive integer. Give the user one chance to correct each invalid input. Prompt the user to input a positive value as shown in the example. (15 points)
6. Calculate the number of substitute yarn balls. Use a method of the Math class to round up to the nearest full ball, and store the result in a variable. (20 points)
7. Print the number of substitute yarn balls to the console, matching the format of the example. (10 points)
8. Use meaningful variable names, consistent indentation, and whitespace (blank lines and spaces) to make your code readable. Add comments where appropriate to explain the overall steps of your program. (10 points)
Thanks for the question, the question seems somewhat incomplete. The question does not includes the output sample which the question keeps on referring also the logic to calculate the number of substitute yarns balls is not given. I have tried to complete as much possible, so to kick start. If you can give me the remaining details then i can finish it off for you. Here is the code so far, comments given so that you can follow it. ============================================================================= import java.util.Scanner; public class YarnCalculator { // add the main method. (10 points) public static void main(String[] args) { //2. Construct a Scanner to read input from the keyboard. (10 points) Scanner scanner = new Scanner(System.in); //3. Use the Scanner to read the name, number of balls System.out.print("Enter name: "); String name = scanner.nextLine();// store teh name in a varaible // ask user to enter the number of balls System.out.print("Enter the number of balls: "); int ballCount = scanner.nextInt(); // store the count in the variable if (ballCount < 0) { System.out.println("Count cannot be in negative. Try Again."); System.out.print("Enter the number of balls: "); ballCount = scanner.nextInt(); // store the count in the variable } System.out.print("Enter yards per ball: "); int yardsPerBall = scanner.nextInt(); //store value if (yardsPerBall < 0) { System.out.println("Yards cannot be in negative. Try Again."); System.out.print("Enter yards per balls: "); yardsPerBall = scanner.nextInt(); // store the count in the variable } scanner.nextLine(); // to erase the line feed // 4. Use the Scanner to read the name and yards per ball of a substitute yarn. System.out.print("Enter substitue name: "); String subName = scanner.nextLine();// store teh name in a varaible // ask user to enter the number of balls System.out.print("Enter the number of balls: "); int subBallCount = scanner.nextInt(); // store the count in the variable if (subBallCount < 0) { System.out.println("Count cannot be in negative. Try Again."); System.out.print("Enter the number of balls: "); subBallCount = scanner.nextInt(); // store the count in the variable } System.out.print("Enter yards per ball: "); int subYardsPerBall = scanner.nextInt(); //store value if (subYardsPerBall < 0) { System.out.println("Yards cannot be in negative. Try Again."); System.out.print("Enter yards per balls: "); subYardsPerBall = scanner.nextInt(); // store the count in the variable } scanner.nextLine(); // to erase the line feed //6. Calculate the number of substitute yarn balls. // logic not given in the question } }