Value To These Data Members Computer Science Essay

Print   

02 Nov 2017

Disclaimer:
This essay has been written and submitted by students and is not an example of our work. Please click this link to view samples of our professional work witten by our professional essay writers. Any opinions, findings, conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of EssayCompany.

1)Ch3Ex2

Create a class Student.

Add private instance variables:

studentName

courseName

age

Add methods in the Student class and write comments as well for every method explaining its functionality.

Create an instance of class Student in Ch3Ex2 class in which set and print the values of:

student name,

age

course name.

10)Ch3Ex3

Create a class Rectangle.

Add two private data members:

length

breadth

Assign the value to these data members using the Rectangle constructor.

Create a method calculateArea which calculates the area of rectangle.

Calculate the area of three rectangles which have different sizes.

1)Ch3Ex4

Create a class Person.

Add a few data members like

firstName

lastName

address

username

Create a constructor which has the parameters

String personFirstName

String personLastName

String personAddress

String personUsername

Assign the above parameters to the data members.

Create a display method displayPersonDetails to display

Name

Address

Username

In the main method create details for the below entries and print them.

Firstname

Lastname

Address

Username

Dave

Davidson

12 Pall Mall

Ddavidson

Joe

Pearse

New york

JoeP

Kathy

Kayle

California

KathyK

Sameer

Chaurasia

Mumbai

SameerC

Jack

Daniel

New Jersey

JackD

Steve

Wagh

Australia

SteveW

11)Ch3Ex5

Create a non-parameterized constructor.

Assign param1 and param2 values in it.

Print "Inside First Non - Parameterized constructor".

Create a parameterized constructor with a single parameter.

Assign that parameter value to param1.

Print "Inside Second single parameter constructor".

Create a parameterized constructor with two parameters.

Call second constructor to assign first parameter value

Assign second parameter value in the same constructor

Print "Inside Third two parameter Constructor".

Create a display method which prints param1 and param2.

In main method create instance of the class call all the constructors and display their values using display method.

12)Ch3LU1Ex4

Create a package called utilities.

Create a class called SalaryCalculator in this package.

Create a method for incrementing the salary of an employee based on the passed salary.

The salary should be incremented as follows:

If the salary of the employee is greater than 10000 then the salary should be incremented by 5000.

If the salary is less than 10000 then there should be no increment in the salary.

Invoke this method for the salaries of 15000 and 9000.

Print the values returned by the function for each of these passed salaries.

13)Ch3LU5Ex2

Write a java program with a non parameterized constructor which will set the value of member variables param1 and param2

Add a method which will return the sum of param1 and param2

Add a method which will return the multiplied value of param1 and param2

Call both the methods one by one and print the values.

8)Ch5Ex1

* *

** **

*** ***

**** ****

***** *****

****** ******

******* *******

******** ********

********* *********

********************

Write a Java program to print the above pattern.

14)Ch5Ex5

Write a program which will print the original 5 digit numeric value and reverse of the same using the do-while statement.

Input – 12345

Output:

The original number: 12345

The reverse number: 54321

15)Ch6Ex1

In the Main class, create an array of type int as given:

[ 4, 82, 12, 45, 1, 89, 13, 24, 81, 72, 63, 22 ]

Write the logic to

Remove the 3rd and the 5th elements of the array

Shift each of following elements to the left

Add two zeros at the end of the array

The output should look like:

[4, 82, 12, 1, 89, 24, 81, 72, 63, 22, 0, 0]

16)Ch6Ex2

In the Main class, create a two dimensional array of type int as given below:

[1, 2, 3, 4]

[5, 6, 7, 8]

[9, 10, 11, 12]

Write the logic to calculate and print:

The sum of all the numbers in the array

The average of the numbers in the array

17)Ch6Ex3

In the Main class, create a two dimensional array of type int as given below:

[1, 2, 3, 4]

[5, 6, 7, 8]

[9, 10, 11, 12]

