The Java language specification

Published: November 30, 2015 Words: 579

Theory and Code Fragments

Theory

There are two main purposes of the Java compiler javac. List and explain them.

Ans: The two main purposes of Java compiler javac is explained below -

List and briefly explain each of the actions which take place when a java program is executed.

A Java method has four essential parts. List and briefly explain each of the four parts.

Elementary Programming Problems

Write a separate and complete Java program to calculate the annual income tax paid by all employees to Inland Revenue of United Kingdom. It is recommended that your solutions be designed with a main method which calls other separate static methods. This kind of design was employed in a number of the example program given in the first few weeks of the subject. The details of calculating income are specified in detail below.

Write a Java method which has accepts all the three types of income as input and returns the tax payable as output. The method should not print the tax value onto standard output - the value of the tax payable should be returned to the caller of the method.

Write a Java program to test the method. The program should allow the user to enter all the three types of income and should report the corresponding tax payable. The program should repeat asking the user until he/she wishes to exit. This can be done using a while loop, which has been discussed in the class. Submit the results of several program runs which show that you have adequately tested your tax calculations.

Some results of several program runs which test tax calculation:

Please choose number to calculate TAX:

Enter your income:

The corresponding TAX payable is £ 199.9

Please enter again:

Enter your income:

The corresponding TAX payable is £ 335.0

Please enter again:

Enter your income:

The corresponding TAX payable is £ 10626.25

Please enter again:

User define class question

To answer this question you need to create two source code files. One of these will be a class which defines a type of objects; the other will be a program which creates objects and tests them.

The User-defined class

In a file called 'Computer.java', write a class, which defines computer objects. A Computer object is one, which simulates a computer system. For example, we might describe a computer as a Dell, with 12 GB Hard Drive and costs £500 . Follow the guide lines below when designing your 'Computer' class.

The state of a Computer object should be defined as

Define the following methods for each Computer object

Computer testing program

Write the code for this program in a file called 'TestComputer.java' and save it into the same working directory as the previous 'Computer.java' source file. The purpose of this program is just to check that the methods of the 'Computer' class work correctly - it is not meant to be a larger or complex program. The TestComputer program should contain just a static main method in which there is code to create two Computer objects - one created using the default constructor and the other with three arguments

The program should start by displaying the name and price of both computers. Then use writer methods of the first object to set its manufacturer's name to 'Compaq', the Hard drive capacity to 20 GB and price to be £800. It should then attempt to set the price of the second object to some negative value.

Bibliography