Java program to read two integers a and b. Compute a/b and print, when b is not zero. Raise an exception when b is equal to zero.

import java.util.Scanner; class division { public static void main(String[] args) { int a,b,result; Scanner input =new Scanner(System.in); System.out.println("Input two integers"); a=input.nextInt(); b=input.nextInt(); try { result=a/b; System.out.println("Result="+result); } catch(ArithmeticException e) {…

Continue ReadingJava program to read two integers a and b. Compute a/b and print, when b is not zero. Raise an exception when b is equal to zero.

Java class called Customer to store their name and date_of_birth. The date_of_birth format should be dd/mm/yyyy. Write methods to read customer data as and display as using StringTokenizer class considering the delimiter character as “/”.

import java.util.Scanner; import java.util.StringTokenizer; class customer { String name; String date; public void read() { Scanner input =new Scanner(System.in); name=input.next(); date=input.next(); } public void display() { System.out.print(name+","); String delims="/"; StringTokenizer…

Continue ReadingJava class called Customer to store their name and date_of_birth. The date_of_birth format should be dd/mm/yyyy. Write methods to read customer data as and display as using StringTokenizer class considering the delimiter character as “/”.

Design a super class called Staff with details as StaffId, Name, Phone, Salary. Extend this class by writing three subclasses namely Teaching (domain, publications), Technical (skills), and Contract (period). Write a Java program to read and display at least 3 staff objects of all three categories.

class Staff { int staffid,phone,salary; String name; public Staff(int id , int no, int sal, String na){ staffid=id; phone=no; salary=sal; name=na; } void display(){ System.out.println("-------------------------------------"); System.out.println("Staff ID:"+ " "+ staffid);…

Continue ReadingDesign a super class called Staff with details as StaffId, Name, Phone, Salary. Extend this class by writing three subclasses namely Teaching (domain, publications), Technical (skills), and Contract (period). Write a Java program to read and display at least 3 staff objects of all three categories.

Program to Evaluate postfix expression using separate header file for operations

STEP 1: create a header file named stack. In this file we declare the class and all the stack operations. ******************************************** stack.h *********************************************/ #define Max 10 class stk_class { /*declaration…

Continue ReadingProgram to Evaluate postfix expression using separate header file for operations

Java program on datagram socket for client/server to display the message on client side, typed at the server side

import java.util.*; import java.net.*; import java.io.*; public class udpserver { public static void main(String args[]) { DatagramSocket aSocket=null; Scanner scan=new Scanner(System.in); int ServerPort=999; System.out.println("Server ready n Waiting for connectionn"); try…

Continue ReadingJava program on datagram socket for client/server to display the message on client side, typed at the server side