[Question 1] ISC 2017 Computer Practical Paper Solved – Box Packing

Question:

A company manufactures packing cartons in four sizes, i.e. cartons to accommodate 6 boxes, 12 boxes, 24 boxes and 48 boxes. Design a program to accept the number of boxes to be packed (N) by the user (maximum up to 1000 boxes) and display the break-up of the cartons used in descending order of capacity (i.e. preference should be given to the highest capacity available, and if boxes left are less than 6, an extra carton of capacity 6 should be used.)
Test your program with the sample data and some random data:
Example 1
INPUT : N = 726
OUTPUT :
48 x 15 = 720
6 x 1 = 6
Remaining boxes = 0
Total number of boxes = 726
Total number of cartons = 16
Example 2
INPUT : N = 140
OUTPUT :
48 X 2 = 96
24 x 1 = 24
12 x 1 = 12
6 x 1 = 6
Remaining boxes 2 x 1 = 2
Total number of boxes = 140
Total number of cartons = 6
Example 3
INPUT : N = 4296
OUTPUT : INVALID LENGTH

SOURCE CODE


import java.io.*;
import java.util.*;
public class ISC2017_BoxPacking
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter number of boxes to be packed    :");
        int nn=sc.nextInt();
        int c=0,total=0,n=nn;
        if(n>1000||n<1)
        {
            System.out.println("INVALID INPUT");
        }
        else
        {
            if(n>=48)
            {
                c=n/48;
                n=n%48;
                total=total+c;
                System.out.println("48*"+c+"="+(c*48));
            }
            if(n>=24&&n<48)
            {
                c=n/24;
                n=n%24;                
                total=total+c;
                System.out.println("24*"+c+"="+(c*24));
            }
            if(n>=12&&n<25)
            {           
                c=n/12;
                n=n%12;
                total=total+c;
                System.out.println("12*"+c+"="+(c*12));
            }
            if(n>=6&&n<12)
            {
                c=n/6;
                n=n%6;
                total=total+c;
                System.out.println("6*"+c+"="+(c*6));                
            }
            System.out.println("Remaining boxes "+n+"*1="+n);
            System.out.println("Total number of boxes = "+nn);
            System.out.println("Total number of curtons = "+total);
        }
    }
}


OUTPUT





If you have any question then leave a comment below I will do my best to answer that question.

Comments

Popular posts from this blog

[Question 3] ISC 2017 Computer Practical Paper Solved – Caesar Cipher.

Pattern of your own name.

Designing Patterns - Print 'Z'.