Tag: class
-
Nokia 6 Cost Price in Nepal & Specifications
Nokia 6, one of the most favored mobile worldwide has now arrived in the Nepalese market too. Not only this but all the branded Nokia phones are available in the Nepali market. Paramount Electronics, Nokia’s official distributor in Nepal has introduced Nokia 6 in the Nepali markets. According to the distributor, Nokia 6 costs Rs.…
-
Create a user-defined package box which has a class definition. For box having data member and disp( ) method
Write a JAVA program to accomplish the following task. Create a user-defined package box which has a class definition. For box having data member and disp( ) method. (Assume suitable data). Source file imports above package and calculates the volume of the box.
-
Java (Thread class) program to implement two threads such that one thread prints prime numbers from 1 to 10 and other thread prints non-prime numbers from 1 to 10
Write a Java program to implement two threads such that one thread prints prime numbers from 1 to 10 and other thread prints non-prime numbers from 1 to 10 (use Thread class ). Note: Each thread has a delay of 500 milliseconds after printing one number.
-
Throw an Exception – Java Exception Program Implementation
Write a JAVA program to accept a number from the user and throw an exception (java exception) if the number is not an even number. Example of Throw an Exception Program Implementation. import java.lang.*; import java.io.*; class myException extends Exception { myException(String msg) { super(msg); } } class q12Exception { public static void main(String args[])…
-
Java Method Overriding: Program Implementation
Write a JAVA program to implement Method Overriding for following inheritance : (Assume suitable data ) Abstract Class : Shape dim1, dim2, disp( ) abstract area ( ) Class: Rectangle getd( ), area ( ) Class: Rectangle getd( ), area ( )
-
Java Multiple Inheritance: Program Implementation
Write a program to implement the following Multiple Inheritance: Class Student Name, roll_no Mark 1, Mark2 Interface: Exam Percent_cal( ) Class: Result Display( )
-
Java Multi-Level Inheritance: Program Implementation
Write a program to implement the following Multi-Level Inheritance: Class: Account Cust_name , acc_no Class: Saving_Acc Min_bal, saving_bal Class:Acct_Details Deposits, withdrawals import java.lang.*; import java.io.*; class Account { String cust_name; int acc_no; Account(String a, int b) { cust_name=a; acc_no=b; } void display() { System.out.println (“Customer Name: “+cust_name); System.out.println (“Account No: “+acc_no); } } class Saving_Acc…
-
Implement a Vector that accepts five items from the command line and store them in a Vector and display the objects stored in a Vector.
Write a JAVA program to implement a Vector that accepts five items from the command line and store them in a Vector and display the objects stored in a Vector. import java.lang.*; import java.io.*; import java.util.*; class q8Vector { public static void main(String args[]) { Vector list = new Vector(); int len=args.length; for(int i=0;i<len;i++)…
-
Write a program to accept the value of Apple sales for each day of the week (using an array of type float) and then, calculate the average sale of the week.
Write a program to accept the value of Apple sales for each day of the week (using an array of type float) and then, calculate the average sale of the week. import java.lang.*; import java.io.*; class q7Apple { public static void main(String args[]) throws IOException { double avg; float sum=0; float sales[]=new float[7]; BufferedReader br…
-
JAVA program to accomplish task using string/string Buffer class
Write a program to Implement a program to accomplish the following task using string/string Buffer class: i. Accept a password from the user. ii. Check if password is correct then display “Good” Else display “Incorrect password” iii. Append the password with the string “Welcome to Java!!!” iv. Display the password in reverse order. v. Replace…
-
Accept a string from the console and count number of vowels, constants, digits, tabs and blank spaces in a string.
Write a program to accept a string from the console and count number of vowels, constants, digits, tabs and blank spaces in a string. import java.io.*; class q5vowels { public static void main(String args[]) throws IOException { String str; int vowels = 0, digits = 0, blanks = 0; char ch; BufferedReader br = new…
-
Define a class Employee to accept emp_id, emp _name, basic_salary from the user and display the gross_salary.
Write a program to define a class Employee to accept emp_id, emp _name, basic_salary from the user and display the gross_salary. import java.lang.*; import java.io.*; class Employee { int emp_id; String emp_name; float basic_salary; Employee(int id, String name, float sal) { emp_id=id; emp_name=name; basic_salary=sal; } void display() { float da=basic_salary*15/100; float hra=basic_salary*10/100; float gross_sal=basic_salary+da+hra; System.out.println…
-
Java Class Fraction Operations / Numerator and Denominator / Initialize Objects using Constructors
Write a program to define a class Fraction having data members numerator and denominator. Initialize three objects using different constructors and display its fractional value. import java.lang.*; import java.io.*; class Fraction { double numerator,denominator,fraction; Fraction (int a, double b) { numerator=a; denominator=b; fraction=numerator/denominator; System.out.println (“Fraction1 = “+fraction); } Fraction (int x, int y) { numerator=x;…
-
Student Class / Data Members / Initialize / Display Data Values and Calculate Students Marks
Write a program to define a class student with four data members such as name, roll no., sub1, and sub2. Define appropriate methods to initialize and display the values of data members. Also, calculate total Marks and percentage scored by the student. import java.lang.*; import java.io.*; class student { String name; int roll_no; int sub1,sub2;…