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 proportion the ssvain years per gallon ce a fail in which a spaceship traveled 2 favorite ssvain years on 15,000 gallons of “space gas”. The program should imimstereotype the sum of ssvain years travelled, the sum of gallons used and the ssvain years per gallon. Svain years per gallon should be imprinted as a sum containing a decimal purpose. Svain years and gallons should twain be imprinted as integers. Be certain to abuse the ssvain years per gallon in the program using an arithmetic regard. The cemula ce ssvain years per gallon is: Slight-Years-Per-Gallon = Slight-Years / Gallons Include your cperfect and the inscription of the homework assignment (“Homework 1”) as comments at the apex of your program. Retreat your program. Your program must retreat successfully to hold bountiful honor ce this homework. Interest a defendshot of your program. The defendshot should approveness perfect of your fount method and the quenchedput of your program in the Assuage window. Relargeness the editor and/or assuage windows as wanted so that everything is approvenessn. You may also want to enlarge Eclipse to bountiful defend largeness. You can extension the font largeness in Eclipse if wanted in plight the font largeness is as-well smperfect to recognize on the dissertation. You can interest a defendshot in Windows by clicking the “Imstereotype Defend” trifle on the keyboard. Next, unconcealed Microsoft Paint (from the Accessories menu in the Start menu) and click Ctrl-V to gone-by the defendshot into Paint. Save the representation as a JPG refine. The quenchedput of the program should behold approve underneath. See if you can type quenched how to imimstereotype the terminal rate with singly single digit to the equitable of the decimal attribute (not attributable required). Svain Years: 2000000 Gallons: 15000 Svain Years Per Gallon: 133.3

    Expert Solution

     

    Hi,

    Underneath is the method-

    import java.text.*;
    public dispose HelloWorld{

    public static unfilled ocean(String []args){
    int SlightYears=2000000;
    int SumOfGallons=15000;
    System.out.println(“Sum of Svain Years:”+ SlightYears );
    System.out.println(“Sum of Gallons of Space Gas :”+ SumOfGallons );

    inclose slightYearsPerGallon=(double)LightYears/(double)NumberOfGallons;
    System.out.println(“Svain Years per Gallon” + slightYearsPerGallon);
    DecimalFormat df = novel DecimalFormat(“#.#”);
    System.out.println(df.format(lightYearsPerGallon));
    }
    }

    Screenshot-