Java Assignments


Basic programming:

1. A school wants to design a calculator application to perform basic Arithmetic operations (Addition, Subtraction,
    Multiplication & Division). Write a program to Design a calculator application.

    *** Recommended IDE: EditPlus

   Observations:
1. Declare 2 input variables with the following names and initialize with values 50 and 5.
a. firstNo
b. secondNo

Experience the feature of flexible variable declaration by declaring 4 output variables separately for each operation
when required. Output Variable names as follows.
a. add – for addition
b. diff – for subtraction
c. prod – for multiplication
d. div – for division

2. A retail store management wants to provide a discount on the bill amount, if the bill amount is above 10000 then 10% otherwise 5%.

  • Declare variables billid,custid and bill amount
  • billid should be numeric Ex:- 101
  • custid should be alphanumeric Ex:-C1001
  • bill amount should be float type Ex:- 12500.00

then calculate discount and total payable amount.

      *** Recommended IDE: NetBeans

3. An intermediate college wants to design a progress report application for their students.

    *** Recommended IDE: NetBeans

   Requirements are as follows:

1. Read marks of maths, physics & chemistry. ( use scanner class )
2. Calculate total & average.
3. Find the class only if all subjects marks crossed 40% other wise display the subject name and status as failed:
4. Grade is categorized based on the following:
Above 60% – First class
50 to 60% – Second class
40 to 50 % – Third class

4. Write an application to read names and ages of 2 persons and find out who is the elder one. (EditPlus)
     Note: Use GUI Input and GUI output.

5. Design an application to read name and gender, and display output as follows.

For m/M : Mr. ________ Welcome to Java class
For f/F : Miss.________Welcome to Java class
Other than m/f ________Welcome to JAVA class
     Note: use scanner class for input, Use printf() for output. (EditPlus)

6. Write a program to read a no using command line argument and check whether the entered no is prime or not.
(EditPlus)

7. Design an application for a Departmental stores which read names and prices of 10 items and prints the list of items
    and total bill amount.
    Note: (NetBeans)
1. Use string array for item names and double array for price.(two arrays used)
2. Declare one variable for final amt. & Use enhanced for loop to calculate final amt;
3. Use ordinary for loop to display item name and price.
4. Display number of items and total bill amount.

8. Design an application which prints mobile no and 4 weeks talk time in Duration of 5 customers. (Editplus/NB).
Note: Do not read input at runtime, initialize the array.

 Output:
Mobile no      W1     W2     W3      W3

9xxxxx123    10       20      12        23
9xxxxx523    11       23      62        53
9xxxxx624    14       22      42        23
9xxxxx524    20       21      14        63
9xxxxx623    30       25      12        13

9. Read no using command line argument and check whether it is even or odd using ternary operator. (NetBeans)

10. Write a program to read a character using scanner class and check whether it is vowel or consonant using switch
case. (EditPlus).

Object oriented programming:

1. A company wants to design an application for their employees which calculates bonus based on given criteria.
    Note: Use NetBeans to develop this application.

emp_class-diagram

      Note:
       1. Execution class logic should be EmpDemo.java
2. Employee class must be public & All the data members should be secured( should not be accessed outside the
class).
3. Gross salary, net salary and bonus fields are read-only(ie no setXXX())
4. Gross salary=basic+allowances
5. Net salary=gross salary-deductions
6. Bonus is calculated based on employee experience.
1. Experience >5 years 3 months of net salary as bonus
2. Experience >3 years 2 months of net salary as bonus
3. Otherwise 1 month of net salary as bonus
4. Display 3 Eemployess data as below

    output:

emp_output

2. Write a program to add below set of no’s (use method overloading)
     1. 12,34,67
2. 12.45,45.78,78.90
3. 56,89
4. 1,2,3,4,5,6

3Observe the following code and prepare the Application logic.
      Note: write 2 logics, 1 with method overloading and 1 with varargs.

class ProductsDemo
{
        public static void main(String[] args)
           {
              Products p=new Products();

              p.disp(“Pen”,”Pencil”,”Gum”);
              p.disp(“Car”,”Bike”);
              p.disp(“Laptop”,”Mouse”,”Keyboard”,”Spekers”);
            }

}

 Output:
overloading_ouput

4. Write aprogram to read rollno, name and different hobbies of 5 students. (use varargs).
Note : instance variables of Student class- Rollno,name,hobbies[]
                 Write the main() method in StudentDemo.java

5. SBI wants to print a report of their customers as below.

customer_screen

Note:

  1. Customer id should be generated automatically
  2. Create only one customer object to read 5 customers details at runtime(array of objects)
  3. Customer class constructor should be as below
    1. Customer(java.lang.String, double);
  4. Customer class should contain display() method to print the customer info.

customer_class
6. Develop an Electricity Bill generation application.
Note: Create a main method class with the name BillDemo.java, Click here to download EleBill.class in zip format. Extract EleBill.zip file to get EleBill.class file.
EleBill class Constructor parameters order-CustomerId, Name, Last month reading, Present month Reading, Category.
Note: Category should be either d/D(Domestic) or C/c(Commercial)

 

Inheritance:

  1. Design a calculator application from the below-given inputs. (Use NetBeans only).

Instructions: 

  1. All the data members should be private
  2. Develop an application “CalcDemo.java”  which performs all the arithmetic operations from the above-given classes.
  3. Only one operation should be performed when the application is run.
  4. Use command line arguments/scanner class to pass the operator(+/-/x//) as input.

 Observations:

  1. Data hiding. (security)
  2. Encapsulation and abstraction
  3. Reusability (inheritance)
  4. Single inheritance
  5. Hierarchal inheritance

Version2:

*** After 1 year the client requested us to convert this application into GUI.***

*** Client wants to add a new module that checks maximum of 2 nos ***

Instructions:

  1. Add a new method calc() in Data class and initialize the variable c to 0.
  2. Override calc() method in every subclass, provide the required business logic.
  3. Add new module Biggest to find biggest of 2 nos, GUI based.
  4. Override read() and disp() methods of Data class with GUI input and GUI output.
  5. Develop an application “CalcDemoGUI.java”  which performs all the arithmetic operations from the above-given classes.
  6. Only one operation should be performed when the application is run.
  7. Use GUI input to read the operator(+/-/x//).

 Observations:

  1. Hierarchal inheritance
  2. Multi-level inheritance
  3. Hybrid inheritance
  4. Method overriding.