Write an expression to detect that the first character of userlnput matches firstLetter. 1 import java.util.Scanner; 2 3 public class CharMatching { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); String userInput; char firstLetter; 4 5 7 8 = scnr.nextLine(); scnr.nextline().charAt(0); 9. userInput firstLetter 10 11 if (/* Your solution goes here */) { System.out.println("Found match: } else { System.out.println("No match: } 12 13 + firstLetter); 14 15 + firstLetter); %3D 16 17 18
Q: Consider public class MyClass { public MyClass(){/code/} // more code… } To instantiate MyClass, you…
A: Given Code: public class MyClass { public MyClass() { /code/ } // more code… } Answer: MyClass mc =…
Q: How do I check the case when the user enters an index that is negative, or lastindex > firstindex…
A: A java code is given. We need to update the code and remove the error. And provide the output .
Q: Consider the class Point2D2310 below that represents a point in a 2 dimensional environment.…
A: The changes in Point2D2310 is highlighted Point2D2310.java public class Point2D2310 { private int…
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: ... 9. Write a method that checks whether all elements in the indicated column are the same.…
A: Programming instructions: Initialize the matrix with strings. Take input from the user for the…
Q: Write a complete Java class that can be used to create a Hamster object as described below: A…
A: The solution for the above given question is given below:
Q: 1mport java.uti. Scanner; public class ballons { static void getLength() {…
A: Main output of this code is to find number of balloons you need to fill with volume of room.…
Q: "Perimeter of Regular Polygon: ", y) n = int(input("Enter the value of n: ")) s = int(input("Enter…
A: GIVEN: Write a Phyton program that will implement try, except, and finally in the sample class given…
Q: For the TimeSpan class described below, add a compareTo method that takes another TimeSpan object as…
A: Please find the answer below :
Q: Write the JAVA method for the following a): Window to View Conversion using equations: x_v=…
A: Code: public class Temp { static void windowToView(int xwmin, int ywmin, int xwmax, int ywmax,…
Q: Consider the class shown in the image below. D "Student java 13 1. 2 public class Student ( private…
A: A class is a group of objects which have common properties. A constructor is a method that is used…
Q: How to answer the following question in java The equals method for Circle objects defined in the…
A: QUESTION 1 : The equals method for Circle objects defined in the text determines equality of two…
Q: Consider the Java program shown here: class NumberTest { public static void main(String[] args)…
A: Q: Output of the given program
Q: in the last line of to string there is error can you solve it package log; import…
A: In function toString() of your program the problem is in quotations that you have inserted. Refer to…
Q: help me run this code import java.util.*; class Main{ static int max_kids; HashMap > sports ;…
A: Given: To run the given code without error.
Q: Write code for a Java class Rectangle with the following fields and methods: Rectangle - width :…
A: /** File: Rectangle.java** Summary of file:* * This file contains the Rectangle class* with all the…
Q: public class StringArrayManipulation { public static double getSum(String[][] data) {…
A: The code is given below.
Q: How do I make sure that numCastMembers expected: 0 in the overloaded parameterized constructor in…
A: import java.util.*;public class Movie { private String movieName;private int numMinutes;private…
Q: Write a program that computes the power of an integer ax where the base is a and the exponent is x,…
A: According to the question below the Complete Program: Java Output:
Q: Write a Java program that implements the following classes: 1. The following class Menu which…
A: the code is an given below : \41 answers Answer: import java.util.*; class Menu{ private String[]…
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: 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: Consider the following code in Java 8: public interface Runnable { void run() ; } public final class…
A: Here we have an interface named Runnable with one abstract method named run, hence we can say that…
Q: public class Test { public void Run() { int a, b ,c; a = 2, b = 10, c = 1; for (int i = 0; i < 2;…
A: Find the answer below.
Q: Write a method swapArrayEnds() that swaps the first and last elements of its array parameter. Ex:…
A: Program: //import the required header file import java.util.Scanner; //definition of class public…
Q: *in java* Complete method printPopcornTime(), with int parameter bagOunces, and void return type.…
A: import java.util.Scanner; public class PopcornTimer {public static void printPopcornTime(int…
Q: We have a main class that implements a parking charge class of a parking management system. We…
A: Here I have first of all created different files for each of the classes defined and pasted the…
Q: What is the output of the following program? public class Ouput { public static void main(String[)…
A: public class Output{ public static void main(String[] args) { A for(int j = 0 , k = 0 ; j < 3;…
Q: Write a unit test for addInventory(), which has an error. Call redSweater.addInventory() with…
A: Program code: // Header files #include <iostream> //std using namespace std; // Define…
Q: create a public static method named manipulateString that asks the user for a sentence using the…
A: Iterate over the array of words and then we have to update the case on original array and then we…
Q: Write a program that prompts the user to enter a positive integer which is greater than one and…
A: Let us consider a Java program that prompts the user to enter a positive integer and displays all…
Q: import java.at."; import javax. swing."; public class RectangleMonday etends JFrame{ public…
A: Introduction of Program: The java program uses the concept of JFrame and it provides a window on the…
Q: Help me run this code import java.util.*; class Main{ static int max_kids; HashMap > sports ;…
A: Source code:- import java.util.*;class Main{ static int max_Students;…
Q: How do I check the case when the user enters an index that is negative, or lastindex > firstindex…
A: import java.util.Scanner; public class Grades { public static int sum(int[] arr) { int…
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: A java program, with a class Rectangle with attributes length and width , each of which defaults to…
A: Program: File name: “Rectangle.java” import java.text.DecimalFormat; public class Rectangle {…
Q: 6.21 LAB: Remove all non alpha characters Write a program that removes all non alpha characters from…
A: Mistakes in your code: 1. You have used next() to read string. It will not read string after space.…
Q: Need help writing the method: getWaitlistedIDs() – returns an array of type int[], namely the ids of…
A: Note: In this question we are asked to modified getWaitlistedIDs method only in java There is a…
Q: Based on the java source code given , how can i add a simple payment system in the code. Please…
A: Errros
Q: WSP 1: Test program (2)
A: I've corrected the Java code as per the question requirement.…
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: Consider the following method. /** Postcondition: m is displayed in a rectangular matrix for…
A: yes,all numbers will correctly display rectangular manner. ex: import java.util.*; class arr13{…
Q: animated house. import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import…
A: void drawEmptyBoard(Graphics g) { int x=x_offset, y=y_offset; Color old_col=g.getColor();…
Q: Create a method public static String[] mergeArrays(String[] arr1, String[] arr2)…
A: I have given an answer in step 2.
Q: Write a client program that allows the user to add up any number of non-zero fractions. The program…
A: An object of the class Fraction is made as f_s with value as fractions.get(0). Another object of the…
Q: debug this: Debugging Exercise 4-3, Farrell, Joyce, Java Programming, 9th edition, Cengage Learning…
A: A program after debugging is as follows, Note: A complete program is written below to test class…
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: Use Netbeans to run the following decorator pattern code. Provide screenshot to prove that the code…
A: The given program cannot be executed as it does not contain the "main()" method like "public static…
Q: To perform a series of computational experiments, create a data type PercolationStats with the…
A: First Import JAR files after running the following code. Java Source Code: PercolationStats.java:…
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images
- 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 &&…Write a program that prints all digits of any integer in reverse order. import java.util.Scanner;public class ReverseDigits{ public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); // TODO: Print the digits of n in reverse /* Your code goes here */ System.out.print(""); if (n < 0) { /* Your code goes here */ n = n*-1; //Convert number to a positive value System.out.print(" -"); //Print negative } else if (n == 0) { /* Your code goes here */ System.out.println("0"); return; } int reverseNumber = 0; while (n != 0) { int digit = n % 10; //extracting the last digit from n reverseNumber = reverseNumber*10 + digit; // printing the digit n = n / 10; //updating n by removing the last digit }…Write a program that prints all digits of a positive integer in reverse order. import java.util.Scanner;public class ReverseDigits{ public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); // TODO: Print the digits of n in reverse while (/* Your code goes here */) { /* Your code goes here */ System.out.print(digit); /* Your code goes here */ } System.out.println(); }}
- 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);…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 =…Write a client program that allows the user to add up any number of non-zero fractions. The program should display the running total as an exact fraction (in simplified form as numerator / denominator), and as an approximate double value. The user can finish by entering a fraction that represents 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…
- Write a method swapArrayEnds() that swaps the first and last elements of its array parameter. Ex: sortArray = {10, 20, 30, 40} becomes {40, 20, 30, 10}. import java.util.Scanner; public class ModifyArray { /* Your solution goes here */ public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int numElem = 4; int[] sortArray = new int[numElem]; int i; int userNum; for (i = 0; i < sortArray.length; ++i) { sortArray[i] = scnr.nextInt();} swapArrayEnds(sortArray); for (i = 0; i < sortArray.length; ++i) { System.out.print(sortArray[i]); System.out.print(" ");} System.out.println("");}}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(","); } } }}Please help debug this: Debugging Exercise 4-3, Farrell, Joyce, Java Programming, 9th edition, Cengage Learning public class DebugBox { private int width; private int length; private int height; private FixDebugBox() { length = 1; width = 1; height = 1; } public DebugBox(int width, int length, int height) { width = width; length = length; height = height; } public void showData() { System.out.println("Width: " + width + " Length: " + length + " Height: " + height); } public double getVolume() { double vol = length - width - height; return vol; } }
- 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…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) ");…Continuing from the example, modify the program so that it outputs the average grade in each course, and also shows which course has the highest average grade. import java.util.Scanner; public class Main { publicstaticvoid main(String[] args) { Scanner s = new Scanner(System.in); int numCourses, numTests; double[][] testScores; System.out.print("How many courses are you taking? "); numCourses = s.nextInt(); testScores = new double[numCourses][]; // allocate an array of references to 1-D arrays (rows) for(int i = 0; i < numCourses; i++) { System.out.print("How many tests are in course number " + (i+1) + "? "); numTests = s.nextInt(); // allocate this row: a 1-D array of doubles: testScores[i] = new double[numTests]; } for(int courseId=0; courseId < testScores.length; courseId++) { for(int testId=0; testId < testScores[courseId].length; testId++) { System.out.print("What was your grade on test " + (testId+1) + " for course " + (courseId+1) + "? ");…