عرض مشاركة واحدة
منتديات طلاب وطالبات جامعة الملك عبد العزيز منتديات طلاب وطالبات جامعة الملك عبد العزيز
قديم 28-09-2012, 12:24 PM   #4

Amo0ol-92

جامعي

 
تاريخ التسجيل: Jul 2010
التخصص: IS
نوع الدراسة: إنتظام
المستوى: السابع
الجنس: أنثى
المشاركات: 57
افتراضي رد: مساعدة في برمجة 202

السؤال الثاني بأحط لك الحل وانتِ فهميه نفسك هو سهل و واضح بس تشوفي الحل بتفهميه ان شاءالله

Solution:

Problem Analysis Chart:

Given Data Required Results
radiusInInches
depthInFeet
CUBIC_FEET_PER_GALLON = 7.48
PI = 3.14159 gallons
Processing Required Solution Alternatives
radiusInFeet = radiusInInches / 12
volumeOfWell =
galons = volumeOfWell * CUBIC_FEET_PER_GALLON = 7.48
gallons = (int) ((Math.PI * (radius / 12.0) * (radius / 12.0) * depth) * CUBIC_FEET_PER_GALLON);


Algorithm:

1. Readradius from user.
2. Read depth from user.
3. Read Age from user.
4. Convert entered radius from inches to feet.
5. Calculate volume of well.
6. Calculate number of gallons in well.
7. Display number of gallons in well.









Sample Code Solution:

Solution:

import java.util.Scanner;

public class WaterWell
{
public static final double CUBIC_FEET_PER_GALLON = 7.48;

public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int radius;
int depth;
int gallons; // This could be a double, it's not specified in the problem

System.out.println("This program calculates how much water will be available in a well.");
System.out.println("What is the radius of the casing in inches?");
radius = keyboard.nextInt();
System.out.println("What is the depth of the well in feet?");
depth = keyboard.nextInt();

// Compute gallons, first converting the radius to feet, then computing the volume
// and multiplying by the conversion factor of cubic feet to gallons
gallons = (int) ((Math.PI * (radius / 12.0) * (radius / 12.0) * depth) * CUBIC_FEET_PER_GALLON);

System.out.println("The well contains " + gallons + " gallons.");
}
}

 

Amo0ol-92 غير متواجد حالياً   رد مع اقتباس