Skip to main content

Practice Test Week-1




1. Write an application that calculates and displays the weekly salary of an employee. 
In the main() method, prompt the user to enter the hourly_pay_rate, regular_working_hours, and overtime_hours. 

Create a separate method to calculate overtime pay, which is regular hours times the pay rate plus overtime hours times 1.5 times the pay rate; return the result to the main() method to be displayed.

2. When gasoline is Rs 120 per barrel, then the consumer’s price at the pump is between Rs 3.60 and  Rs 4.20 per gallon. 

Create a class named GasPrice such that its main() method holds an integer variable named price_per_barrel to which you will assign a value entered by a user at run time. 

Create a method to which you pass price_per_barrel. The method displays the range of possible prices per gallon. For example, if gas is Rs150 per barrel, then the price at the pump should be between Rs 4.50 and  Rs 5.25.

3. Create a class named TestBankAccount whose main() method declares 3 BankAccount objects. 

Call a getData() method 2 times. Within the method, prompt the user to enter values for each field for a BankAccount, and return a BankAccount object to the main() method where it is assigned to one of main()’s BankAccount objects. 

Do not prompt the user for values for the 3rd BankAccount object, but let it continue to hold the default values. Then, in main(), pass each BankAccount object in turn to a showValues() method that displays the data, calls the method that deducts the monthly fee, and displays the balance again. The showValues() method also calls the method that explains the deduction policy i.e. if the balance is less than Rs 1000 then Rs 100 will be deducted.  

4. Create a class named Billing that includes three overloaded computeBill() methods for a photo book store.
When computeBill() receives a single parameter, it represents the price of one photo book ordered. Add 7.5% tax, and return the total due. 

When computeBill() receives two parameters, they represent the price of a photo book and the quantity ordered. Multiply the two values, add 7.5% tax, and return the total due. 

When computeBill() receives three parameters, they represent the price of a photo book, the quantity ordered, and a coupon value. Multiply the quantity and price, reduce the result by the coupon value, and then add 7.5% tax and return the total due. Write a main() method that tests all three overloaded methods.

5. Create a class named State that holds the appropriate fields for name of the state, an population, and two City objects that hold data about the capital city and the most populour city. 

The State constructor requires parameters that represent the names and populations of the state, its capital, and its most populour city. Provide get methods for each field.

Create the City class to be a non-static, private inner class within the State class; the City class contains a city’s name and population. Create a class to assign values to and display values from two State objects.

Comments

  1. Hi, Thanks for this valuable information sharing with us. This is very useful for me and many others people. Keep update Thanks once again.
    Java Training in Noida

    ReplyDelete
  2. Good Post! Thank you so much for sharing the post, it was so good to read and useful to improve
    Java Training in Electronic City

    ReplyDelete
  3. Well, that is the nice post for java programming. If somehow interested to know about Hindu temples of India visit here at https://www.astrolika.com/temples/.

    ReplyDelete

Post a Comment

Popular posts from this blog

Practice MCQs

  1. What will be the Output of the following code? class X{                  static int x = 1;                        static class Y {                              static int y = x++;                                static class Z                                                                       {                                                                                         static int z = ++y;                                                                        }                                               }                }   class MainClass{     public static void main(String[] rk)    {                             System.out.print(X.x);                                             System.out.print(X.Y.y);                             System.out.print(X.Y.Z.z);         } } A. 113 B. 123 C. 111 D. None of These Ans: A 2.  Which of the following statement is TRUE about t he following code? public class Outer  {    private i

Practice Set

1. Write a program to create a class Voter which contains attributes name, date_of_birth and voter_id and voter has a Voter_Card. Provide appropriate constructor to initialize all the attributes of the Voter but voter id must be assigned automatically only when the age of the voter is greater than or equal to 18 years. VoterCard is a nested class with attributes voter_id and Voter_name. Make sure that voter card is created only when user is a valid voter and if it is already created then must not be assigned the new voter id. 2. Write a program to define two interfaces UGC and AICTE both having a default method int getAdmission() to take the admission and an abstract method String payFee(). getAdmission() in UGC must ask the percentage in qualifying exam and if the percentage >= 60 then generate the registration number and return. getAdmission() is AICTE must ask the user to join the counseling after 5 days and display the date of counseling and return the counseling token numb

Mock Test - 1

1. Which of the following is a byte stream class? A. ObjectInputStream B. Writer C. PrintWriter D. Scanner Ans: A 2. Which exception is thrown by read() method in InputStream class? A. IOException B. InterruptedException C. FileNotFoundException D. None of These Ans: A 3. Which of the following class is subclass of FilterInputStream? A. InputStream B. ObjectOutputStream C. FileInputStream D. BufferedInputStream  Ans: D 4. Which of these class contains the print() and println() methods? A. System B. out C. PrintStream D. BUfferedOutputStream Ans: C 5. Which of these is a method to clear all the data present in output buffer without terminating the stream? A. clear() B. fflush() C. flush() D. close() Ans: C 6. Which of these classes defined in java.io and used for file-handling are abstract? (i) InputStream        (ii) PrintStream    (iii) Reader        (iv) FileInputStream A. Only i     B. i and ii    C. Only iii    D. i and iii Ans: D 7. What is the output of this program? class MyE