Northwood
Slavan
- Učlanjen(a)
- 09.10.2005
- Poruke
- 1,822
- Poena
- 349
OK, potrebna mi je pomoc oko programiranja jednog programcica 😉
Dobio sam zadatak da odradim program koji ce da preracuna broj milja u svetlosne godine i AU (Astronomical Unit) i da to prikaze na odredjen nacin...
Ukoliko nekoga ne mrzi da procita ovo i da mi pomogne
imam problem sa konverzacijom (sta da postavim tacno kao operand-e i output) 😀
za sada kod izgleda ovako
ako sam izostavio nesto samo recite...
Hvala
Dobio sam zadatak da odradim program koji ce da preracuna broj milja u svetlosne godine i AU (Astronomical Unit) i da to prikaze na odredjen nacin...
Ukoliko nekoga ne mrzi da procita ovo i da mi pomogne
Purpose: A light year is the distance in which light can travel in a vacuum in the course of one year. It is a unit of measure that helps scientists to measure distances in the universe where distances are very large. One light year is 5,850,000,000,000 miles (or 5.85* 1012). (from HowStuffWorks.com)
Astronomical units (AU) are used to measure distances within our solar system and refer to the average distance between earth and sun. One light year = 63,239.7 AU.
Your task is to develop an application that will calculate the number of astronomical units and light years from earth to various bodies in the universe given the number of miles to that body.
Program Behavior
Your application must do these things:
1. Your program will prompt for and read in two input value; the name of the celestial body we are working with and the distance in miles from earth to the given body.
2. Your program will calculate the appropriate light years and AUs to that body.
3. Your program must display these results.
Output
1. Output the heading, “Welcome to the CS139 Universe Distance Calculator” followed by the two newline characters.
2. Your first input prompt must be the string, “Type the name of the astronomical body: “
3. You must output a new line character after the user has typed in the name.
4. Your second input prompt must be the String, name " is how many miles away? ", where name is the response to the first prompt.
5. You must output a new line character after the user has typed in a name.
6. Your final output line must be preceded by one line of blank space and then must be of the form:
"%s is %.2f light years and %.2f astronomical units from Earth\n",
where the first substitution is the name of the body, the second is the number of light years and the final substitution is the number of AUs.
Example Output
Kod:Welcome to the CS139 Universe Distance Calculator Type the name of the astronomical body: Alpha Centauri Alpha Centauri is how many miles away? 25155000000000 Alpha Centauri is 4.30 light years and 271930.71 astronomical units from Earth.
Additional Program Requirements
1. You must use variables for the values of the input parameters.
2. You must use constants for the two conversion factors.
3. Numbers displayed as output should be output with 2 decimal points and no commas.
4. All divisions carried out should be floating point division regardless of the data type of the operands.
5. Your program must include an acknowledgement section acknowledging help received from TAs or reference sources. You do not need to reference receiving help from the instructor. See this course's Style Guide for other style criteria.
6. If you received no help your acknowledgement section should have a statement to that effect.
7. Your program must conform to standard Java programming standards and the additional standards for this class. See the Style Guide for this class.
imam problem sa konverzacijom (sta da postavim tacno kao operand-e i output) 😀
za sada kod izgleda ovako
Kod:
import java.util.Scanner;
public class HowFarIsIt
{
/********************************************
* main method documentation goes here. What does
* this method do
*
* @param args Unused in this application
********************************************/
public static void main (String args [])
{
String aBody; // User input
String miles; // Number of miles as a literal
float numOfMil; // Number of miles as a number
float lY; // Light Years
float aU; // Astronomical Units
Scanner keyboard = new Scanner(System.in);
System.out.println("Welcome to the CS139 Universe Distance Calculator");
System.out.println("\n");
System.out.println("\n");
System.out.print("Type the name of the astronomical body: ");
aBody = keyboard.nextLine();
System.out.println("\n");
System.out.print(aBody + " is how many miles away? ");
miles = keyboard.nextLine();
numOfMil = Float.parseFloat(miles);
System.out.println("\n");
System.out.println("\n");
// ACTION CODE:
}
}
ako sam izostavio nesto samo recite...
Hvala