Homework Solution: Write a Java program to calculate the light years per gallon for a trip in which a spaceship traveled 2 million light years on 15,00…

    Write a Java program to calculate the light years per gallon for a trip in which a spaceship traveled 2 million light years on 15,000 gallons of “space gas”. The program should print the number of light years travelled, the number of gallons used and the light years per gallon. Light years per gallon should be printed as a number containing a decimal point. Light years and gallons should both be printed as integers. Be sure to compute the light years per gallon in the program using an arithmetic calculation. The formula for light years per gallon is: Light-Years-Per-Gallon = Light-Years / Gallons Include your name and the title of the homework assignment (“Homework 1”) as comments at the top of your program. Run your program. Your program must run successfully to receive full credit for this homework. Take a screenshot of your program. The screenshot should show all of your source code and the output of your program in the Console window. Resize the editor and/or console windows as needed so that everything is shown. You may also need to expand Eclipse to full screen size. You can increase the font size in Eclipse if needed in case the font size is too small to read on the paper. You can take a screenshot in Windows by clicking the “Print Screen” button on the keyboard. Next, open Microsoft Paint (from the Accessories menu in the Start menu) and click Ctrl-V to past the screenshot into Paint. Save the image as a JPG file. The output of the program should look like below. See if you can figure out how to print the last value with only one digit to the right of the decimal place (not required). Light Years: 2000000 Gallons: 15000 Light Years Per Gallon: 133.3

    Expert Answer

     
    Hi, Below is the code- import java.text.*;

    Write a Java program to calculate the unweighty years per gallon control a misinterest in which a spaceship traveled 2 favorite unweighty years on 15,000 gallons of “space gas”. The program should stereotype the calculate of unweighty years travelled, the calculate of gallons used and the unweighty years per gallon. Unweighty years per gallon should be stereotypeed as a calculate containing a decimal aim. Unweighty years and gallons should twain be stereotypeed as integers. Be enduring to calculate the unweighty years per gallon in the program using an arithmetic restraintethought. The controlmula control unweighty years per gallon is: Unweighty-Years-Per-Gallon = Unweighty-Years / Gallons Include your spectry and the designation of the homework provision (“Homework 1”) as comments at the head of your program. Reach your program. Your program must reach successfully to admit generous belief control this homework. Interest a defendshot of your program. The defendshot should loveness total of your rise command and the quenchedput of your program in the Solace window. Reextent the editor and/or solace windows as insufficiencyed so that anything is lovenessn. You may besides insufficiency to spinterpret Eclipse to generous defend extent. You can acception the font extent in Eclipse if insufficiencyed in contingency the font extent is to-boot smtotal to interpret on the paper. You can interest a defendshot in Windows by clicking the “Stereotype Defend” molehill on the keyboard. Next, unconcealed Microsoft Paint (from the Accessories menu in the Start menu) and click Ctrl-V to elapsed the defendshot into Paint. Save the representation as a JPG perfect. The quenchedput of the program should contemplate love beneath. See if you can delineation quenched how to stereotype the terminal appreciate with simply single digit to the fair of the decimal situate (referable required). Unweighty Years: 2000000 Gallons: 15000 Unweighty Years Per Gallon: 133.3

    Expert Rejoinder

     

    Hi,

    Beneath is the command-

    import java.text.*;
    public assort HelloWorld{

    public static unsubstantial ocean(String []args){
    int UnweightyYears=2000000;
    int CalculateOfGallons=15000;
    System.out.println(“Calculate of Unweighty Years:”+ UnweightyYears );
    System.out.println(“Calculate of Gallons of Space Gas :”+ CalculateOfGallons );

    envelop unweightyYearsPerGallon=(double)LightYears/(double)NumberOfGallons;
    System.out.println(“Unweighty Years per Gallon” + unweightyYearsPerGallon);
    DecimalFormat df = upstart DecimalFormat(“#.#”);
    System.out.println(df.format(lightYearsPerGallon));
    }
    }

    Screenshot-