COMPUTER PROGRAMMING ASSIGNMENT 1&2
INSTITUTE OF PUBLIC ADMINSTATION AND MANAGEMENT(IPAM
MODULE: COMPUTER PROGRAMMING
COURSE:BSC IN INFOMATION TECHNOLOGY
YEAR 1
BY: NAOMI BALAMA MOORE
A1) Your father is a civil engineer. Write a program that can assist your father to determine the quantity of tile needed for construction of any rectangular shape.
1, flowchart
2,pseudo code
3,code
ANSWER
1) FLOWCHAT
START
↓
Input Length of area (L)
↓
Input Width of area (W)
↓
Input Length of one tile (TL)
↓
Input Width of one tile (TW)
↓
Calculate Area of surface = L × W
↓
Calculate Area of one tile = TL × TW
↓
Number of tiles = Surface Area ÷ Tile Area
↓
Display Number of tiles
↓
END
2)PSEUDO CODE
BEGIN
INPUT length_of_area
INPUT width_of_area
INPUT tile_length
INPUT tile_width
area_of_surface = length_of_area * width_of_area
area_of_tile = tile_length * tile_width
number_of_tiles = area_of_surface / area_of_tile
PRINT number_of_tiles
END
3) JAVA CODE
import java.util.scanner;
class TileCalculation{
public static void main(Strang[] args){
Sanner input = new Scanner(System.in);
System.out.println("Enter the Length of the area");
double length = input.nextDouble();
System.out.println("Enter the Width of the area");
double width = input.nextDouble();
System.out.println("Enter the Length");
double tilelength = input.nextDouble();
System.out.println("Enter the Width");
double tilewidth = input.nextDouble();
double areasurface = length*width;
double areatile =tilelength * tilewidth
double numberoftile = areasurface / areatile
System.out.println("number of tile needed:"+ Math.ceil(numberofTiles);
input.close();
}
}
A2)Write a program that can calculate the area of any rectangular shape, given its length and width. Illustrates the working of the program using a flowchart. In brackets, skip conditional check for now by assuming all inputs are positive. Hint: Declare your variable as double. Use the next double method of the scanner class to accept the length and the width from the user.
ANSWER
FLOWCHART
START
↓
Input Length (L) [Assume L > 0]
↓
Input Width (W) [Assume W > 0]
↓
Area = L × W
↓
Display Area
↓
END
JAVA CODE
import java.util.Scanner;
public class RectangleArea {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double length;
double width;
double area;
System.out.print("Enter the length of the rectangle: ");
length = input.nextDouble();
System.out.print("Enter the width of the rectangle: ");
width = input.nextDouble();
area = length * width;
System.out.println("The area of the rectangle is: " + area);
input.close();
}
}
Comments
Post a Comment