Write the logic to calculate and print:

The sum of row 1

The sum of row 2

The sum of row 3

The sum of column 1

The sum of column 2

The sum of column 3

2)Ch6Ex4

In the Main class, create an array of type int as given below:

[ 12, 9, 4, 99, 120, 1, 3, 10 ]

Write logic to sort this array and print the sorted array.

The output should look like:

Values Before the sort:

12 9 4 99 120 1 3 10

Values after the sort:

1 3 4 9 10 12 99 120

9)Ch7Ex1

Observe the code that is provided below.

The code compiles correctly.

However, when you try to run this code, an exception is raised and the program terminates.

Introduce exception handling in the following code so that the program does not terminate due to an error and the errors are caught and handled gracefully.

class CustomerCareExecutive

{

String executiveName;

int rating;

public void dusplayDetails()

{

System.out.println(executiveName);

System.out.println(rating);

}

}

public class Ch7Ex1

{

CustomerCareExecutive exObj[];

public Ch7Ex1()

{

for (int ctr=0;ctr != 3;ctr++)

{

exObj[ctr]=new CustomerCareExecutive();

}

exObj[0].executiveName="Robert";

exObj[0].rating=Integer.parseInt("30+40");

exObj[1].executiveName="Gaurav";

exObj[1].rating=Integer.parseInt("85");

exObj[2].executiveName="Jeetendra";

exObj[2].rating=Integer.parseInt("60");

}

public void displayCollection()

{

for (int ctr=0;ctr != 3;ctr++)

{

exObj[ctr].dusplayDetails();

}

}

public static void main(String args[])

{

Ch7Ex1 collectionObj;

collectionObj=new Ch7Ex1();

collectionObj.displayCollection();

System.out.println("All Records displayed");

}

}

10)Ch7Ex3

Write a program that includes a user defined exception.

In the program,

Compare the salary of an employee according to the condition that, if the salary is less than or equal to 10000.

Throw a user defined exception signifying that the employee is not eligible.

Use a catch block to handle the exception.

3)Ch7Ex4

Write a program that performs the following operations on string. You must use the StringBuffer class and its methods.

Obtain the length of the string.

Display the third character in the string.

Append another string to the end of the existing string.

4)Ch8Ex3

Create a class called Employee with instance variables:

id

name

salary

In the main method,

Get values from the user for id, name and salary

Assign the above values to an Employee instance.

Use DataInputStream.

Use DataOutputStream to print the Employee details on the console.

5)Ch8Ex4

Create a Java program to list all the folders and the sub-folders in the root (/).

6)Ch8Ex5

Create a serializable class Student with the following attributes:

id

name

remark

Store it in a Student.dat file using ObjectOutputStream.

Print the content of the Student.dat file on screen by reading the ObjectInputStream.

7)Ch9Ex1

Define an interface having one method that takes an integer parameter.

For this method, provide three implementations:

In the first one, just print the value.

In the second one, print the square of the number.

In the third, print the cube of number.

Try to call all the versions.

11)Ch9Ex4

Create a class called Employee.

Add two methods (with identical name) in this class for calculating the remaining years of service.

Method 1: The parameter list should take a parameter for year. Calculate and return years of service from the current year.

Method 2: Should have no parameters. Calculate the retirement year from the passed in value.

Create a method for setting the employee’s current age.

The remaining years of service should be calculated using the retirement age, current age and the specified year to calculate from.

Instantiate this class and demonstrate the usage of both these methods. Display the returned value from both methods.

12)Ch9Ex5

Create a class called TaxRateCalculator having

Method which calculates the tax on the passed amount.

The tax should be 10% of the past value.

Derive a class called IndiaRateCalculator.

Override the method inherited from the base class.

Calculate the tax based on 15% of the past amount.

Instantiate objects for both the classes TaxRateCalculator and IndiaRateCalculator.

Pass the same amount to the methods in both the objects.

