Skip to main content

Posts

Showing posts from February, 2018
What will be the output?  1. class DemoString   {    public static void main(String... rk )              {           StringBuilder b = new StringBuilder (" abcdef ");           b.delete (4,6);           b.ensureCapacity (22);           System.out.print ( b.capacity ());             b.ensureCapacity (23);           System.out.print ( b.capacity ());     } } 2.      import java.time.*; import java.time.format.*; class DemoDateTime {    public static void main(String...rk)     {          DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yy/mm/dd"); LocalDateTime ldt = LocalDateTime.of(2015, 10, 10 , 11, 22);     System.out.println(dtf.format(ldt));            } } 

Practice Set 2

1. Write an application for Mobile Store where the user can view the available mobile phones in the store according to his/her preference. Store the mobile phone objects having attributes model number, OS, and Price. User should be allowed to filter the phones on the basis of those features. If user selects the model number, then ask to enter the model number and then display all the details of the phone with the given model number. If user selects OD then ask to choose the OS( Android/Windows/IOS) and display all the mobiles with that OS. If the user selects Price then ask to enter the minimum and maximum amount and display all the mobiles which can be bought with that amount. Now ask the user to select the mobile and display the details and bill. 2. Write an application for Cellular Company which provides different post paid plans for Calling/SMS. Ask the user to select the service provider and Display the menu to select the plan/pay bill. If user wants to selec

Compile-time Binding and Run-time Binding (Static & Dynamic Binding)

Consider the following program: class Parent {    public void demo(double d)     {         System.out.println("Parent "+d);     }    public void test(double d)     {         System.out.println("Parent Test "+d);     } } class Child extends Parent {    public void demo(int d)     {         System.out.println("Child "+d);     }    public void test(double d)     {         System.out.println("Overriding test in Child "+d);     } } class CompileTimeBinding {    public static void main(String...rk)     {         Parent p = new Child();         p.demo(5);   //Compile time Binding         p.test(5);   //Run-time Binding               } }

Brainstorming

What will be the output of the following Programs? A. class If_Demo {   public static void main(String...rk){    int i =10;    if(true)     {         i=20;     }    else        System.out.print(i);    System.out.println(++i);   } } B. class WhileDemo {   public static void main(String...rk){    int i =10;    while(false)     {         i=20;     }     System.out.println(++i);   } }

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()