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 integer
System.out.println("Please enter an integer larger than 0: ");
//Step 2: Get an integer from the user and assign it to the
variable num.
//Step 3: Check the value of num. Print an error message if it's
less than 1.
// Otherwise, call sumSquare method and print the returned
value.
System.out.println("**************************");
System.out.println(" Task 2: Displacement");
System.out.println("**************************");
//Task 2. Write your code here.
//Print the prompt and ask the user to enter three double values
separated by space.
System.out.println("Please enter three double values for x, v, and
t(separated by space): ");
//Step 4: Write three statements here to get the double values from
the user and
// assign them to the variables x, v, and t.
//Step 5: Call the displacement method with the three variables
x, v, and t,
// and print the returned value.
}
public static int sumSquare (int number) {
int sum = 1;
//Step 6: Check the value of the parameter number. If number is
equal to 1, return sum directly.
//Step 7: Calculate the sum of the squares from 1 to the value of number using a for loop.
//Step 8: Return sum
}
public static double displacement (double x, double v, double t) {
//Step 9: Declare a constant G and assign it to be 9.78.
//Step 10: Calculate the displacement and return it.
}
}
Step 1:
Scanner in =new Scanner(System.in);
Step 2:
num=in.nextInt();
Step 3:
if(num<1)
System.out.println("Error");
else
System.out.println(sumSquare(num));
Step 4:
x=in.nextDouble();
v=in.nextDouble();
t=in.nextDouble();
Step 5:
System.out.println(displacement(x,v,t));
Step 6:
if(number==1)return 1;
Step 7:
for(int i=1;i<=number;i++)
sum+=(i*i);
Step 8:
return sum;
Step 9:
final double G=9.78;
Step 10:
return x +(v*t +0.5*G*t*t);
This is for a java program public class Calculation { public static void main(String[] args)...
public static void main(String[] args) { System.out.println("Welcome to the Future Value Calculator\n"); Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // get the input from the user System.out.println("DATA ENTRY"); double monthlyInvestment = getDoubleWithinRange(sc, "Enter monthly investment: ", 0, 1000); double interestRate = getDoubleWithinRange(sc, "Enter yearly interest rate: ", 0, 30); int years = getIntWithinRange(sc, "Enter number of years: ", 0, 100); System.out.println(); ...
import java.util.Scanner; public class SCAN { public static void main(String[ ] args) { int x, y, z; double average; Scanner scan = new Scanner(System.in); System.out.println("Enter an integer value"); x = scan.nextInt( ); System.out.println("Enter another integer value"); y = scan.nextInt( ); System.out.println("Enter a third integer value"); z = scan.nextInt( ); average = (x + y + z) / 3; System.out.println("The result of my calculation is " + average); } } What is output if x = 0, y = 1 and...
Correct the mistakes public class customer { public static void main(String[] args) { D customer=new d(); d.employee(56,”ali”); d.department(7,8.6,9); } public void employee(String name, int age) { System.out.println("Your name is"+name); System.out.println(“Age is”+age); } public int department(double d, double t, int a) { System.out.println("I have java exam at 3:00"); Return(1.1); } } V. PROGRAMMING. Write a complete JAVA program to implement the following. 1. Create a class named Exponent. Its main() method accepts an integer value from a user at the keyboard,...
Given the following Java code: public static void main (String[] args) { int num; System.out.println("Enter a number"); num = scan.nextInt(); <-first input statement while (num != 0) { System.out.println ("The number is: " + num); System.out.println("Enter a number"); num = scan.nextInt(); } //End While } //End Module The first input statement shown above is called the:
import java.util.Scanner; public class SieveOfEratosthenes { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter a number"); int num = sc.nextInt(); boolean[] bool = new boolean[num]; for (int i = 0; i< bool.length; i++) { bool[i] = true; } for (int i = 2; i< Math.sqrt(num); i++) { if(bool[i] == true) { for(int j = (i*i); j<num; j = j+i) { bool[j] = false;...
Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp { public static void main(String[] args) { displayWelcomeMessage(); // create the Scanner object Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // generate the random number and invite user to guess it int number = getRandomNumber(); displayPleaseGuessMessage(); // continue until the user guesses the number int guessNumber = 0; int counter = 1; while (guessNumber != number) { // get a valid int from user guessNumber...
import java.util.Scanner;
public class Lab6d {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
// TODO: get user choice
// TODO: call printTable method passing choice as the
parameter
}
public static void printTable(int stop) {
// TODO: print header
// TODO: loop to print table rows up to stop value
}
Write a Java program where the main () method prompts the user to select an integer value between 1 and...
import java.util.Scanner; public class StudentClient { public static void main(String[] args) { Student s1 = new Student(); Student s2 = new Student("Smith", "123-45-6789", 3.2); Student s3 = new Student("Jones", "987-65-4321", 3.7); System.out.println("The name of student #1 is "); System.out.println("The social security number of student #1 is " + s1.toString()); System.out.println("Student #2 is " + s2); System.out.println("the name of student #3 is " + s3.getName()); System.out.println("The social security number...
Draw a flowchart for this program public class InsertionSort { public static void main(String a[]) { int[] array = {7, 1, 3, 2, 42, 76, 9}; insertionSort(array); } public static int[] insertionSort(int[] input) { int temp; for (int i = 1; i < input.length; i++) { for (int j = i; j > 0; j--) { if (input[j] < input[j - 1]) { temp = input[j]; input[j] = input[j - 1]; input[j - 1] = temp; } } display(input, i);...
please debug this code:
import java.util.Scanner;
import edhesive.shapes.*;
public class U2_L7_Activity_Three{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
double radius;
double length;
System.out.println("Enter radius:");
double r = scan.nextDouble();
System.out.println("Enter length:");
double l = scan.nextDouble();
System.out.println("Enter sides:");
int s = scan.nextInt();
Circle c = Circle(radius);
p = RegularPolygon(l , s);
System.out.println(c);
System.out.println(p);
}
}
Instructions Debug the code provided in the starter file so it does the following: • creates two Double objects named radius and length creates...