Display the returned value on the console to demonstrate that they are different.

JPP

8)Ch3Ex3

Create a program to read a file and print the content of the file in the console.

The user will enter the file path and by using thread, read the contents of the file.

13)Ch4Ex5

Create a thread and print the name with its priority in the run() method.

In the main method, get five numbers as user input and calculate the total.

If the total is not a prime number,

Start the thread.

Otherwise, print a message "Number is a prime, unable to create thread".

9)Ch5Ex3

Create a Java program to perform the following tasks:

Create an ArrayList to store the names of the employees.

Create two synchronized methods to add the employee names to the ArrayList and print the employee names.

Print the employee names once both the threads have finished adding the employees.

14)Ch5Ex5

Create a class and implement the Runnable method.

Create a character array and initialize it with 'a' to 'z'.

Implement the run() method to print the array.

In the main method, create two threads for a single reference of the Runnable method.

Start the threads.

Make sure the array is printed twice in a proper sequence.

Ch6Ex2(not uploaded)

Write a Java program to create a class that implements the Runnable interface.

In the main method, create a thread by using the FixedThreadPool.

In the run() method, get the input from the user.

Calculate a Fibonacci series up to the input value.

2)

We are an IT Service Company having several clients.

During reviews we found that the automatic mailing software replaced client contents during the mailing process due to a virus infection.

At this time we are able to identify the content for each client but want to avoid the manual copy and paste process.

So we want to make a program which will take two files as input and will replace the content of two files with each other.

Conditions:

Both the files will be static into the program. Like client1.txt and client2.txt.

Both files are text files (.txt) only.

Output:

If file content is replaced successfully, then display message "Content Replaced Successfully".

If any error occurred during replacement, then display message "Error in replacement".

If any of the two file did not exist on the system, then display message "File Not Found".

3)

Write a program which will return the image location of a specific shape.

We have predefined set of shapes:

Circle

Square

Triangle

You will be allowed to enter shape value and program will return the image URL from system.

Conditions:

Image store folder is fixed into system and predefined in the program.

Images are stored into specified location for each shape.

Image file name will be <shape-value>.jpg.

Example: for circle it will be circle.jpg

4)

Write a program to print the date and time before and after the content is copied from one file to another file.

Create two files input.txt and output.txt.

In the input.txt write "I am normal text being used by the programmer to check the modification time."

Print the last modification time of input.txt.

Make the thread sleep and print message that the thread is going to sleep.

Copy the values from input.txt to output.txt by program.

After successfully copying the values, display the last modification time of file.

Conditions:

There is no user input involved into this program.

5)

Write a program to calculate the train reservation date from the user entered date.

Conditions:

Train reservation can be done up to 120 days from the user entered date.

By default system shows today’s date and will calculate 120 days from today’s date.

Program must show option to check the validity from other dates as well.

System should ask the user to enter Y/N for checking with new date.

Message "Do you want to check the validity with another date?"

If the input is ‘Y’, then take another input for date

If the input is ‘N’, exit from the program.

You can enter dates which lie between 120 days before today’s date and 120 days after today’s date.

6)

An IT company has around 300 customers and they want to transfer customer data from the head office to all the regions and development centers.

Now they have a need to create a program which will serialize customer data and send it to all the sub offices.

There is a program which will read this serialized data and convert it back to customer data.

You need to write a program for serialization and de serialization of customer data.

Take at least 5 predefined customers of your choice with corresponding field data.

Customer will have following data:

Customer Name

Country

Contact Number

Email

Note: create a class Customer having all predefined field.

Use serialization technique to write data into the byte streams.

Make two separate methods for serialization and de - serialization process.

7)

Write a program to generate user defined exception for FileNotFound and NullPointerException.

Override the toString method to display a customized message.

Write three separate user defined exceptions to handle these three exceptions given above.

Create a program to generate these three exceptions and handle them with user defined exceptions.

15)

Create a thread for taking input from the user.

