Task 01 - Java Basics

Task Objects:
  1. Writing, compiling and running Hello World program
  2. Using primitive data types and their literals
  3. Getting input from user of different primitive types
  4. Using escape sequences and format specifiers
  5. Using functions of Math for sin, cos, tan, ceil, and floor etc. and using Random class 
  6. Using if/else and loops in Java
Objectives of lab tasks is to practice OOP concepts discussed in class. Most of the tasks would be based on class topics but sometimes, to make it interesting and increase your interest, I would give tasks that requires you to think and devise better solution and that increase you logic building skill. Sometime, you may have to explore new stuff, but it would be of your level, so no worries. Make habit of doing programming tasks at your homes or hostals, use labs to discuss issues or your projects or to show me working code of your weighted assignments etc.

Programming is your core course, so I expect and suggest you to spend at least 2 hours a day on average. That means, you must spend arround 14 hours per week on OOP. It may seems difficult, but if you do it, InshaAllah you would be able to make complete software using Java GUI for basic business needs and learning Android programming would take just 1-2 months after this course.

1. Make a class HelloWorld.java and define main method in it. The method should get 2 integers from user and print sum on command line interface (CLI). After this task, you should be able to:
  1. Create and save HelloWorld.java file
  2. Declare and initialize variable of type int
  3. Compile and run it
  4. Get input from user using Scanner class
  5. Using System.out.println and System.out.printf functions

2. Make another class named MinMaxAverage.java, when its compiled and executed, its main method should take three double numbers from user and print minimum, maximum and average number on CLI.

3. Take two integers from user i.e. table-number and ending-value. As output, show the table of user entered number up to ending-value. Your output must follow below format. I assume user entered: 3 and 6, the output should table of 3, printed up to 6.
1 x 3 = 3
2 x 3 = 6
3 x 3 = 9
4 x 3 = 12
5 x 3 = 15
6 x 3 = 18

Then update the program, such that, it get the start value from user and print table from start-value to end-value.

4. Get an integer from that represent a year, it must be greater than 500, if less, ask again until valid number is entered (hint: use loop to remain asking until valid number is given). Your program should print, is the year is leap or not.

A leap year is one which is evenly divided by 4. But for century years, the year must also be evenly divided by 400. e.g. 1800 is divisible at 4, but not leap because its a century year and is not evenly divisible at 400. So you must also check whether the user entered year is century year or not to decide correctly. (optional : also add 2-3 lines multi-line comment in your program that explains why we need leap years and why Feb days are 29 in leap year. see http://www.mathsisfun.com/leap-years.html).

5. Get an integer n from user. Print first n prime numbers.

6. Declare and initialize byte, short, int, float, long, double, boolean type variables using literals, change those values by user input and then print all of 8 variables on input console using format specifiers.

7. Get 5 digits integer number from user input and print each digits on a separate line.

8. Get a double vaue from user and print its sin, cos, tan, ceiling, floor, log, etc. using different functions of Math class. See this link for function names: https://docs.oracle.com/javase/7/docs/api/java/lang/Math.html

9. User java.util.Random class's nextInt(int n) method to generate a random number between 0 to (n-1). To roll a dice 1000 times. and print the average number you get. Print number int value using some function of Math class.


Popular posts from this blog

Task 12 - Create Java Program with MySQL Database Connectivity

Java Interfaces and Exception Handling - Practice Problem with Solution

Task 16 - Javafx Program to Create, Retrieve, Update and Delete records with Database