1 import java.util.Scanner; 2 import java.util.regex.Matcher; 3 import java.util.regex.Pattern; 4. public class RegexExample { public static void main( String args[] ) { //Regular expression to match a string of non-word with Length 2 to 6 6. 7 8. //Creating a Pattern object 9. 10 //Creating a Matcher object 11 12 13 }
Q: package com.java.runner; import java.io.BufferedReader; import java.io.IOException; import…
A: I have answered this question in step 2.
Q: Write a Java class, XXX_Lab7-3, where XXX is your Kean email ID. In the main method:* Create an…
A: Writing a java Program to create a class name XXX_Lab7-3. In this program there are two arrays, one…
Q: Please implement the Book search(Object e). This method returns the object being search if not found…
A: Here we need to iterate over the ArrayList we have and when we have a matching Book we are going to…
Q: implementation of the Caesar cipher (Section 5.3 in the textbook), which we discussed in class.…
A: Java code for Caesar Cipher import java.util.Scanner; public class CaesarCipher{ public static…
Q: I have a code for an assignment, but the code isn't working please help me. The code of the…
A: The exception shown in the picture occurs when we try to access the file which is not available in…
Q: How do I fix Java? Error: Error ---------- Movie.toString() returns: Movie: [ Minutes 142 | Movie…
A: import java.util.Arrays; public class Movie { private String movieName; private int…
Q: Write a Java program, using object- oriented programming concepts, that allows the user: 1- Enter…
A: Note: Answering the first three subparts as per the guidelines. Input : Input marks of 10 students.…
Q: 1 import java.util.Scanner; 2 3 public class DeclaringVariables { public static void main(String[]…
A: import java.util.Scanner; public class DeclaringVariables { public static void main (String[] args)…
Q: Given a class Square with an instance variable width, provide a recursive getArea method. Construct…
A: public class Main{ public static void main(String[] args) { new Square(5).getArea(); //create…
Q: import java.util.ArrayList; public class BasicArrayList { // main method public static void…
A: As per the requirement program is modified up to a, b and c bits. Note: As per our guidelines we are…
Q: Write a Java class that populates an array of 20 random ints between 0 and 100. Write two methods:…
A: Step 1 : Start Step 2 : Define a method getLargest() which accepts an array and returns the largest…
Q: verseDigits * G DOLoop.java x G SentinelDemo.java X ojects 1 DuplicatedCharacters.java ×…
A: /******************************************************************************…
Q: Write a java application that stores the number of food stocks in a supermarket, particularly, we…
A: We need to create a public class Super Market, we had initialized a static array with the given…
Q: Can someone help me to correct the error of this code so that it is able to run at Jeliot tool?
A: The code in this particular file is correct. Just implement Output.java in jeliot.io correctly. You…
Q: what is the output of the code? Is the code have parallel programming ? Explain in depth about the…
A: Answer: Yes, the given code is parallel programming, this method is suitable for the problem.…
Q: Make a class TestArrayList with a main method: import java.util.*; public class TestArrayList {…
A: Note: The modified code is in bold for your reference. import java.util.*; public class…
Q: import java.util.Scanner; import java.util.HashSet; public class GroceryList { public static void…
A: Program: import java.util.Scanner;import java.util.HashSet;public class Main { public static void…
Q: Explain this java codes thank you import java.io.BufferedReader; import…
A: The question has been answered in step2
Q: What would be the output generated by the following code? public class Main implements Runnable {…
A: start() method causes thread to begin execution, the Java Virtual Machine calls the run method of…
Q: import java.io.*; import java.util.stream.*; public class Solution { static class ListCell {…
A: Merge Sort is a Divide and Conquer algorithm. It divides the input array into two halves, calls…
Q: public class Book implements Comparable { protected int pages; public Book () { pages - 1500; public…
A: Here I have created a class Book that implements the Comparable interface. Inside the class, I have…
Q: package com.java.runner; import java.io.BufferedReader; import java.io.IOException; import…
A: The finally block is used to ensure resources are recovered regardless of any problems that may…
Q: I am not able to get the ID, it jumps straight to GPA, where did i mess up? This is my code :…
A: While entering the record for the student, the buffer for the input needs to be cleared. It can be…
Q: Is there a particular reason why I do not get the right answer after I choose my option? Entering…
A: The list is created to store the students and faculty objects. Loop do-while is used to take input…
Q: What would be the output generated by the following code? public class Main implements Runnable {…
A: Program is given as: public class Main implements Runnable{ String str1, str2; public void…
Q: JAVA PROGRAM (SEE ATTACHED PHOTO FOR THE PROBLEM) What is the output of the program code? Use comma…
A:
Q: What is the output of the following Java code? public class CircularQueue { protected static final…
A: Question. What is the output of the following Java code? public class CircularQueue {…
Q: Java a code give out what is on the image. Essentially write in the main function so that it prints…
A: This program provides information about the total score of the game , according to the points x and…
Q: Covert the Java in to C++ import java.util.*; public class Main { public static void main(String[]…
A: #include <iostream> using namespace std; int main(){ int a, b, c, r; cout << "Enter…
Q: Write a Java method splitName() that takes a string (that contains 1 word or more…
A: Here I have created a function named splitName(). In this function, I have first of all converted…
Q: Many user-created passwords are simple and easy to guess. Program that takes a simple password and…
A: Note: Below is the required java program Programming Approach: Importing necessary package.…
Q: The following attempt at Java code might have been written by a beginner. Identify (but do not…
A: The program mentioned is a Java program made with object oriented approach. It has three classes,…
Q: implementation in Java
A: Introduction Java is a kind of programming language that provides a large number of applications…
Q: Purpose To review threads in Java. Threading Divisors Directions and Example: A divisor is a number…
A: According to the information given:- we have to follow the instruction mentioned and modify the code…
Q: Type the program's output ColorSorter.java Color.java import java.util.Scanner; import…
A: The solution to the given problem is below.
Q: import ADTs.QueueADT; import DataStructures.ArrayStack; import ADTs.StackADT; import…
A: Solution for following question :- 1. Сhаnging Liсense Heаders fоr Рrоjeсt In NetBeаns, right…
Q: Fix the Java code below, make sure it can make the same outputs as the sample: import…
A: Code with Output is given below : NOTE : Code have been modified according to the output given.
Q: What is output? import java.util.ArrayList; public class SimpleCar { @Override public String…
A: Given:
Q: In this problem, you will complete the implementation of the addlast method in a single linked list.…
A:
Q: A Java array is a Java object and can contain a list of objects is a Java object and…
A: Java array is an object which contains elements of a similar data type. Additionally, The elements…
Q: import java.io.*; class Super { void show() { System.out.println("parent"); } } public class Sub…
A: as per Bartleby guidelines we are supposed to answer?️ only one question. Kindly repost other…
Q: JAVA threads confused help 1. A)Consider the Java program. What is the expected logical output? What…
A: Multithreading in java: It is an essential feature of java that performs two or more programs to run…
Q: In this problem, you will model a circuit consisting of an arbitrary configuration of resistors.…
A: Filename: Circuit.java public class Circuit { public double getResistance() { return 0;…
Q: Write a complete java program that will store the weekly sales data for a small shop that sells…
A: Java Program: public class WeeklySalesForShop{ public static void main(String[] args) {…
Q: import java.util.LinkedList; import java.util.Scanner; import java.util.Arrays; import java.io.File;…
A: import java.util.LinkedList;import java.util.Scanner;import java.util.Arrays;import…
Q: please check my JAVA code. One of my test cases is wrong. The question is as stated in the image…
A: One of your test cases didn't execute because the given code is not checking the case where the…
Q: In Java: -Using a BST Interface (Binary Search Tree) -Create a class Disk. Disk contains four…
A: Answer: our instruction is answer the first three part from the first part and . I have done code in…
Q: Implement Tower of honai in Java by using Stack. Towers Disks Smallest Largest The mission is to…
A: Implement TOWER OF HANOI USING JAVA OR STACK implementation
Q: A new deadly virus has infected large population of a planet. A brilliant scientist has discovered a…
A: So as per the question logic for code should be, vaccine count of midichlorains will be higher than…
Q: NameSorter.java Name.java import java.util.Scanner; import java.util.ArrayList; import…
A: code: import java.util.*;public class Main{ public static void main(String[] args) { Scanner scnr =…
Complete the following code. Attach the simulation too.
Step by step
Solved in 2 steps with 1 images
- Beginner Java import java.util.Arrays;import java.util.Scanner; Arrays and scanner required. Suppose that a Scanner object contains a bunch of tokens all on a single line separated by spaces. For example: 100.5 65 pizza 100 45.75 70 5.8 5 Also suppose that you have two integers n and m that are both positive. For example: n = 5 and m = 10 Write a static method: public static double partialSum(Scanner s, int n, int m) that takes a Scanner and two integers n and m as arguments and returns the sum of the integers read by the Scanner that are divisible by n and not divisible by m. In the above example, the integers divisible by 5 and not divisible by 10 are 65 and 5, so the result would be 70. If the Scanner is empty, or no tokens are valid integers, the result should be 0. You can assume the Scanner is not null. It is probably easiest to test your method by creating a Scanner with a String instead of System.in. The starter code for an example of how to do this is…import java.util.Scanner; public class ContactList { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); ContactNode head = null; ContactNode current = null; // Read the name and phone number for three contacts and build a linked list. for (int i = 1; i <= 3; i++) { System.out.print(" " + i + ": "); String name = scnr.next(); System.out.print(" " + i + ": "); String phoneNumber = scnr.next(); ContactNode newContact = new ContactNode(name, phoneNumber); if (head == null) { head = newContact; current = head; } else { current.insertAfter(newContact); current = newContact; } } // Output each contact. current = head; for (int i = 1; current != null; i++) { System.out.print("Person " + i + ": "); current.printContactNode();…import java.util.Random; class Main { public static void main(String[] args) { Random rand = new Random(); int a = new int[100]; for (int i = 0; i < 100; i++) { a[i] = rand.nextInt(100); } print(a); System.out.println("---"); quicksort(a, 0, a.length - 1); print(a); } public static void print(int[] a) { for (int x : a) { System.out.println(x); } } public static void swap(int[] a, int p1, int p2) { int temp = a[p1]; a[p1] = a[p2]; a[p2] = temp; } public static int partition(int[] a, int left, int right) { int pivot = right; int p1 = left; int p2 = pivot - 1; while (p2 >= p1) { if (a[p1] > a[pivot]) { swap(a, p1, p2); swap(a, p2, pivot); p2 = pivot - 1; } else { p1++; } } return pivot; } public static void quicksort(int[] a, int left, int right) { if (left < right) { int p = partition(a, left, right); quicksort(a, left, p - 1);…
- import java.util.Scanner; public class PetInformation {public static void main(String[] args) {Scanner scnr = new Scanner(System.in); Pet myPet = new Pet(); Cat myCat = new Cat(); String petName, catName, catBreed; int petAge, catAge; petName = scnr.nextLine(); petAge = scnr.nextInt(); scnr.nextLine(); catName = scnr.nextLine(); catAge = scnr.nextInt(); scnr.nextLine(); catBreed = scnr.nextLine(); // Create generic pet (using petName, petAge) and then call printInfo myPet.setName(petName); myPet.setAge(petAge); myPet.printInfo(); // Create cat pet (using catName, catAge, catBreed) and then call printInfo myCat.setName(catName); myCat.setAge(catAge); myCat.setBreed(catBreed); myCat.printInfo(); // Use getBreed(), to output the breed of the cat System.out.println(" Breed: " + myCat.getBreed());}}Please sort out the following JAVA code....line by line. Run the code in Netbeans and provide screenshots to verify that it runs successfully. CODE: import java.io.*; import java.util.*; public class experiment { public static void main(String args[]) { Scanner in=new Scanner(System.in); int time[]=new int[10]; float weight[]=new float[10]; String get; char ch; int i=0; do{ try { System.out.print("\nEnter the time in seconds:"); time[i]=in.nextInt(); System.out.print("\nEnter the weight in kilograms:"); weight[i]=in.nextFloat(); i++; } catch(Exception e) { System.out.print("\nInvalid type"); } System.out.print("\n-----------------"); System.out.print("\n|Time\t|Weight\t|"); System.out.print("\n-----------------"); for(int x=0;x<i;x++) { System.out.print("\n|"+time[x]+"\t|"+weight[x]+"\t|"); System.out.print("\n-----------------"); } if(i==10) { for(int x=0;x<9;x++) { time[x]=time[x+1]; weight[x]=weight[x+1]; } i--; } System.out.print("\nDo you want to continue?(y/n) ");…import java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int n = scnr.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = scnr.nextInt(); } for (int i = n - 1; i >= 0; i--) { System.out.print(arr[i]); if (i > 0) { System.out.print(","); } } }}
- Write a client program that loops around getting two fractions from the user,output their sum, and state whether or not they are equal. Keep looping until the first fraction entered is a zero fraction. import java.util.ArrayList;import java.util.Scanner; //Define the class Fractionclass Fraction{private int n, d;public Fraction(){//Initialize the valuesthis.n = this.d = 0;}public Fraction(int n, int d){//Initialize the variablesthis.n = n;this.d = d;}//Define the getter function getNum() that returns the numeratorpublic int getNum(){//Returns numeratorreturn n;}//Define the getter function getDen() that returns the denominatorpublic int getDen(){//Returns denominatorreturn d;}//Define the boolean function isZero() that returns 0 if numerator is 0 and denominator is not equals to zeropublic boolean isZero(){return(getNum() == 0 && getDen() != 0);}public boolean isequals(Object c){Fraction f = (Fraction) c;return(Integer.compare(n,f.n))==0 &&…Java Program Fix this Rock, Paper and scissor program so I can upload it to Hypergrade and it can pass all the test cases. Here is the program: import java.util.Random;import java.util.Scanner;public class RockPaperScissors { public static void main(String[] args) { if (args.length != 1) { System.out.println("Please provide a seed as a command line argument."); return; } long seed = Long.parseLong(args[0]); Random random = new Random(seed); Scanner scanner = new Scanner(System.in); System.out.println("Enter 1 for rock, 2 for paper, and 3 for scissors."); do { int computerChoice = random.nextInt(3); int userChoice = getUserChoice(scanner); if (userChoice == -1) { continue; } System.out.println("Your choice: " + choiceToString(userChoice) + ". Computer choice: " + choiceToString(computerChoice) + "."); int result =…Fix the Java code below, make sure it can make the same outputs as the sample: import java.util.ArrayList;import java.util.Scanner; class Main{ //Returns index of name if found otherwise -1 public static int findName(ArrayList<String> arr, String name) { for(int i = 0; i < arr.size(); i++) if(arr.get(i).equals(name)) return i; return -1;//Name not found } //Deletes a name from ArrayList public static void deleteName(ArrayList<String> arr, String name) { int index = findName(arr, name);//Get index of name to be deleted for(int i = index; i < arr.size() - 1; i++){ arr.set(i, arr.get(i + 1)); } arr.remove(arr.size() - 1);//Remove last element } public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.print("Enter number of students(upto 10): "); int n = scan.nextInt(); ArrayList<String> arr = new…
- I need help with fixing this java program as described in the image below: LablProgram.java: import java.util.Scanner; public class LabProgram { /* TODO: Write recursive printLinkedList() method here. */ public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int size; int value; size = scnr.nextInt(); value = scnr.nextInt(); IntNode headNode = new IntNode(value); // Make head node as the first node IntNode lastNode = headNode; // Node to add after IntNode newNode = null; // Node to create // Insert the second and the rest of the nodes for (int n = 0; n < size - 1; ++n) { value = scnr.nextInt(); newNode = new IntNode(value); lastNode.insertAfter(newNode); lastNode = newNode; } // Call printLinkedList() with the head node printLinkedList(headNode); }} intNode.java: public class IntNode { int dataVal; private…JAVA Implement the equals method of the Arrow class. Two arrows are equal when they have the same starting point and direction. public class Arrow{ private Point start; private String direction; /** Constructs an arrow. @param x the x-position @param y the y-position @param direction a compass direction N E S W NE NW SE SW */ public Arrow(int x, int y, String direction) { start = new Point(); start.move(x, y); this.direction = direction; } /** Checks whether this arrow is equal to another. @param otherObject another arrow @return true if this arrow and otherObject have the same position and direction. */ public boolean equals(Object otherObject) { /* code goes here */ }}WRITE THE BODY OF Java program - THE checkWinner METHOD BELOW SO THAT THE GAME STOPS WHEN SOMEONE WINS, OR WHEN THE BOARD IS FULL. AS SHOWN IN THE SAMPLE OUTPUT AT THE BOTTOM. Code: import java.util.Scanner; public class TicTacBoard { private char[][] board; // 2-D array of characters private char curPlayer; // the player whose turn it is (X or O) // Constructor: board will be size x size public TicTacBoard(int size) { board = new char[size][size]; // initialize the board with all spaces: for(int row=0; row < board.length; row++) for(int col=0; col < board[row].length; col++) board[row][col] = ' '; curPlayer = 'X'; // X gets the first move } public void playGame() { display(); do { takeTurn(); display(); }while(!checkWinner()); } /////// display //////// // Display the current status of the board on the // screen, using hyphens (-) for horizontal lines // and pipes (|) for vertical lines. public void…