Question

1.8 zyLab training: Basics (Java) While the zyLab platform can be used without training, a bit...

1.8 zyLab training: Basics (Java)

While the zyLab platform can be used without training, a bit of training may help some students avoid common issues.

The assignment is to get an integer from input, and output that integer squared, ending with newline. (Note: This assignment is configured to have students programming directly in the zyBook. Instructors may instead require students to upload a file). Below is a program that's been nearly completed for you.

Click "Run program". The output is wrong. Sometimes a program lacking input will produce wrong output (as in this case), or no output. Remember to always pre-enter needed input.

Type 2 in the input box, then click "Run program", and note the output is 4.

Type 3 in the input box instead, run, and note the output is 6.

When students are done developing their program, they can submit the program for automated grading.

Click the "Submit mode" tab

Click "Submit for grading".

The first test case failed (as did all test cases, but focus on the first test case first). The highlighted arrow symbol means an ending newline was expected but is missing from your program's output.

Matching output exactly, even whitespace, is often required. Change the program to output an ending newline.

Click on "Develop mode", and change the output statement to output a newline: System.out.print(userNumSquared);. Type 2 in the input box and run.

Click on "Submit mode", click "Submit for grading", and observe that now the first test case passes and 1 point was earned.

The last two test cases failed, due to a bug, yielding only 1 of 3 possible points. Fix that bug.

Click on "Develop mode", change the program to use * rather than +, and try running with input 2 (output is 4) and 3 (output is now 9, not 6 as before).

Click on "Submit mode" again, and click "Submit for grading". Observe that all test cases are passed, and you've earned 3 of 3 points.

CODE

import java.util.Scanner;

public class NumSquared {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int userNum;
int userNumSquared;
  
userNum = scnr.nextInt();
  
userNumSquared = userNum + userNum; // Bug here; fix it when instructed
  
System.out.print(userNumSquared); // Output formatting issue here; fix it when instructed
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

import java.util.Scanner;

public class NumSquared {

public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int userNum;
int userNumSquared;
  
userNum = scnr.nextInt();
  
userNumSquared = userNum*userNum; // Fixed : * instead of +
  
System.out.println(userNumSquared); // Done, used println instead of print
}
}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
1.8 zyLab training: Basics (Java) While the zyLab platform can be used without training, a bit...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Auto-graded programming assignments have numerous advantages, but have some challenges too. Students commonly struggle with realizing...

    Auto-graded programming assignments have numerous advantages, but have some challenges too. Students commonly struggle with realizing that example input / output provided in an assignment's specification interleaves input and output, but the program should only output the output parts. If a program should double its input, an instructor might provide this example: Enter x: 5 x doubled is: 10 Students often incorrectly create a program that outputs the 5. Instead, the program should only output the output parts: Enter x:...

  • in java, finish the method 17: Chapter 8: Handling a number as different types (Method Overloading)...

    in java, finish the method 17: Chapter 8: Handling a number as different types (Method Overloading) J o pulli UCILISIS lule zyBooks catalog Help/FAQ 31.47 Chapter 8: Handling a number as different types (Method Overloading) Write an overloaded method called divide_by_two() that can handle a number between 1-5 as an int, double, or String. • The method should be able to handle the String version with upper or lower case letters in any location in the String. ACTIVITY 31.47.1: Chapter...

  • in java M al you wille to print: • The area of the box if the...

    in java M al you wille to print: • The area of the box if the user gives valid sizes "Invalid size given', otherwise . For example, if the user enters: 'small medium large', the program will print Area of the box is 6 . For example, if the user enters: 'small medium big', the program will print 'Invalid size given LAB ACTIVITY 31.24.1: Chapter 7: Area of a box (Methods) 0/5 Main.java Load default template. 1 import java.util.Scanner; LD...

  • 5.13 LAB: Output range with increment of 10 5.13 LAB: Output range with increment of 10...

    5.13 LAB: Output range with increment of 10 5.13 LAB: Output range with increment of 10 Write a program whose input is two integers, and whose output is the first integer and subsequent increments of 10 as long as the value is less than or equal to the second integer Ex: If the input is -15 30, the output is: 15-5 5 15 25 Ex: If the second integer is less than the first as in 20 5, the output...

  • C# Programming: DebugNine2 The provided file has syntax and/or logical errors. Determine the problem(s) and fix...

    C# Programming: DebugNine2 The provided file has syntax and/or logical errors. Determine the problem(s) and fix the program. +DebugNine2.cs Instructions Build Output The provided file has syntax and/or logical errors. Determine the problem(s) and fix the program. 1/ Creates a Breakfast class 2 // and instantiates an object 3// Displays Breakfast special information 4 using static System.Console; Conpilation fatled: 2 error(s), 8 warnings DebugNine2.cs(9,61): error C$1810: Newline in constant DebugNine2.cs (11,6): error CS1525: Unexpected synbol "Writeltne class DebugNine2 7static void...

  • use  JOptionPane to display output Can someone please help write a program in Java using loops, not...

    use  JOptionPane to display output Can someone please help write a program in Java using loops, not HashMap Test 1 Grades After the class complete the first exam, I saved all of the grades in a text file called test1.txt. Your job is to do some analysis on the grades for me. Input: There will not be any input for this program. This is called a batch program because there will be no user interaction other than to run the program....

  • This program will take the classic tongue-twister "Peter Piper picked a peck of pickled peppers." and...

    This program will take the classic tongue-twister "Peter Piper picked a peck of pickled peppers." and generate a tongue twister phrase based on user input for a last name, a unit of measurement and a vegetable. For all three cases, the user input may be multiple words. Once read, the user input will be modified to fit the following rules: last name: No leading or trailing whitespace; the first character will be upper case and the rest lower case. unit...

  • [15 marks] Suppose that students enrolled in one course are required to take four tests, and...

    [15 marks] Suppose that students enrolled in one course are required to take four tests, and each student’s final grade for this course is the average of his/her grades of these four tests. This question asks you to write a program that can be used to compute the lowest final grade, highest final grade and the average final grade. General Requirements: Use a5q1.c as the name of your C source code file. We will use the following command on bluenose...

  • Can anyone help me with this code? I've never worked with insertion sort and I'm having...

    Can anyone help me with this code? I've never worked with insertion sort and I'm having trouble. I posted the instructions and the included code. Thank you! Insertion Sort Given an array of integers, sort the array in ascending/descending order by using Insertion sort. Reference: http://www.algolist.net/Algorithms/Sorting/Insertion_sort Input 4368 92157 Where, • First line represents the type of ordering. • Second line represents the size of the array. • Third line represents the array elements. Output 123456789 + Test Case(s) DriverMain.java...

  • You will need to think about problem solving. There are several multi-step activities. Design, compile and...

    You will need to think about problem solving. There are several multi-step activities. Design, compile and run a single Java program, StringEx.java, to accomplish all of the following tasks. Add one part at a time and test before trying the next one. The program can just include a main method, or it is neater to split things into separate methods (all static void, with names like showLength, sentenceType, lastFirst1, lastFirst), and have main call all the ones you have written...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT