What’s wrong/could be wrong with this code: public Stream GetItems(double minPrice) { synchronized(this) { return _inventory.stream().filter(item -> item.Price >= minPrice); } }
I don't have full, it is code given in interview.
synchronized(this) -- this line will be giving an error because we cant use the this keyword here and we need to provide a sync_object here so while execution it will give error.
What’s wrong/could be wrong with this code: public Stream GetItems(double minPrice) { synchronized(this) { return _inventory.stream().filter(item...
Provided code Animal.java:
public class Animal
{
private String type;
private double age;
public Animal(String aT, double anA)
{
this.type = aT;
if(anA >= 0)
{
this.age =
anA;
}
}
public String getType()
{
return this.type;
}
public double getAge()
{
return this.age;
}
}
Provided code Zoo.java:
public class Zoo {...
java code ========= public class BankAccount { private String accountID; private double balance; /** Constructs a bank account with a zero balance @param accountID - ID of the Account */ public BankAccount(String accountID) { balance = 0; this.accountID = accountID; } /** Constructs a bank account with a given balance @param initialBalance the initial balance @param accountID - ID of the Account */ public BankAccount(double initialBalance, String accountID) { this.accountID = accountID; balance = initialBalance; } /** * Returns the...
help with java OOP, here is the started code:
package P2;
public class Farm {
private double availableFood;
private Animal[] animals;
public Farm() {
setAvailableFood(1000);
animals = new Animal[4];
animals[0] = new Chicken();
animals[1] = new Cow();
animals[2] = new Llama();
animals[3] = new Llama();
}
public void makeNoise(){
// all animals make their
sound (Moo, Cluck, etc)
for(Animal...
import java.util.Scanner; public class TempConvert { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); //ask the user for a temperature System.out.println("Enter a temperature:"); double temp = scnr.nextDouble(); //ask the user for the scale of the temperature System.out.println("Is that Fahrenheit (F) or Celsius (C)?"); char choice = scnr.next().charAt(0); if(choice == 'F') { //convert to Celsius if given temperature was Fahrenheit System.out.println(temp + " degrees Fahrenheit is " + ((5.0/9) * (temp-32)) + " degrees Celsius"); } else {...
Code in c++ please fix all errors that’s being asked to find and please follow instructions ------------------------------------------------- // This is example code from Chapter 6.7 "Trying the second version" of // "Software - Principles and Practice using C++" by Bjarne Stroustrup // /* This file is known as calculator02buggy.cpp I have inserted 5 errors that should cause this not to compile I have inserted 3 logic errors that should cause the program to give wrong results First try to find...
Java Programming: The following is my code: public class KWSingleLinkedList<E> { public void setSize(int size) { this.size = size; } /** Reference to list head. */ private Node<E> head = null; /** The number of items in the list */ private int size = 0; /** Add an item to the front of the list. @param item The item to be added */ public void addFirst(E...
starter code
To write a program using the starter code which is
TestLinkedList to see if the LinkedList program has bugs. It will
produce ether a pass or fail.More information is in the first two
pictures.
LinkedList.java
/**
* @author someone
*
* Implements a double-linked list with four errors
*/
public class LinkedList<E>
{
// The first and last nodes in the list
private Node<E> head, tail;
// Number of items stored in the list
private int size;
//...
what is wrong with the following code? public class EightBall { private static Scanner scanner = new Scanner(System.in); private static Random rnd = new Random(); public static String getAnswer(int category, int answer) { if (category >= 74) { if (answer == 0) { return "As I see it, yes." ; } else if (answer == 1) { return "Signs point to yes." ; } else if (answer == 2) { return "Outlook good." ; } else if...
public static int[] collatz(int start, int numIterations) Given integer start and integer numIterations, return an array containing the Collatz sequence beginning with start up to numIterations. The Collatz function is defined by: 3n + 1 if n is odd n/2 if n is even Given start = 7 and numIterations = 3, this method returns [7, 22, 11, 34] TESTING: collatz(7,3) should return {7, 22, 11, 34} collatz(6,0) should return {6} collatz(6, 5) should return {6, 3, 10, 5, 16,...
Develop a Generic String List (GSL). NOTE: I have done this lab but someting is wrong here is what i was told that was needed. Ill provide my code at the very end. Here is what is missing : Here is my code: public class GSL { private String arr[]; private int size; public GSL() { arr = new String[10]; size = 0; } public int size() { return size; } public void add(String value) { ...