Question

In: Computer Science

I am struggling with this java code Objectives: Your program will be graded according to the...

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)

Solutions

Expert Solution

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
    }
}

Related Solutions

I am struggling with this assignment for my java class. Objectives: Your program will be graded...
I am struggling with this assignment for my java class. 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. (5 points) 2. Construct a Scanner to read input from the keyboard. (5 points) 3. Prompt the user with three questions from the Psychology Today quiz, and use the Scanner to read their...
I am struggling with this java code ublic class HW2_Q4 {    public static void main(String[]...
I am struggling with this java code ublic class HW2_Q4 {    public static void main(String[] args) {        // Define the input string. Note that I could have written it all on a        // single line, but I broke it up to match the question.        String input = "Book , Cost , Number\n"                    + "Hamlet , 24.95 , 10\n"                    + "King Lear , 18.42...
Assembly Question: I am trying to annotate this code and am struggling to understand what it...
Assembly Question: I am trying to annotate this code and am struggling to understand what it is doing. Can someone please add comments? .data .star: .string "*" .line: .string "\n" .input: .string "%d" .count: .space 8 .text .global main printstars: push %rsi push %rdi _printstars: push %rdi mov $.star, %rdi xor %rax, %rax call printf pop %rdi dec %rdi cmp $0, %rdi jg _printstars mov $.line, %rdi xor %rax, %rax call printf pop %rdi pop %rsi ret printstarpyramid: mov %rdi,...
I am struggling with this assignment. I can't get the program to run when I enter...
I am struggling with this assignment. I can't get the program to run when I enter a number with the $ symbol followed by a number below 10. any help would be greatly appreciated. Create a program named Auction that allows a user to enter an amount bid on an online auction item. Include three overloaded methods that accept an int, double, or string bid. Each method should display the bid and indicate whether it is over the minimum acceptable...
I am comfortable with structures that contains one item per variable. But i am struggling to...
I am comfortable with structures that contains one item per variable. But i am struggling to manage structure that contains multiple items in one variable (within a matrix). it's in C language. for example this structure :    struct resume{ char *name; char *job; char school*; int counter_resume; }resume; i want to create functions that are able to dynamically allocate memory so it can add multiple persons resume without knowing how many they are going to be in the beginning....
I am trying to write a java program that determines if an inputted year is a...
I am trying to write a java program that determines if an inputted year is a leap year or not, but I am not able to use if else statements how would I do it. I don't need the code just advice.
I have the following code for my java class assignment but i am having an issue...
I have the following code for my java class assignment but i am having an issue with this error i keep getting. On the following lines: return new Circle(color, radius); return new Rectangle(color, length, width); I am getting the following error for each line: "non-static variable this cannot be referenced from a static context" Here is the code I have: /* * ShapeDemo - simple inheritance hierarchy and dynamic binding. * * The Shape class must be compiled before the...
I am using NetBeans IDE Java for coding. I would like the code to be commented...
I am using NetBeans IDE Java for coding. I would like the code to be commented for a better understanding. 1. Implement a class Robot that simulates a robot wandering on an infinite plane. The robot is located at a point with integer coordinates and faces north, east, south, or west. Supply methods: public void turnLeft() public void turnRight() public void move() public Point getLocation() public String getDirection() The turnLeft and turnRight methods change the direction but not the location....
Java code TIA I need this: Your program makes accommodations for repeating digits. For example if...
Java code TIA I need this: Your program makes accommodations for repeating digits. For example if the random numbers generated were 141 in that order. Then the user entered 271 in that order, be sure that the last one does not count a match to the first and third numbers of the random numbers. They only matched one number in this case. Now if the random numbers are 141 in that order and the user enters 113, then they did...
I am struggling with certain types of factoring. I recognize there is a special situation, but...
I am struggling with certain types of factoring. I recognize there is a special situation, but don't understand how to factor it. For example y2+24yw-36w What's the procedure on determining how to factor this?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT