Problem 3. (15 points) Complete the two Java programs below. The first one, PrimeGenerator, generates prime numbers, and the second one, prompts the user for an integer, and then prints out all prime numbers up to that integer. For example, when the user enters 10, the program should print: 3 5 7 /** This class generates all prime numbers. public class PrimeGenerator private int current; public PrimeGenerator() current = 1; ** Calculates the next prime number. @return the next prime number */ public int nextPrime() // Complete this part Check if n is a prime number. @param n to check whether it is prime or not @return true if n is prime public static boolean isPrime(int n) // Complete this part
Q: Need help in writing a program consisting between 300-500 lines of code. Program is a java…
A: Java code is given below
Q: Problem 2 of Lab 8: Write a program to help a local restaurant automate its breakfast billing…
A: Program: //Including header file #include<iostream> #include<string> #include…
Q: Correct the following wrong statements. 1. do … while repetition statement gives full control on the…
A:
Q: JAVA LAB PRACTICE PROBLEMS 1. Write a program to create an object of the Calendar class having Year…
A: Here I have created an object of the Calendar class. Next, I have created variables to store the…
Q: Problem #1: Car experts recommend changing your air filter as often as every 6000 miles if the oil’s…
A: Here is the code using switch cases
Q: Question 3 Except where otherwise stated, any code you write in this question should be in Java. (a)…
A: Here is the detailed explanation of the solution
Q: Give the output of the following java program code.
A: import java.awt.*; public class SimpleExample extends Frame{ SimpleExample(){ Button b =…
Q: UTER FUNDAMENTALS AND PROGRAMMING 2 USING JAVA Problem 1: Using Scanner format, create a program…
A: Java code to compute the discount amount and the discounted price is given below.
Q: Create java program with a declaration of int x = {1,2,3,4,5,6,7,8,9,10} that prints the total of…
A: Please find the answer below :
Q: Write a program whose inputs are three integers, and whose output is the smallest of the three…
A: import java.util.*;class Test167 { public static void main(String args[]) { Scanner sc = new…
Q: Consider the following game between two players: Both players simultaneously declare “one” or "two".…
A: Part 1 Program Explanation: Define a class for the computer player Declare the instance variable,…
Q: Please, help to write such a programm in Java! Build a program to work with the Date class. The…
A: Calendar Class in Java Calendar class in Java is a theoretical class that gives strategies to…
Q: (1) Write a Java program that prompts the user to enter an integer number, then it computes its…
A: Algorithm : Step 1 : declaring the variable to store input and loop variable as int and factorial…
Q: PROBLEM STATEMENT: Return the greatest of two numbers! Can you help mew with this question The…
A: According to the Question below the Solution: Output:
Q: Indicate whether or not the following is a valid Java statement. Whenever the statement is invalid,…
A: double net profit = 5000.00; double is used to store float values ,it uses 64 bits to store a…
Q: Write Java code that will assign the variable G the value of 0 if a variable f is less than 6 or F…
A: logic:- set G=10,F=7 assumed. If(F<6 || F>5) set G=0 Display G
Q: Can not use "and" or "or" in java Language Write the function parrotTrouble. * * We have a loud…
A: PROGRAM STRUCTURE: Import the required package. Start the definition of the public class. Write the…
Q: Complete the class Problem 1, the program does the following: Prompt the user to enter an integer n.
A: Please find the answer below :
Q: 1. Using the steps in analyzing a problem, show how to solve a problem that obtains two integer…
A: We need to write 5 sub-steps to analyze the given problem. The problem is that we need to take two…
Q: 6. Write a Java program that takes age from the keyboard as _ and prints the age description…
A: Please find the answer below
Q: B/ State whether the following are true (✓) or false (x) and correct the false statements 1- We can…
A: Find the required answers with reason given as below : As per company guidelines we are supposed to…
Q: Debug Java Code Consider and understand the scenario that follows. Debug the program in order for…
A: Actually, Java is a high level programming language. And also object oriented . It. Is a platform…
Q: 1)-Write a Java program that reads values for three sides of a triangle. The sides will form a…
A: Please give positive ratings for my efforts. Thanks. PROGRAM import java.util.Scanner; class…
Q: 5. Assume each of the following has the same name, which of the following methods are overloaded…
A: Step 1:- Method Overloading is also known as Function overloading which means the method has…
Q: public void Unknown() if
A: Given :
Q: JAVA CODE ONLY 2. Rectangle by CodeChum Admin A rectangle can be formed given two points, the top…
A: The following formula is used in Java program: Find rectangle's area = length*breadth Find…
Q: 12,13,14, 15 public static void m { int c = 12; while( { System.out.
A: Below the output of the following program
Q: Create a java program that accepts five integers as arguments via the command line.The program…
A: Please give positive ratings for my efforts. Thanks. PROGRAM class Main { static int…
Q: QUESTION 21 Java uses early binding for all methods except for a few cases. O False O True
A: The statement Java uses early binding for all methods except for a few cases is false. Hence the…
Q: Problem 1: A candy factory can make 456 pieces of candies each day, create a java program that will…
A: note:- If two programs are not related , post it separately to maintain bartleby policy violation.…
Q: Use python, import sys, sys.argv to create a program called classname.py. The program should define…
A: please see the next step for solution
Q: 1) State whether the following declarations are valid or invalid. Give reasons for the invalid…
A: According to the guidelines i can answer only first 3 parts
Q: I'm new to Java programming. Can you please tell me what I'm doing wrong? My input are on lines 12…
A: In the above code, the formula of the volume of the sphere is incorrectly written on lines 12 and…
Q: Write a program that simulates rolling two twenty-sided dice 100000 times, counting now many times…
A: Below a program that simulates rolling two twenty-sided dice 100000 times, counting now many times…
Q: (in python 3) Take the username and password from a user and check the validity of the password…
A: 1. Take username and password as input from user 2. Check if password contains username, if yes…
Q: Operations All instructions in this section should be carried out in the class PrimitiveOperations,…
A: Primitive Operations Type casting means changing one primitive data type into another. It can simply…
Q: Q3 / In one of the projects we had the resistance of a large group of concrete cubes, it is required…
A: Input : Array of values of compressive strength. Output : Count of values in the range [20,30].
Q: - Write a Java method to find the s mong three entered numbers. ( Pro- our code and output )
A: GIVEN: Create a Java program with a method to find the smallest among three entered numbers.
Q: Using any of the iteration structure, write a class that would display the following numbers…
A: import java.util.*;import java.lang.*;import java.io.*; class Codechef{ public static void main…
Q: Read the following JAVA program and answer the questions given at the end.
A: (a) In class Example, there are two types of data members: Instance or non-static data members int…
Q: ind the error(s) in each of the following and explain how to correct it (them):a) Assume the…
A: a) Assume the following prototype is declared in class Time:void ~Time( int );
Q: 6. What will be the output of the following Java program?
A: Exceptions are run time errors which forces program to behave abnormally. That's why it is…
Q: Create java program with a declaration of int x = {1,2,3,4,5,6,7,8,9,10} that stores the value of…
A: We will retrieve the element at index 9 and then we will assign that element to index 1. The first…
Q: Rectangle by CodeChum Admin A rectangle can be formed given two points, the top left point and the…
A: To find center point of rectangle : mid_x = (x1+x2)/2 mid_y = (y1+y2)/2 Perimeter of rectangle…
Q: 05: Consider the following Java program: public void fun(void) { int a, b, c; /* definition 1 */ ...…
A: The java program: public void fun(void) { int a, b, c; /* definition 1 */ . . . while (.…
Q: The following program uses a variable workHoursPerWeek rather than directly using 40 in the salary…
A: 1. Observation of the program,Salary.java when workHoursPerWeek=40; //Salary.javapublic class Salary…
In java
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
- Remaining Time: 1 hour, 28 minutes, 35 seconds. * Question Completion Status: QUESTTON 11 There are five syntax errors in the following java program. Explain them by mentioning the line number with each error. public class public static void main (String [] args) { { double a = 9; 4 double b = 9.0; int x; System.out.println ("Sum of a and b is if( a = b) + (a+b)) 80 X = a; switch (a+b) { case 0: System.out.println (x); default: System.out.println (x) ; 10 11 12 13 14Put a box around your answers for the outputs. Determine the output for #1 - 5, 1. int i = 2; while (i 0; i = i - 1) System.out.print( "yes"); 5. int total : 4; int i = 2; while (i < 5) total = total * i; is i+ 1; System.out.printIn("The total is " + total); 6. Rewrite #5 above using a for loop instead of a while loop.42) Look at the following method: public static int test2 (int x, int y) if (x < y) { return -5; } else { return (test2 (x - y, y + 5) + 6) ; } } What is returned for test2 (10, 20)? A) -5 B) 1 C) 6 D) 10 43) This term is used for methods that directly call themselves. A) Simple recursion C) Absolute recursion B) Direct recursion D) Native recursion 44) If the base case in a recursive method is never reached: A) The result will always be off by one. C) The method will call itself indefinitely. B) The method will call itself only once. D) The method will never call itself. 45) A(n) is an object that is generated in memory as the result of an error or an unexpected event. A) exception C) default exception handler B) exception handler D) error message 46) All of the exceptions that you will handle are instances of classes that extend this class. A) Exception C) IOException B) RunTimeException D) Error 47) All exceptions are instances of dasses that extend this class. A) Throwable C)…
- a) The following attempt at Java code might have been written by a beginner. Identify (but do not correct) as many of the mistakes as you can. Explain how each oddity you identify is either something that would prevent the program from compiling, something that would cause it to stop abruptly reporting failure at runtime. //* A comment to start with: Exam:2000 */ public Class mycode.java { void static public fun main(String [junk]) begin Leaf tr = null; for (i=1; i>10; ++i) tr = new Node(i, tr) tr.print(); end; } class Leaf { integer value; Leaf(int value) { this = value; } public void print(){ System.out.println(value); } } class Node extends Leaf { Leaf left, right; Node(leaf l, Leaf r) { left = l, right = r; } void print() { left.print(); System.out.println("val=" @ value); right.print(); } } b) Comment each line of code.Task #1 Tracing Recursive Methods 1. Copy the file Recursion.java (see Code Listing 16.1) from the Student Files or as directed by your instructor. 2. Run the program to confirm that the generated answer is correct. Modify the factorial method in the following ways: a. Add these lines above the first if statement: int temp; System.out.println ("Method call "calculating "Factorial of: " + n); Copyright © 2019 Pearson Education, Inc., Hoboken NJ b. Remove this line in the recursive section at the end of the method: return (factorial(n - 1) * n); c. Add these lines in the recursive section: temp - factorial (n - 1) ; System.out.println ("Factorial of: " + (n - 1) + " is " + temp); return (temp * n); 3. Rerun the program and note how the recursive calls are built up on the run-time stack and then the values are calculated in reverse order as the run-time stack "unwinds".(3) public static void test_b(int n) { if (n>0) test_b(n-2); System.out.println(n + " "); Consider the following method: What is printed by the call test_b(4)? A. 0 2 4 B. 0 2 C. 2 4 D. 4 2 E. 4 20 3 (4) What is the efficacy class of +? n 3 A: ©(1) B: O (log n) C: O (n) D: O (n log n) E: Θ n)
- 2222 0539 * Question Completion Status: 444+ There are five syntax errors in the following java program. Explain them by mentioning the line number with each error. 1 public class Find Errors { public static void main (String[] args) { int a = 8; 2 3 4 int b = 9.0; int x; 6. System.out.println ('Sum of a and b is ' + (a+b)); if( a = b) 8 X = a; else 10 x = b; 11 switch (b > a) { case 0: System.out.println (x); default: System.out.println (x): 12 13 14 } 15 } Click Save and Submit to save and submit. Click Save All Answers to save all answers. Answersmport java.util.Scanner; public class ParkingCharges { // function to calculate the basic charge using the asked hours static double getBasicCharge(int hours) { if (hours >= 7 && hours <= 8) return 5.50; else if (hours >= 5 && hours <= 6) return 4.50; else if (hours >= 2 && hours <= 4) return 4.00; return 3.00; } // function to return the amount to subtract based on local living and OAP static double getDiscount(String isLocal, String isOAP) { if (isOAP.equals("Yes") && isLocal.equals("Yes")) return 2.0 + 1.0; else if (isOAP.equals("Yes")) return 2.0; else if (isLocal.equals("Yes")) return 1.0; return 0; } public static void main(String[] args) { // create a new Scanner object Scanner sc = new Scanner(System.in); // prompt the user to ask if they are disabled…Remaining Time: 55 minutes, 18 seconds. * Question Completion Status: QUESTION 17 There are five syntax errors in the following java program. Explain them by mentioning the line number with each error. 1 public class Find Errors { public static void main (String [] args) ( 3 int a = 8; 4 int b = 9,0; int x; System.out.println('Sum of a and b is ' if( a b) + (a+b)); 8 X = a; else 10 x = b; switch (b > a) { 11 case 0: System.out.println (x) : default: System.out.println (x); 12 13 14 15 Click Save and Submit to save and submit. Click Save All Answers to save all answers. Save All Answer TOSHIBA F5 BVD F6 F7 F8 F9 F10 F11 F12 INS SCROLL LOCK 7. 7 V 8 A9 A TyY!U
- Calculate your Physics final Write a Java program to solve the following problem: grade based on the following: Assessment Percent Lab Activity(ies) Quiz (zes)/Test (s) 10% 10 Assignment (s) 208 Midterm Exam (8) 20% Final Exam 40% Theory grade is the quiz/test, midterm and final exam marks. Practical grade is the assignment and lab marks. Final grade is all five marks. But the calculation of Final grade needs to comply with the following rule: If either of the practical or theory grade is less than 50%, the final grade is the lesser of the two. A grade letter must be assigned based on the final grade (See the courses outline for the distribution of grades) You must implement input validation for each mark as follows: Lab mark must be out of 10. Quiz/Test mark must be out of 10. Assignment mark must be out of 20. Midterm mark must be out of 20. Final Exam must be out of 40. Bonus: Modify your code so that you can calculate and display grade for N number of students. Your program must…JAVA Notes: all program codes should be written with method/s separated from the main() structure. Use a separate code files for each. Programming Problems: 1. Write a value-returning method, isVowel, that returns the value true if a given character is a vowel, otherwise return false. Also write a program to test your method. 2. Write a program that prompts the user to enter a sequence of characters and output the number of vowels and consonants separately. (use the method isVowel written in problem 1). 3. Write a program that output inflation rates for two successive years and whether the inflation rates are increasing or decreasing. Ask the user to input the current price of an item and its price, one year and two years ago. To calculate the inflation rate for a year, subtract the price of the item for that year and from the price of the item from one year ago and then divide the result by the price a year ago. Your program must contain a method to calculate the results. Use…light } What is the output of this Java program? } class Driver { public static void main(String[] args) { int a = 6: int b = 6; int c = 5; int x = 1; if (a > 2) { } } if x = x + 600; (b> 3) { x = x + 60; } if (c < 9) { X = x + 5; System.out.print(x);