مبتعث جديد New Member
السعودية
صبر بلاحدود , أنثى. مبتعث جديد New Member. من السعودية
, مبتعث فى السعودية
, تخصصى العلوم
, بجامعة جامعة
- مكة, مكة
- السعودية
- Nov 2012
المزيدl November 9th, 2012, 12:51 AM
November 9th, 2012, 12:51 AM
حل هذي الاسئلة ضروري وباسرع وقت..
Problem 1:
Write a program that asks the user to enter a favorite color, a favorite food, a favorite animal, and the first name of a friend or relative. The program should then print the following two lines, with the user’s input replacing the items in italics: I had a dream that Name ate a Color Animal and said it tasted like Food!
For example, if the user entered blue for the color, hamburger for the food, dog for the animal, and Jake for the person’s name, the output would be
I had a dream that Jake ate a blue dog and said it tasted like hamburger!
Don’t forget to put the exclamation mark at the end.
Notes:
This project requires careful attention to spaces in output messages. In particular, a space must be explicitly printed between the variables color and animal.
Solution: as an example
Problem Analysis Chart:
Given Data | Required Results |
name
color
animal
food | Print “I had a dream that Name ate a Color Animal and said it tasted like Food!" |
Processing Required | Solution Alternatives |
System.out.println("I had a dream that " + name + " ate a " + color + " " + animal); System.out.println("and said it tasted like " + food + "!"); | |
Algorithm:
- Read Name from user.
- Read Color from user.
- Read Animal from user.
- Read Food from user.
- Display message “I had a dream that Name ate a Color Animal and said it tasted like Food!"
Sample Code Solution:
From now on to the end of your four year program here at the University, every program you submit whether it is in lab or as homework should include the following:
- File name
- Full description of the coded program
- Author: Name of student
- Student ID
- Student email address
- Date submitted
/** File name: SillySentence.java This program does the following: Prompts the user to enter a friend's or relative's name, a favorite color, a favorite food, and a favorite animal. Prints the following sentence with the user's input inserted: I had a dream that NAME ate a COLOR ANIMAL and said it tasted like FOOD! Author: Lew Rakocy email address: LRakocy@devrycols.edu Date: 8/13/2000 */ import java.util.*; public class SillySentence { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.println("Enter the name of someone you know:"); String name = keyboard.nextLine(); System.out.println("Enter your favorite color: "); String color = keyboard.nextLine(); System.out.println("Enter your favorite food: "); String food = keyboard.nextLine(); System.out.println("Enter your favorite animal: "); String animal = keyboard.nextLine(); System.out.println("I had a dream that " + name + " ate a " + color + " " + animal); System.out.println("and said it tasted like " + food + "!"); } } |
Problem 2:
The Harris-Benedict equation estimates the number of calories your body needs to maintain your weight if you do no exercise. This is called your basal metabolic rate or BMR.
The calories needed for a woman to maintain her weight is:
BMR = 655 + (4.3 * weight in pounds) + (4.7 * height in inches) - (4.7 * age in years)
The calories needed for a man to maintain his weight is:
BMR = 66 + (6.3 * weight in pounds) + (12.9 * height in inches) - (6.8 * age in years)
A typical chocolate bar will contain around 230 calories. Write a program that allows the user to input their weight in pounds, height in inches, and age in years. The program should then output the number of chocolate bars that should be consumed to maintain one’s weight for both a woman and a man of the input weight, height, and age.
Notes:
This project gives the student practice with numerical calculations and simple input/output. For a slightly more challenging problem allow the height to be entered in feet and inches and have the program convert to inches.
1 kg = 2.2046226218487757 pounds
1 m = 39.37007874015748 inches
Problem 3:
Many private water wells produce only 1 or 2 gallons of water per minute. One way to avoid running out of water with these low-yield wells is to use a holding tank. A family of 4 will use about 250 gallons of water per day. However, there is a “natural” water holding tank in the casing (i.e. the hole) of the well itself. The deeper the well, the more water that will be stored that can be pumped out for household use. But how much water will be available?
Write a program that allows the user to input the radius of the well casing in inches (a typical well will have a 3 inch radius) and the depth of the well in feet (assume water will fill this entire depth, although in practice that will not be true since the static water level will generally be 50 feet or more below the ground surface). The program should output the number of gallons stored in the well casing. For your reference:
The volume of a cylinder is [IMG]file:///C:\Users\Hp\AppData\Local\Temp\msohtmlclip1\01\cli p_image001.png[/IMG] where r is the radius and h is the height.
1 cubic foot = 7.48 gallons of water.
For example, a 300 foot well full of water with a radius of 3 inches for the casing holds about 441 gallons of water -- plenty for a family of 4 and no need to install a separate holding tank.
Notes:
This project gives the student practice with numerical calculations and simple input/output. Introduces problem solving with relatively straightforward conversion of units. Students are likely to encounter data type conversion issues from double to int and vice versa (e.g. radius / 12 will result in 0 if radius is an int).
والباقي في المرفق اذا سمحتوااا
November 9th, 2012, 12:51 AM
حل هذي الاسئلة ضروري وباسرع وقت..Write a program that asks the user to enter a favorite color, a favorite food, a favorite animal, and the first name of a friend or relative. The program should then print the following two lines, with the user’s input replacing the items in italics: I had a dream that Name ate a Color Animal and said it tasted like Food!
For example, if the user entered blue for the color, hamburger for the food, dog for the animal, and Jake for the person’s name, the output would be
I had a dream that Jake ate a blue dog and said it tasted like hamburger!
Don’t forget to put the exclamation mark at the end.
Notes:
This project requires careful attention to spaces in output messages. In particular, a space must be explicitly printed between the variables color and animal.
Solution: as an example
Problem Analysis Chart:
color
animal
food
Algorithm:
Sample Code Solution:
From now on to the end of your four year program here at the University, every program you submit whether it is in lab or as homework should include the following:
File name: SillySentence.java
This program does the following:
Prompts the user to enter a friend's or relative's name,
a favorite color, a favorite food, and a favorite animal.
Prints the following sentence with the user's input inserted:
I had a dream that NAME ate a COLOR ANIMAL and said
it tasted like FOOD!
Author: Lew Rakocy
email address: LRakocy@devrycols.edu
Date: 8/13/2000
*/
import java.util.*;
public class SillySentence
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the name of someone you know:");
String name = keyboard.nextLine();
System.out.println("Enter your favorite color: ");
String color = keyboard.nextLine();
System.out.println("Enter your favorite food: ");
String food = keyboard.nextLine();
System.out.println("Enter your favorite animal: ");
String animal = keyboard.nextLine();
System.out.println("I had a dream that " + name
+ " ate a " + color + " " + animal);
System.out.println("and said it tasted like " + food + "!");
}
}
Problem 2:
The Harris-Benedict equation estimates the number of calories your body needs to maintain your weight if you do no exercise. This is called your basal metabolic rate or BMR.
The calories needed for a woman to maintain her weight is:
BMR = 655 + (4.3 * weight in pounds) + (4.7 * height in inches) - (4.7 * age in years)
The calories needed for a man to maintain his weight is:
BMR = 66 + (6.3 * weight in pounds) + (12.9 * height in inches) - (6.8 * age in years)
A typical chocolate bar will contain around 230 calories. Write a program that allows the user to input their weight in pounds, height in inches, and age in years. The program should then output the number of chocolate bars that should be consumed to maintain one’s weight for both a woman and a man of the input weight, height, and age.
Notes:
This project gives the student practice with numerical calculations and simple input/output. For a slightly more challenging problem allow the height to be entered in feet and inches and have the program convert to inches.
1 kg = 2.2046226218487757 pounds
1 m = 39.37007874015748 inches
Problem 3:
Many private water wells produce only 1 or 2 gallons of water per minute. One way to avoid running out of water with these low-yield wells is to use a holding tank. A family of 4 will use about 250 gallons of water per day. However, there is a “natural” water holding tank in the casing (i.e. the hole) of the well itself. The deeper the well, the more water that will be stored that can be pumped out for household use. But how much water will be available?
Write a program that allows the user to input the radius of the well casing in inches (a typical well will have a 3 inch radius) and the depth of the well in feet (assume water will fill this entire depth, although in practice that will not be true since the static water level will generally be 50 feet or more below the ground surface). The program should output the number of gallons stored in the well casing. For your reference:
The volume of a cylinder is [IMG]file:///C:\Users\Hp\AppData\Local\Temp\msohtmlclip1\01\cli p_image001.png[/IMG] where r is the radius and h is the height.
1 cubic foot = 7.48 gallons of water.
For example, a 300 foot well full of water with a radius of 3 inches for the casing holds about 441 gallons of water -- plenty for a family of 4 and no need to install a separate holding tank.
Notes:
This project gives the student practice with numerical calculations and simple input/output. Introduces problem solving with relatively straightforward conversion of units. Students are likely to encounter data type conversion issues from double to int and vice versa (e.g. radius / 12 will result in 0 if radius is an int).
والباقي في المرفق اذا سمحتوااا