Based on the predefined user inputs, program will display specific message for each input as given in the table below:

Predefined User Input

Output message on screen

Run

I am running now

Stop

I am stopped now

Tired

I am exiting the race

Note:

Program should not quit until it gets "Tired" as the user input.

All the inputs are case sensitive.

Level-3 Exercises

PROJECT QUESTIONS

ClearTech Pvt. Ltd. is a fast expanding software company in the telecom space.

The senior management has realized that the existing manual system of managing employee payroll is inefficient, error prone and not employee friendly. They have approved the development of an Automated Payroll Processing System that performs the following functions:

Allows employees to query and seek information about their compensation structure, salaries and deductions.

Perform payroll computations for all employees efficiently and correctly.

The Project has been named CTEMPS (ClearTech Employee Payroll Management System).

The company has 2 types of employees

Permanent employees

Employees on contract

Each of these types has differing compensation structures, methods of computation and taxation rules.

Here is an overview of the functional requirements of the CTEMPS project. Your Project Manager has planned the project in 5 stages. You are required to complete each stage before you move to the next.

#

User Category

User Functionality

1

Permanent Employee

Query employee and compensation details

Compute Salary slip (with breakup) and display for a given month

2

Contracted Employee

Query employee and compensation details

Compute Salary slip ( with breakup) and display salary slip for a given month

3

HR Administrator

Enter employee details ( for say 6 employees ), permanent and contracted

Compute Tax liability for each employee

Query details for a particular employee

Query total salary payout details for all Salaried employees

Query total salary payout details for all Contracted employees

Stage1

Create appropriate packages and add divide the employees in different classes such as Contract Employee and Permanent Employee to make your program more efficient and your code more manageable.

Both classes should have properties of employee details.

Create a class ClearTechSolutions and using instance of Permanent and Contract employee class, set and print the following employee details:

Permanent Employee

Contract Employee

Employee Code

Employee Code

Employee Name

Employee Name

Employee Address

Employee Address

Employee Date of Birth

Employee Date of Birth

Employee Basic Salary

Employee Daily Rate

Employee Monthly Gross Salary

Employee Number of Days Worked

Employee Monthly Tax

Employee Monthly Tax

Employee Net Salary

Employee Net Salary

Stage 2:

Create a class diagram, both, for permanent and contracted employees, the details of which are supposed to be accepted and displayed on screen.

The following details need to be tracked for permanent employees:

Employee Code

Name

Address

Date of Birth

Annual Basic Salary

Subsequently in the program, you will also calculate and store Monthly Gross Salary, Monthly Tax and Monthly Net Salary for the employee.

Further on, you will need to build leave accounting into the system, for which you will need 3 additional fields:

No. of days in a month

No. of leaves

Net payable salary

The following details need to be tracked for contracted employees:

Employee Code

Name

Address

Date of Birth

Rate per Working Day

Subsequently in the program, you will also calculate and store Monthly Gross Salary, Monthly Tax and Monthly Net Salary for the employee.

Further on, you will need to build leave accounting into the system, for which you will need 2 additional fields:

No. of working days a contract employee is present

Net payable salary

You must use the following initial data for your program:

Employee Code

Name

Address

Date of Birth

Annual Basic Salary

E001

Mohan

E-15 Mandir Marg

31/July/1984

400,000

Employee Code

Name

Address

Date of Birth

Annual Basic Salary

C001

Mohan

E-32 M.G. Marg

30/Jun/1974

5,000

Stage 3:

Create a class diagram, both, for permanent and contracted employees, the details of which are supposed to be accepted and displayed on screen.

The following details need to be tracked for permanent employees:

Employee Code

Name

Address

Date of Birth

Annual Basic Salary

Subsequently in the program, you will also calculate and store Monthly Gross Salary, Monthly Tax and Monthly Net Salary for the employee.

Further on, you will need to build leave accounting into the system, for which you will need 3 additional fields:

