There are a few errors in this java code: can you fix it please, its basically a debugging exercise: public static int sum(int n){ int n; for (int i=1; i<=n;i--){ sum++; } return sum; } }
Q: Have a research on the use of the Math methods and write a program that uses Math method. Use at…
A: Solution: 1) Java code: public class Main { public static void main(String[]…
Q: change this java code into a pseudo code
A: This code is to find whether password is valid or invalid that is entered by user.If it is valid it…
Q: Write a method that returns the percentage of elements greater or equal to 90 in an array of…
A: public static void main(String args[]) { int a[] = {}; System.out.println(calcPercentage(a));…
Q: In Java: The program extends the representation for rational numbers Add a test class…
A: Algorithm: Start Create a class named Rational with numerator and denominator as its attributes…
Q: How to do it in the JAVA language? Write a program that has the following "static" return value…
A: We have to write a Java program Which has static" return value methods. The parameters have…
Q: You are given a positive number N. Write a program to round N to the nearest mult Note Consider the…
A: // Java implementation of the approachclass GFG{ // Function to round the given number// to the…
Q: What is the number of operations executed when the following Java code runs? Your answer is expected…
A: The given code is below- public class RandomSequence { public static void main ( String[] args ) {…
Q: Write a recursive Java method that calculates the sum of n positive integer numbers. The math…
A: Note:- please mention type of error which you have faced in your post. Here is logic:- public…
Q: 2. Write a Java method "largestOfFour" to find the largest number among four numbers. The method…
A: Required: create a java method to find maximum of 4 number given by user.
Q: java, write simple program use the following method: getMin: takes three integers as arguments and…
A: Here, Code instruction is given.
Q: Write a recursive method that parses a binary number as astring into a decimal integer. The method…
A: Program: //Import the package import java.util.Scanner; //Create a class public class Main {…
Q: Solution IN JAVA A quadratic equation a x² + b x + c = 0 has either 0, 1, or 2 distinct solutions…
A: In this problem we need to provide the solution in the JAVA Programming language. Algorithm -…
Q: What is the number of operations executed when the following Java code runs? Your answer is expected…
A: The given code is below- public class RandomSequence { public static void main ( String[] args ) {…
Q: You have a card on which the letter J is written on one side and K on the other. You want to see all…
A: The program illustrate a recursive function in java with a simple card problem as given in the…
Q: FOR JAVA Write a Java method that makes following calculation. f(n)= 1! - 2! + 3! - 4! + 5! .....…
A: Algorithm : factorial function : Step 1 : declare and initialize variables. Step 2 : check if n is…
Q: ITERATORS IN JAVA Re-write this program using Java Iterators but without changing the meaning and…
A: The ask is to populate and print the elements of 2-D array using the Iterator class. It also asks to…
Q: A positive integer is called a perfect number if it is equal to the sum of all of its positive…
A: Introduction: A positive integer is called a perfect number if it is equal to the sum of all of its…
Q: . Random walkers. Write a program RandomWalkers.java that takes two integer command-line arguments r…
A: public class RandomWalk { public static void main(String[] args) { int n =…
Q: (JAVA)Consider this code: int m = 3; int n = -2; m = ++m * n--; What are the final values of m…
A: if a= 3 b=a++ ( then b=3 and a=4 ) b=++a (then b= 4 and a=4) same also applicable in -- operator…
Q: Write a recursive method that counts the number of postive integers in a bag from the client…
A: Java is a programming language. It contains extensive libraries (package). It can be used to create…
Q: Need dry run for the following code in java language This question is from the book absolute…
A: For this question, there is supposed to be 2 classes, Circle and Rectangle where there will be a…
Q: .What will be the output when the following program is executed? public class Recur{ public…
A: using the function the code is called directly and indirectly which is called the recursive function…
Q: Write a static recursive method called mrecursiv that displays all of the permutations of the…
A: Find the required code in C++ as language not mentioned given as below and output :
Q: Creating a JAVA program which should implement a method that verifies whether a given 4 x 4 square…
A: Answer: I have written a code to generate magicSquare this will help to solve the problem if you…
Q: Write a method that returns the index of the smallest element in an array of doubles. The method…
A: As given, I need to write a Java program having a method that should receive an array for formal…
Q: Consider the following Java method. Which term best describes what this method computes? static int…
A: Incorrect options: a. average To find the average, one needs to find the sum of all array elements…
Q: Write a method that returns the percentage of elements greater or equal to 90 in an array of…
A: The method- calcPercentage( ) takes in an array of integer values as a parameter. Next, it iterates…
Q: Write a recursive method that converts a positive decimal number to into a binary number as a…
A: Program in Java: import java.util.*; import java.lang.*; import java.io.*; class DecimalToBinary {…
Q: Java- Consider this method declaration: void quiz(int i) { if (i > 1) {…
A: According to the information given:- We have to define the follow in code output.
Q: ISP-Java Write a program whose input is two integers, and whose output is the first integer and…
A: Given: ISP-Java Write a program whose input is two integers, and whose output is the first integer…
Q: A two-dimensional random walk simulates the behavior of a particle moving in a grid of points. At…
A: A java program that takes an integer command-line argument “n” and simulates the motion of a random…
Q: hange Java code below so that it outputs a 9x9 board and not a 3x3 board. import java.util.*;…
A: Change Java code below so that it outputs a 9x9 board and not a 3x3 board.
Q: Write a method that returns the smallest element in the array that it takes as a parameter. (In the…
A: Initialize the first element as minimum and then for each element in array, compare and update if…
Q: Define a method in JAVA that prompts the user to enter a floating-point number and then print the…
A: In this question, we are asked to write a java program in such way that user enter a floating number…
Q: The following code is in Java,find the error in the following: int[] table = new int[10]; for…
A: Given the code is in the java we have to find the error in the Following:
Q: Java - public static void test_a(int n) {…
A: Java Sun Microsystems initially introduced Java, a programming language and computing platform, in…
Q: Consider the following Java program, and convert myFunction() method to iterative style (using…
A: public class MyClass{ //recursive method /* //lets first understand what this method does…
Q: HIS IS MEANT TO BE IN JAVA So far we've learned variables, branches, loops, and some array. I was…
A: The given problem is related to java programming where the user will input the price and last…
Q: Show the derivation of the asymptotic run time, O(n), for each of the following methods. You may…
A: Line 3 will be executed 1 time when evenOrOdd() function called at line 13Line 4 will be executed 1…
Q: How do I code: public static int sum(int[] arr) public static int sum(int[] arr, int…
A: Algorithm: for (initialExpression; testExpression; updateExpression){ // body of the…
Q: I need a help in making a method that will Input a text that will be converted to Huffman code and…
A: Above code is right only we changes ; public class Huffman=> we use only…
Q: Here is a Java program to get the sum of a Array of numbers. String[] numbers={"3", "5", "6", "9",…
A: Given code String[] numbers={"3", "5", "6", "9", "10"}; // line 1 int sum=0; // line 2 for (int…
Q: How do you make this code in java, that it adds a point for each question answered or doesn't give a…
A: As per the given question, 3 questions are being asked. If the input to the question from user is…
Q: HIS IS MEANT TO BE IN JAVA So far we've learned variables, branches, loops, and some array. The…
A: The given problem is related to programming where the program is to be implemented in Java language.…
Q: Java - public static void test_b(int n) { if (n>0)…
A: Given Java program is, public static void test_b(int n) { if…
Q: can you check for me why this java code is error
A: There are some errors in the given Java Code. 1. The variable "college" stores a string (non…
Q: IN JAVA Given an array of numbers, return whether it is possible to make the number 7 by adding any…
A: Ask: Determine and write a Java program to validate if sum of 3 numbers in the number Array is 7…
Q: Java - How many recursive calls will be made if the following method is called with 6? void…
A: Java Java is a programming language that is employed by developers to develop apps for mobile…
Q: Write a recursive method called digitCount() that takes a positive integer as a parameter and…
A: According to the Question below the Solution: Output:
There are a few errors in this java code: can you fix it please, its basically a debugging exercise:
public static int sum(int n){
int n;
for (int i=1; i<=n;i--){
sum++;
}
return sum;
}
}
Step by step
Solved in 3 steps with 1 images
- Please help me fix the errors in the java program below import javax.swing.*; import java.awt.event.*; import java.awt.*; public class Halloween extends JFrame implements ActionListener { int hallo[][] = { { 4, 6, 2 }, { 1, 4, 3 }, { 3, 5, 2 }, { 2, 3, 5 }, { 4, 1, 3 } }; int rows = 3; int cols = 5; JButton pics[] = new JButton[rows * cols]; public Halloween() { setSize(600, 600); JPanel grid = new JPanel(new GridLayout(rows, cols)); int m = 0; for (int x = 0; x < rows; x++) { for (int y = 0; y < cols; y++) { pics[m] = new JButton(createImageIcon("back.png")); pics[m].addActionListener(this); pics[m].setActionCommand(m + ""); pics[m].setPreferredSize(new Dimension(100, 100)); grid.add(pics[m]); m++; } } add(grid); setVisible(true); } public void actionPerformed(ActionEvent ae) {}if(e.getActionCommand().equals("Reset")) { for (int m = 0; m…Hi there, I have to write apache kafka in java for 3 consumers. Currently I have code for 1 but i am struggling to make it to 3 consumers. Can anyone change it so that it runs with 3 consumers. consumer.java is as follows import org.apache.kafka.clients.consumer.ConsumerRecord;import org.apache.kafka.clients.consumer.ConsumerRecords;import org.apache.kafka.clients.consumer.KafkaConsumer;import java.time.Instant;import java.util.ArrayList;import java.util.List;import java.util.Properties;import java.time.Instant;public class Consumer {public static void main(String[] args) {Properties properties = new Properties();properties.put("bootstrap.servers", "localhost:9092");properties.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");properties.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");properties.put("group.id", "test-group");KafkaConsumer<String, String> kafkaConsumer = new KafkaConsumer<String,…PLEASE ADD SOME DESIGNS ON MY JAVA PROGRAM, LIKE FONTS, BACKGROUND COLOR ETC. import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; //class declaration public class foodtest extends JFrame implements ActionListener { // declare global variables JCheckBox cbBurger, cbEggs, cbFriedChicken, cbBrownRice, cbIceCream; JLabel lblTitle, lblBurger, lblEggs, lblFriedChicken, lblBrownRice, lblIceCream; JButton b1Calculate, b2Check, b3Reset, b4Cancel; JTextArea t1Output; int burgerCal = 295, eggsCal = 72, friedchickenCal = 260, brownriceCal = 111, icecreamCal = 300; int totalCal = 0; ArrayList<String> foodItems = new ArrayList<String>(); ArrayList<Integer> foodCalories = new ArrayList<Integer>(); // constructor public foodtest() { // set frame properties setTitle("IS YOUR FOOD HEALTHY?"); setSize(630, 520); setLayout(new FlowLayout());…
- Code for Activity2PayStub: // Activity2PayStub.java import java.util.Scanner; public class Activity2PayStub{ // constants public static final double OVERTIME_RATE = 1.5; public static final double SS_WITHHOLDING = .1; public static final double FEDERAL_TAX = .2; // fields private String name, ssn; private int regHours, overHours; private double hourlyRate, regPay, overRate, overPay, grossPay, ssWith, fedTax, netPay; public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); // create an object of Activity2PayStub class Activity2PayStub a2ps = new Activity2PayStub(); // get inputs a2ps.getInput(keyboard); // compute payments a2ps.calculate(); // display information a2ps.printPayStub(); } /** * method that takes inputs of name, ssn, regular hours, overtime hours * and hourly rate and set the fields to the values input by the user */ public void getInput(Scanner keyboard) {…this does not work in Eclipse Java, please you can fix it? please see below: import java.util.Scanner; public class Assig4 { //email using name and last name public static String generateEmail(String fname, String lname) { String email = fname.substring(0, 1).toLowerCase() + "." + lname.toLowerCase() + "@kean.edu"; return email; } //password using first name, security answer and birth year public static String generatePassword(String firstname, String answer, String birthyear) { String password = firstname.substring(0, 3).toUpperCase() + "" + birthyear + "" + answer.substring(0, 3).toUpperCase(); return password; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter first name: "); String firstname = sc.nextLine(); System.out.print("Enter last name: "); String lastname…Java Programming: Below are BooleanCompareNode.java, VariableReferenceNode.java, IfNode.java, RepeatNode.java, & WhileNode.java. Attached is an image where it's circled in blue all the methods that must be implemented in the java files that are presented below: BooleanCompareNode.java public class BooleanCompareNode extends Node {enum CompareType { eq, ne, lt, gt, le, ge }; CompareType type; Node left; Node right; public BooleanCompareNode(CompareType type, Node left, Node right) { this.type = type; this.left = left; this.right = right; } public String ToString() { return left.toString() + type.toString() + right.toString(); } } VariableReferenceNode.java public class VariableReferenceNode extends Node{String name; Node arrayIndex; public VariableReferenceNode(String name) { this.name = name; this.arrayIndex = arrayIndex; } public String ToString() { String indexString = (arrayIndex == null) ? "" : "[" + arrayIndex.toString() + "]"; return name + indexString; } public…
- Can you please check what is wrong with my project. I am trying to do a convolution on the following picture, but the error is connected with bounds. Please correct my code. import javax.imageio.ImageIO;import javax.swing.*;import java.awt.*;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import java.util.Scanner;import java.awt.Color;import java.awt.FlowLayout;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import javax.imageio.ImageIO;import javax.swing.ImageIcon;import javax.swing.JFrame;import javax.swing.JLabel;public class project {public static void main(String[] args) throws IOException {String imagePath = "C:\\Users\\hasib\\Downloads\\11″ TUFTEX BLACK.jpg";int[][] matrix = {{1,0,-1},{2,0,-2},{1,0,-1}}; //edge detectionBufferedImage image = ImageIO.read(new File(imagePath));JFrame frame = new JFrame();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setLayout(new…Question is in images Starter code: import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.text.DecimalFormat; public class GPACalculator extends JFrame{private JLabel gradeL, unitsL, emptyL; private JTextField gradeTF, unitsTF; private JButton addB, gpaB, resetB, exitB; private AddButtonHandler abHandler;private GPAButtonHandler cbHandler;private ResetButtonHandler rbHandler;private ExitButtonHandler ebHandler; private static final int WIDTH = 400;private static final int HEIGHT = 150; private static double totalUnits = 0.0; // total units takenprivate static double gradePoints = 0.0; // total grade points from those unitsprivate static double totalGPA = 0.0; // total GPA (gradePoints / totalUnits) //Constructorpublic GPACalculator(){//Create labelsgradeL = new JLabel("Enter your grade: ", SwingConstants.RIGHT);unitsL = new JLabel("Enter number of units: ", SwingConstants.RIGHT);emptyL = new JLabel("",SwingConstants.RIGHT); //Create text fieldsgradeTF = new…I am not able to get the ID, it jumps straight to GPA, where did i mess up? This is my code : package com.company;import java.util.ArrayList;import java.util.Iterator;import java.util.Scanner;class UniversityPersonnelManagement {public static void main(String[] args) {ArrayList<Student> studentList= new ArrayList<Student>();ArrayList<Faculty> facultyList= new ArrayList<Faculty>();System.out.println("Welcome to my Personal Management Program");for(;;){int input=0;System.out.println(" Choose one of the options:");System.out.println("Add a new Faculty member");System.out.println("Add a new Student");System.out.println("Print tuition invoice for a student");System.out.println("Print information of a faculty");System.out.println("Exit Program");System.out.print(" Enter your selection: ");Scanner s=new Scanner(System.in);try{input=s.nextInt();}catch (Exception e) {System.out.println("Invalid entry- please try again");}if(input==1){Faculty f=new…
- JAVA: is there anything wrong with this my RolePermission class below? I am getting error: Error creating bean with name 'rolePermissionController'below is the class@Entity@Getter@Setter@NoArgsConstructorpublic class RolePermission {@Id@GeneratedValue(strategy = GenerationType.SEQUENCE,generator = "Id")// @Column(name = "id", nullable = false)private Long id;//@ManyToOne(fetch = FetchType.LAZY,cascade = CascadeType.REMOVE)// @ManyToOne@JoinColumn(name = "roleId")@JsonIgnoreprivate Role role;@ManyToOne(fetch = FetchType.LAZY,cascade = CascadeType.REMOVE)// @ManyToOne@JoinColumn(name = "permissionId")// @JoinColumn(name = "permissionId", referencedColumnName = "permission",// insertable = false,updatable = false)@LazyToOne(LazyToOneOption.NO_PROXY)@JsonIgnoreprivate Permission permission;@CreatedDate@CreationTimestamp@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)LocalDateTime createdAt;@LastModifiedDate@UpdateTimestamp@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)LocalDateTime…the following code is centered around data collection, filtering, and using the Singleton pattern in Java, which is all part of a mockup "student information management system", with its purpose being making mockup new student accounts. I've been having issues using the software “dbeaver” for making java projects. Please organize the below code into an executable project “simulation.student” and given step by step instruction as to how this was done Address.java public class Address {private String _city;private String _state;private String _streetName; // Newprivate int _streetNumber; // Newprivate int _apartmentNumber; // New public Address(String city, String state, int zip, String streetName, int streetNumber, int apartmentNumber) {setCity(city);setState(state);setZip(zip);setStreetName(streetName);setStreetNumber(streetNumber);setApartmentNumber(apartmentNumber);} public String getCity() {return _city;} public void setCity(String city) {_city = city;} public String getState()…the following code is centered around data collection, filtering, and using the Singleton pattern in Java, which is all part of a mockup "student information management system", with its purpose being making mockup new student accounts. I've been having issues using the software “dbeaver” for making java projects. Please organize the below code into an executable project “simulation.student” and given step by step instruction as to how this was done Address.java public class Address {private String _city;private String _state;private String _streetName; // Newprivate int _streetNumber; // Newprivate int _apartmentNumber; // New public Address(String city, String state, int zip, String streetName, int streetNumber, int apartmentNumber) {setCity(city);setState(state);setZip(zip);setStreetName(streetName);setStreetNumber(streetNumber);setApartmentNumber(apartmentNumber);} public String getCity() {return _city;} public void setCity(String city) {_city = city;} public String getState()…