In this lab, you complete a partially written Java program that includes two methods that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a method that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another method that computes the product of all the whole numbers up to and including the entered number. The source code file provided for this lab includes the necessary variable declarations and the input statement. Comments are included in the file to help you write the remainder of the program. Instructions Ensure the file named SumAndProduct.java is open. Write the Java statements as indicated by the comments. Execute the program by clicking "Run Code." // SumAndProduct.java - This program computes sums and products. // Input: Interactive. // Output: Computed sum and product. import java.util.Scanner; public class SumAndProduct { public static void main(String args[]) { Scanner s = new Scanner(System.in); int number; String numberString; System.out.println("Enter a positive integer or 0 to quit: "); numberString = s.nextLine(); number = Integer.parseInt(numberString); while(number != 0) { // call sums() method here // call products() method here System.out.println("Enter a positive integer or 0 to quit: "); numberString = s.nextLine(); number = Integer.parseInt(numberString); } System.exit(0); } // End of main() method. // Write sums() method here. // Write products() method here. } // End of SumAndProduct class.
import java.util.Scanner;
class SumAndProduct {
static int sums(int x) {
int ans = 0;
for (int i = 1; i <= x; i++) {
ans += i;
}
return ans;
}
static int products(int x) {
int ans = 1;
for (int i = 1; i <= x; i++) {
ans *= i;
}
return ans;
}
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
int number;
String numberString;
System.out.println("Enter a positive integer or 0 to quit: ");
numberString = s.nextLine();
number = Integer.parseInt(numberString);
while (number != 0) {
// call sums() method here
int sum = sums(number);
int prod = products(number);
System.out.println("Sum = "+sum+" , Prod = "+prod);
// call products() method here
System.out.println("Enter a positive integer or 0 to quit: ");
numberString = s.nextLine();
number = Integer.parseInt(numberString);
}
// System.exit(0);
}
// End of main() method.
// Write sums() method here.
// Write products() method here.
// }
//
}
OUTPUT :

In this lab, you complete a partially written Java program that includes two methods that require...
In this lab, you complete a partially written Java program that includes two methods that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a method that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another method that computes the product of all the whole numbers up to...
In this lab, you complete a partially written Java program that includes methods that require multiple parameters (arguments). The program prompts the user for two numeric values. Both values should be passed to methods named calculateSum(), calculateDifference(), and calculateProduct(). The methods compute the sum of the two values, the difference between the two values, and the product of the two values. Each method should perform the appropriate computation and display the results. The source code file provided for this lab...
Complete a partially written C++ program that includes a function that return a value. The program is a simple calculator that prompts the user of 2 number and an operation (+, -, * or, /). The two number and the operator are passed to the function where the appropriate arithmetic operation is performed. The result is return to the main function () where the arithmetic operation and result are displayed. For example 3 * 4 = 12 The source code...
unctions with No Parameters Summary In this lab, you complete a partially prewritten Python program that includes a function with no parameters. The program asks the user if they have preregistered for art show tickets. If the user has preregistered, the program should call a function named discount() that displays the message "You are preregistered and qualify for a 5% discount." If the user has not preregistered, the program should call a function named noDiscount() that displays the message "Sorry,...
This is for a java program public class Calculation { public static void main(String[] args) { int num; // the number to calculate the sum of squares double x; // the variable of height double v; // the variable of velocity double t; // the variable of time System.out.println("**************************"); System.out.println(" Task 1: Sum of Squares"); System.out.println("**************************"); //Step 1: Create a Scanner object //Task 1. Write your code here //Print the prompt and ask the user to enter an...
Summary In this lab, you add a loop and the statements that make up the loop body to a Java program that is provided. When completed, the program should calculate two totals: the number of left-handed people and the number of right-handed people in your class. Your loop should execute until the user enters the character X instead of L for left-handed or R for right-handed. The inputs for this program are as follows: R, R, R, L, L, L,...
Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: o Write a method called cubeIt that accepts one integer parameter and returns the value raised to the third power as an integer. 2. Write a method called randomInRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. o Write a method called larger that accepts two double parameters and...
You will write a single java program called MadLibs. java. This file will hold and allow access to the values needed to handle the details for a "MadLibs" game. This class will not contain a maino method. It will not ask the user for any input, nor will it display (via System.out.print/In()) information to the user. The job of this class is to manage information, not to interact with the user.I am providing a MadLibsDriver.java e^{*} program that you can...
The program is described in Chapter 9, Exercise 11, in Programming Logic and Design. In this program, you should include two overloaded methods named computeRate(). One version accepts a number of days and calculates the rate at $99.99 per day. The other accepts a number of days and a code for a meal plan. If the code is A, three meals per day are included, and the price is $169.00 per day. If the code is C, breakfast is included,...
This is the contents of Lab11.java
import java.util.Scanner;
import java.io.*;
public class Lab11
{
public static void main(String args[]) throws IOException {
Scanner inFile = new Scanner(new File(args[0]));
Scanner keyboard = new Scanner(System.in);
TwoDArray array = new TwoDArray(inFile);
inFile.close();
int numRows = array.getNumRows();
int numCols = array.getNumCols();
int choice;
do {
System.out.println();
System.out.println("\t1. Find the number of rows in the 2D
array");
System.out.println("\t2. Find the number of columns in the 2D
array");
System.out.println("\t3. Find the sum of elements...