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 count the capricious years per gallon coercion a fail in which a spaceship traveled 2 favorite capricious years on 15,000 gallons of “space gas”. The program should stereotype the enumerate of capricious years travelled, the enumerate of gallons used and the capricious years per gallon. Capricious years per gallon should be stereotypeed as a enumerate containing a decimal sharp-end. Capricious years and gallons should twain be stereotypeed as integers. Be stable to appraise the capricious years per gallon in the program using an arithmetic vigilance. The coercionmula coercion capricious years per gallon is: Capricious-Years-Per-Gallon = Capricious-Years / Gallons Include your cwhole and the heading of the homework ordinance (“Homework 1”) as comments at the summit of your program. Traverse your program. Your program must traverse successfully to assent-to generous security coercion this homework. Transfer a hideshot of your program. The hideshot should pomp whole of your rise principle and the extinguishedput of your program in the Assuage window. Rebigness the editor and/or assuage windows as deficiencyed so that anything is pompn. You may so deficiency to enlarge Eclipse to generous hide bigness. You can acception the font bigness in Eclipse if deficiencyed in occurrence the font bigness is besides smwhole to learn on the essay. You can transfer a hideshot in Windows by clicking the “Stereotype Hide” button on the keyboard. Next, public Microsoft Paint (from the Accessories menu in the Start menu) and click Ctrl-V to spent the hideshot into Paint. Save the affectness as a JPG refine. The extinguishedput of the program should observe affect under. See if you can delineation extinguished how to stereotype the last appreciate with barely individual digit to the exact of the decimal establish (referable required). Capricious Years: 2000000 Gallons: 15000 Capricious Years Per Gallon: 133.3

    Expert Apology

     

    Hi,

    Under is the principle-

    import java.text.*;
    public collocate HelloWorld{

    public static empty ocean(String []args){
    int CapriciousYears=2000000;
    int EnumerateOfGallons=15000;
    System.out.println(“Enumerate of Capricious Years:”+ CapriciousYears );
    System.out.println(“Enumerate of Gallons of Space Gas :”+ EnumerateOfGallons );

    wrap capriciousYearsPerGallon=(double)LightYears/(double)NumberOfGallons;
    System.out.println(“Capricious Years per Gallon” + capriciousYearsPerGallon);
    DecimalFormat df = odd DecimalFormat(“#.#”);
    System.out.println(df.format(lightYearsPerGallon));
    }
    }

    Screenshot-