WAJP to create a Player class.Inherit the classes Cricket_Player,Football_Player and Hockey_ Player from Player class.
JAVA-15 Q.15 WAJP to create a Player class.Inherit the classes Cricket_Player,Football_Player and Hockey_ Playerfrom Player class. Â class Player { protected String name; protected int age; public Player(String name, int age) { this.name = name; this.age = age; } public void display() { System.out.println(“Name: ” + name); System.out.println(“Age: ” + age); } } class Cricket_Player […]
Write an application that creates and start three threads, each thread is instantiated from the same class. It executes a loop with 5 iterations. First thread display “BEST”, second thread display “OF” and last thread display “LUCK”. All threads sleep for 1000 ms. The application waits for all threads to complete and display a message.
JAVA-13 Q.13 Write an application that creates and start three threads, each thread is instantiated from the sameclass. It executes a loop with 5 iterations. First thread display “BEST”, second thread display “OF” andlast thread display “LUCK”. All threads sleep for 1000 ms. The application waits for all threads tocomplete and display a message. Solution […]
Write a Java program to display string with capital letters which are inputted through command line. Display those string(s) which starts with “B”.
JAVA-13 Q.13 Write a Java program to display string with capital letters which are inputted through command line. Display those string(s) which starts with “B”. Solution :- public class DisplayStringsStartingWithB { public static void main(String[] args) { if (args.length == 0) { System.out.println(“Please provide input strings as command-line arguments.”); return; } System.out.println(“Strings starting with ‘B’:”); […]
Write a Java code that handles the custom exception like when a user gives input as Floating point number then it raises exception with appropriate message.
JAVA-12 Q.12 Write a Java code that handles the custom exception like when a user gives input as Floating point number then it raises exception with appropriate message. Solution :- import java.util.*; // Custom exception class class FloatingPointInputException extends Exception { public FloatingPointInputException(String message) { super(message); } } public class CustomExceptionExample { public static void […]
Create class EMPLOYEE in java with id, name and salary as data-members. Again create 5 different employee objects by taking input from user. Display all the information of an employee which is having maximum salary.
JAVA-11 Q.11 Create class EMPLOYEE in java with id, name and salary as data-members. Again create 5 different employee objects by taking input from user. Display all the information of an employee which is having maximum salary. Solution :-Â import java.util.*; class Employee { int id; String name; double salary; public Employee(int id, String name, […]
Write a java program that accepts string from command line and display each character in capital at the delay of one second.
JAVA-10 Q.10 Write a java program that accepts string from command line and display each character in capital at the delay of one second. Solution :-Â public class DisplayCharsWithDelay { public static void main(String[] args) { if (args.length == 0) { System.out.println(“Error: Please provide a string as a command-line argument.”); return; } String input = […]
Write a Java program that prompts the user to input the base and height of a triangle. Accordingly calculates and displays the area of a triangle using the formula (base* height) / 2, and handles any input errors such as non-numeric inputs or negative values for base or height. Additionally, include error messages for invalid input and provide the user with the option to input another set of values or exit the program.
JAVA-9 Q.9 Write a Java program that prompts the user to input the base and height of a triangle. Accordingly calculates and displays the area of a triangle using the formula (base* height) / 2, and handles any input errors such as non-numeric inputs or negative values for base or height. Additionally, include error messages […]
Write a java application which accepts two strings. Merge both the strings using alternate characters of each one.Â
JAVA-8 Q.8 Write a java application which accepts two strings. Merge both the strings using alternate characters of each one. Solution :- import java.util.*; public class MergeStrings { public static String mergeAlternate(String str1, String str2) { StringBuilder merged = new StringBuilder(); int length1 = str1.length(), length2 = str2.length(); int maxLength = Math.max(length1, length2); for (int […]
Write a java program that creates Singly Link List to perform create, insert, delete and display node using menu driven program.
JAVA-7 Q.7 Write a java program that creates Singly Link List to perform create, insert, delete and display nodeusing menu driven program. Solution :-Â import java.util.Scanner; class Node { int data; Node next; public Node(int data) { this.data = data; this.next = null; } } class SinglyLinkedList { private Node head; public void create(int data) […]
Write a java program to design a class Mystring having data member of type String add member function to achieve following task.
JAVA-6 Q.6 Write a java program to design a class Mystring having data member of type String add memberfunction to achieve following task. Solution :-Â import java.util.Scanner; class MyString { private String str; public MyString(String str) { this.str = str; } // Method to reverse the string public String reverseString() { return new StringBuilder(str).reverse().toString(); } […]