What will be the output of the program? Cour class MyThread extends Thread { public static void main(String [] args) { MyThread t = new MyThread (); /* Line 5 */ t.run(); /* Line 6 */ } public void run() { for (int i=1; i < 3; ++i) { System.out.print(i + ".."); } red
Q: What would be the output generated by the following code? import java.util.concurrent.*; public…
A: Answer: Elements: {1=Welcome, 2=to, 3=Java, 4=World}Elements after key 2 is removed: {1=Welcome,…
Q: Write a class MyArrayQueue that Inherit the ArrayBoundedQueue class show in screen shot and such…
A: public class MyArrayQueue<T> implements ArrayBoundedQueue<T>{ private final int…
Q: Roni and Rajesh love to play a rope-based game. The game is as follows. At first, Tracy writes a…
A: Algorithm: First input contains a single integer T, the number of test cases. Then the second line…
Q: Suppose we built a hash table for strings where the hash value (number) associated to each string is…
A: Hashing is a technique that uses a hash table for storing the values in an indexed manner. The hash…
Q: Write a Java Program to do the following: • Create a LinkedList object and store 5 different Integer…
A: It is defined as a programming language and a platform. Java is a high level, robust,…
Q: Consider the BadReaderWriter.java program attached with this homework. The program has three…
A: According to the infromation given:- we have to BadReaderWriter.java. It had 3 threads (reader,…
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: What would be the output generated by the following code? import java.util.concurrent.*; public…
A: Java.util.concurrent.ConcurrentHashMap.putIfAbsent(): In java this is an in- built function to…
Q: What would be the output of the following program: public class StackTest { public static void…
A: Content for First Stack 4, 6, 8,10
Q: Consider a hash table to size 10. Write a program to insert the following keys 27, 6, 9, 32, 82, 12…
A: //C++ program to insert the following keys 27, 6, 9, 32, 82, 12 and 56 into has table and then…
Q: A thread with priority 30 is active. What if it exhausted its whole time quantum? b) Is it…
A: Once a thread is selected to run, it runs for a period called the quantum.
Q: PSEUDOCODE FOR THIS CODING package disktower; import java.util.*; class MyComparator…
A: It is defined as a term which is often used in programming and algorithm based fields. It is a…
Q: what is the correct formula for the load factor?
A: The load factor is the proportion of the array's size to the number of entries in the hash table.…
Q: In c++ if possible i have tried everything i can quite get it: Write a thread-safe logger…
A: We need a local buffer to collect message before sending to the log file. In the example below,…
Q: If you wanted to find if a particular number was present in an array of one million integers, which…
A: Given: If you wanted to find if a particular number was present in an array of one million integers,…
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: Write a Java program that creates a new thread called PrintEven, that prints the Odd numbers petween…
A: Thread allows a program to operate more efficiently by doing multiple things at the same time.…
Q: fork-join threading
A: Code: import java.util.Arrays;import java.util.concurrent.ForkJoinPool;import…
Q: Implement a class that checks whether a given number is a prime number or not using both the Thread…
A: The solution code for the above given problem has been provided below - For both of the solutions…
Q: Exercise 3: 1) Read the following code and try to guess what will be its output. import java.util.":…
A: 1) Code: import java.util.*;class Car{private int speed;//declaring private variablepublic void…
Q: Write a program in Java to implement a Singly linked list with two fields: String name and Integer…
A: Creating a Node Class. Inside the Node class declare fields for linked list. Take constructor for…
Q: What is the safe sequence? [Note, try to exexute the threads sequentitally that is T0, then T1 and…
A: Given: What is the safe sequence? [Note, try to exexute the threads sequentitally that is T0, then…
Q: what would be the output generated by the following code? import java.util.concurrent. *; public…
A: To find the output of the given code. The given code is: import java.util.concurrent. *; public…
Q: Write a C++ Program to implement a hash table with chaining that does the following: The hash…
A: Introduction of Hash Table: In the above question bucket size is 9 so the hash table uses the…
Q: Trace through the state of the queue q in the following code fragment in the main method. You need…
A: Given question tracing through the state of the queue q in the given code fragment in the main…
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: 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: You are asked to take as input a list of integers that went through several reverse operations, and…
A: Solution: Solution is Implemented in Java. I implemented the solution using file input/ output. I…
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: please i just need screen shot for output
A: The code has the following error.
Q: Define a class MyData that holds an instance variable x, a function to increment x by 5, and a…
A: NOTE: - ISSUE is discussed in step 4. Different Classes Description: - MyData class comprises one…
Q: In JAVA can a dead thread be started again?
A: In java, a thread which is in dead state can’t be started again. There is no way to restart a dead…
Q: What would be the output generated by the following code? public class Main implements Runnable…
A: public class Main implements Runnable //extends class{ String str1, str2; // string type…
Q: Write a java program that reads ten numbers into a linked list and prints them then displaying the…
A: Actually, java is a object oriented programming language. It is a platform independent.
Q: What is the output of the following Java program? Explain. class s1 extends Thread { public void…
A: Given : What is the output of the following Java program? Explain.class s1 extends Thread{public…
Q: Write a MultiThreaded ServerSocket Program in C# that can handle multiple clients at the same time.…
A: Given: Write a MultiThreaded ServerSocket Program in C# that can handle multiple clients at the same…
Q: FOR JAVA WRITE A CLASS BY EXTENDING THREAD AND PRINT OUT THE ODD NUMBERS FROM 1 TILL N
A: ALGORITHM:- 1. Create a class extending the Thread class. 2. Take the value of N as input from the…
Q: Implement a program which gets the thread number and add it to a tsum variable. int tsum=0; #pragma…
A: Here is the detailed explanation of the program
Q: Using a ListItreator output the contents of the LinkedList in the original order. Using a…
A: import java.Security.SecureRandom; import java.util.*; public class Tester{ public static void…
Q: Write a Java Program to do the following: • Create an LinkedList object and store 5 different…
A: Please find the answer below :
Q: Write a multi-threading JAVA program having four threads: - The “Generator” thread: it takes as…
A: we have to write a java thread program Write a multi-threading JAVA program having four threads:-…
Q: Consider the following double linked list, where the next pointer points to the next node and the…
A: Program Plan: Define deleteNodeAtGivenPos() that deletes the node of a doubly linked list at the…
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: ssume there are two public phone booths in your area. Each person is allotted a fixed time of 1000…
A: import java.util.LinkedList; public class Threadexample { public static void main(String[] args)…
Q: Implement, using only the Queue kernel methods, the static method declared as follows and answer the…
A: Answering for the first question Kernel method : In AI, kernel strategies are a class of…
Q: Write a Java program that creates a new thread called PrintEven, that prints the Even numbers…
A: GIVEN: Create a java program that creates a new thread PrintEven to print the even numbers between 1…
Q: We know that java generics cannot prevent runtime error. Then, how can we avoid runtime error while…
A: Java generics allows to create a single class, interface and method that can be used with different…
Q: What exactly do you mean when you say "thread salvation"?
A: Introduction: In order to do two or more tasks at the same time, threads are employed.
Q: Write a Console Java program that inserts 25 random integers in the range of 0 to 100 into a Linked…
A: As you have not provide the sample output, so we have given the output in Step 4 in the most…
This is a java program question don't copy from the internet please and write correctly
Step by step
Solved in 2 steps with 1 images
- 1 public class PSP6 { public static void main(String[] args) { System.out.println(finalCarPrice (1)); System.out.println(finalCarPrice (2)); System.out.println(finalCarPrice (3)); } 2 // should print out 33550.0 // should print out 44550.0 // should print out 66550.0 3 4 6. 7 8. /* 9. Task 1: Complete finalCarPrice method to calculate the price of a $30K car 10 The option is an int input argument (assume it will always be 1, 2, or 3): 11 - Option 1 is for entertainment package add-on which cost $500 Option 2 includes option 1 and self-driving package for an additional $10K Option 3 includes option 2 with 3 years warrantly for an addition of $20K 13 14 Calculate the final price of the car with tax. We assume tax is another addition of 10% of the sale price. 15 16 17 */ public static double finalCarPrice(int option){ 18 19 20 21 22 23 24 double basePrice // base price of a car is $30K 30000.0; double finalPrice = 0.0; %3D // Complete task 1 here to update the final price using if else…$ubject Name: Advanced Object-Oriented Programming • Complete the below given program class Thread1 extends Threads { class Thread2 extends Thread { private String text; public Thread1(String n,String text) { super(n); this.text-text;} public void run(){ try{ for(int i=1;i0; i--) { System.out.println("Num "+i); try { sleep(1000); } catch(Exception e)(System.out.println("Thread Interrupted");} public static void main (String[] args) { MyThread th = new MyThread("Jack"); th.start();Code example 2-1import java.util.Scanner;public class InvoiceApp {public static void main(String[] args) {Scanner sc = new Scanner(System.in);String choice = “y”;While (choice.equals(“y”)) {System.out.print("Enter subtotal: ");double subtotal = sc.nextDouble();double salesTax = subtotal * .0875;double invoiceTotal = subtotal + salesTax;String message = “Subtotal = ” + subtotal + “\n”+ “ Sales tax = ” + salesTax + “\n”+ “Invoice total = ” + invoiceTotal + “\n\n”System.out.println(message);System.out.print(“Continue? Enter y or n: ”);Choice = sc.next();}}}38. (Refer to code example 2-1.) If the user enters “Y” when asked if he/she wants to continue, the application will a. repeat the while loop b. display a blank line, then repeat the while loop c. End
- Code example 2-1import java.util.Scanner;public class InvoiceApp {public static void main(String[] args) {Scanner sc = new Scanner(System.in);String choice = “y”;While (choice.equals(“y”)) {System.out.print("Enter subtotal: ");double subtotal = sc.nextDouble();double salesTax = subtotal * .0875;double invoiceTotal = subtotal + salesTax;String message = “Subtotal = ” + subtotal + “\n”+ “ Sales tax = ” + salesTax + “\n”+ “Invoice total = ” + invoiceTotal + “\n\n”System.out.println(message);System.out.print(“Continue? Enter y or n: ”);Choice = sc.next();}}} (Refer to code example 2-1.) If the user enters 100 the first time the while loop is executed, what will the program display at the console? a. Subtotal: 100.0 Sales tax: 8.75 Invoice total: 108.75 b. Subtotal = 100.0 Sales tax = 8.75 Invoice total = 108.75 c. Subtotal = 100.0 Sales tax = 8.75Invoice total = 108.75 d. Subtotal = 100.0 Sales tax = 8.75Invoice total = 108.75class MyAbstract { public int doNothing() { System.out.print("abc"); } } } public class Main extends MyAbstract { public static void main(String args[]) { MyAbstract a = new MyAbstract(); doNothing (a.doNothing()); } public static void doNothing (int dummy) { System.out.print("xyz"); } return 1; O None of the other options abcxyz O xyzabc O abcComplete the isExact Reverse() method in Reverse.java as follows: The method takes two Strings x and y as parameters and returns a boolean. The method determines if the String x is the exact reverse of the String y. If x is the exact reverse of y, the method returns true, otherwise, the method returns false. Other than uncommenting the code, do not modify the main method in Reverse.java. Sample runs provided below. Argument String x "ba" "desserts" "apple" "regal" "war" "pal" Argument String y "stressed" "apple" "lager" "raw" "slap" Return Value false true false true true false
- 1- class Excep { 2- public static void main(String[] args){ 3 try{ int arr[]=(1,2}; 4 int x = arr[1]/arr[0]-1; 6 7 catch(ArithmeticException e) 8- { 9. System.out.printin("divide by e"); 10 } 11 catch(ArrayIndexOutofBoundsException e) 12- { 13 System.out.println("wrong indexing"); 14 15 finally 16- { 17 System.out.println("Runtime error"); 18 } 19 }} 20 Answer:public class main { public static void main(String [] args) { Dog dog1=new Dog(“Spark”,2),dog2=new Dog(“Sammy”,3); swap(dog1, dog2); System.out.println(“dog1 is ”+ dog1); System.out.println(“dog2 is ”+ dog2); } public static void swap(Dog a, Dog b) { String nameA = a.getName(); String nameB = b.getName(); a.setName(nameB); b.setName(nameA); } What is the output of the main()?public static void main(String[] args) throws IOException{ BufferedReader b=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Input instructor Salary: "); double salary=Double.parseDouble(b.readLine()); System.out.print("Input Academic Rank: "); String rank=b.readLine(); double tax=0; if(rank.equalsIgnoreCase("Assistant")) tax=salary*9/100; else if(rank.equalsIgnoreCase("Associate")) tax=salary*12/100; else if(rank.equalsIgnoreCase("Lecturer")) tax=salary*7/100; double net_salary=salary-tax; System.out.println("\nThe amount of Tax is BD "+tax); System.out.println("The Net Salary is BD "+net_salary); } }
- main Application public class Application { public static void main(String[] args) {//Create library objectLibrary l = new Library();//Add booksl.add(new Kids("KidsBook1", "author1", 18, 5));l.add(new Kids("KidsBook2", "author2", 15, 7));l.add(new Kids("KidsBook3", "author3", 10, 9));l.add(new Scientific("ScientificBook1", "author1", 12));l.add(new Scientific("ScientificBook2", "author2", 13));//Borrower objectsBorrower b1 = new Borrower("Borrower1", 1, 10, 2);Borrower b2 = new Borrower("Borrower2", 2, 6, 5);//Borrower1 borrow 2 booksif (b1.getMaxBookNum() <= b1.getSerialNumbers().size()) {System.out.println("Reached maximum borrowings!!!");} else {if (l.borrow(18, b1)) {b1.borrow(18);}}if (b1.getMaxBookNum() <= b1.getSerialNumbers().size()) {System.out.println("Reached maximum borrowings!!!");} else {if (l.borrow(15, b1)) {b1.borrow(15);}}//Borrower2 borrow 1 bookif (b2.getMaxBookNum() <= b2.getSerialNumbers().size()) {System.out.println("Reached maximum borrowings!!!");}…public class Test { } public static void main(String[] args) { String str = "Salom"; System.out.println(str.indexOf('t)); }StringFun.java import java.util.Scanner; // Needed for the Scanner class 2 3 /** Add a class comment and @tags 4 5 */ 6 7 public class StringFun { /** * @param args not used 8 9 10 11 12 public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Please enter your first name: "); 13 14 15 16 17 18 System.out.print("Please enter your last name: "); 19 20 21 //Output the welcome message with name 22 23 24 //Output the length of the name 25 26 27 //Output the username 28 29 30 //Output the initials 31 32 33 //Find and output the first name with switched characters 34 //All Done! } } 35 36 37