Java Programming | Catalog Display

Introduction

This is a program to calculate the number of pages required for displaying given number of products if number of products to be displayed on one page is given. The program is not extendable but it can be used in web-pages for pagination. Go enjoy the program. Lets begin…..

Program for catalog display in java.

//import Scanner as we require it.
import java.util.Scanner;

// the name of our class its public
public class CatalogDisplay {
	//void main
		public static void main (String[] args)
		{
			//declare int
			int a,b,c,d;

			//Declare input as scanner
			Scanner input = new Scanner(System.in);

			//Take inputs
			 System.out.println("Enter no. of products to be displayed on one page:");
			 a = input.nextInt();
			 System.out.println("Enter no of products:");
		     b = input.nextInt();

		     //calculate
		     c=b%a;

		     if(c==0)
		    	d=b/a;
		     else
		     {
		    	d=b/a;
		    	d=d+1;
		     }

		     //print
		     System.out.println("No of pages required :"+ d);
		}
}

Output

Enter no. of products to be displayed on one page:
10
Enter no of products:
56
No of pages required :6

How does it work

  1. You enter the no. of products on one page
  2. You enter the no. of products.
  3. The mod is calculated.
  4. The conditional statement calculates the no of pages required.
  5. No. of pages required is printed on screen.

Extending it.

The program is not extendable. However, it can be used in web-pages for pagination.

Explanation.

  1. Import the Scanner.
  2. Declare the class as public
  3. Add the void main function
  4. Add system.out.println() function with the message to necessary inputs.
  5. Declare input as Scanner.
  6. Take the inputs and save it in variables.
  7. Calculate mod and save it in variable.
  8. Add a if-else statement
  9. Calculate the no of pages required and save it in variable.
  10. Add system.out.println() function to print the no of pages required.

At the end.

You learnt creating the Java program for Catalog Display. So now enjoy the program.

Please comment on the post and share it.
And like it if you liked.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s