No. of days in a month

No. of leaves

Net payable salary

The following details need to be tracked for contracted employees:

Employee Code

Name

Address

Date of Birth

Rate per Working Day

Subsequently in the program, you will also calculate and store Monthly Gross Salary, Monthly Tax and Monthly Net Salary for the employee.

Further on, you will need to build leave accounting into the system, for which you will need 2 additional fields:

No. of working days a contract employee is present

Net payable salary

You must use the following initial data for your program:

Employee Code

Name

Address

Date of Birth

Annual Basic Salary

E001

Bob

E-12 Lajpat Nagar

01/Feb/1974

800,000

E002

Kevin

E-15 Mandir Marg

01/Apr/1990

1,000,000

E003

Mohan

E-15 Mandir Marg

31/July/1984

400,000

Employee Code

Name

Address

Date of Birth

Rate per Day

C001

Mohan

E-32 M.G. Marg

30/Jun/1974

5,000

C002

Steve

A-32 M.G. Marg

15/Oct/1981

7500

C003

Mary

A-31 Rohini

15/Dec/1979

10,000

Note: - Use Arrays of object to implement the program

Stage 4:

Transfer the data stored in the arrays to a file.

Create a menu in the main method

The Main menu should have 2 category of users, and should get the following functionalities:

Employee User Type

View Payslip

These functionalities allow the employee to view one's own slip.

Access is controlled by asking for the employee code and password (For current purposes, let the password be the same as the employee code)

HR Administrator User Type:

View existing employee details, either all of them or for specific employee using the employee code as input.

Add additional employee details via the console inputs.

Employee Code

E004

E005

Employee Name

Maya

Shanti

Employee Address

E-14 Lajpat Nagar

F-16 Mandir Marg

Employee DOB

11/Feb/1974

11/Apr/1980

Annual Basic Salary

600,000

1,400,000

Publish reports on total monthly salary payout and tax deducted for Permanent and Contract employees . Access is controlled by asking for a password (make password hard code in main method)

Stage 5:

Provide functionality for the HR Administrator to enter any leaves taken by the salaried employees or No. of days when a contract employee is absent.

Compute Monthly salary accordingly.

Build safeguards for two (2) scenarios where this program will fail or give the erroneous results.

One such scenario is entry of negative numbers in Day Rate or Basic Salary of an employee.

Identify a second such scenario and build safe guard for it.

Level 2 - Problem 3: (Threading)

Create a program to identify whether a new railway crossing establishment is required or not based on probability of accidents.

2 trains are involved in this simulation.

Each train has a certain speed and they are running in opposite directions on the same track.

There is change-over point on the track, from where second train will change its route

However, if the first train crosses the changeover point before the second train changes its route then there will be collision.

Train speed will be between 100 to 300 Km per hour. Speed is generated by the program for both trains.

500 KM track is used for testing this operation.

The changeover point could be anywhere between 200 km to 300 km mark on the test track. This will be decided by the program randomly.

User will give input for the number of times the test has to be simulated.

Both trains will start simultaneously from either end of the track.

Output:

If the two trains collide on 50% or more occasions, then system will display:

"A Railway crossing is needed"

Else display:

"No railway crossing is needed"



rev

Our Service Portfolio

jb

Want To Place An Order Quickly?

Then shoot us a message on Whatsapp, WeChat or Gmail. We are available 24/7 to assist you.

whatsapp

Do not panic, you are at the right place

jb

Visit Our essay writting help page to get all the details and guidence on availing our assiatance service.

Get 20% Discount, Now
£19 £14/ Per Page
14 days delivery time

Our writting assistance service is undoubtedly one of the most affordable writting assistance services and we have highly qualified professionls to help you with your work. So what are you waiting for, click below to order now.

Get An Instant Quote

ORDER TODAY!

Our experts are ready to assist you, call us to get a free quote or order now to get succeed in your academics writing.

Get a Free Quote Order Now