Explore BrainMass
Share

Explore BrainMass

    Java code errors

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    1. What are the errors in the following codes: What would correct the errors?

    A.) if ( age >= 65 ) ;
    System.out.println( "Age greater than or equal to 65" );

    else

    System.out.println( "Age is less than 65 )";

    B.) int x = 1, total;
    while ( x <= 10 )
    {

    Total += x;
    ++x;

    }

    C.) while ( x <= 100 )
    total += x;

    ++x;

    D.) while ( y > 0 )
    {

    System.out.println( y );
    ++y;

    _________________________________________________________________________

    2. Drivers are concerned with the mileage their automobiles get. One of my drivers has kept track of several tankfuls of the gas he used and recorded the miles driven and gallons used for each tankful. I need help developing a JAVA application that will input the miles driven and gallons used(both as integers) for each thankful. The program should calculate and display the miles per gallon obtained for each thankful and print the combined miles per gallon obtained for all tankfuls up to this point. All averaging calculations should produce floating-point results. Use class Scanner and sentinel-controlled repetition to obtain the data from the user.
    __________________________________________________________________________

    3.) A large company pays its salespeople on a commission basis. The salespeople receive $200 per week plus %9 of their gross sales for that week. An example of this would be "a salesperson who sells $5000 worth of merchandise in a week receives $200 plus %9 of $5000 or a total of $650. I have been supplied with a list of the items sold by each salesperson. The value of these items are listed below:

    Item Value
    1 239.99
    2 129.75
    3 99.95
    4 350.89

    I need help developing a Java application that inputs one salesperson's items sold for last week and calculates and displays that salesperson's earnings. There is no limit to the number of items that can be sold by a salesperson.

    © BrainMass Inc. brainmass.com October 9, 2019, 10:55 pm ad1c9bdddf
    https://brainmass.com/computer-science/java/java-code-errors-237460

    Solution Preview

    Hello student,
    I have completed and attached the solution.

    Java code errors
    1. What are the errors in the following codes: What would correct the errors?

    A.) if ( age >= 65 ) ;
    System.out.println( "Age greater than or equal to 65" );

    else

    System.out.println( "Age is less than 65 )";

    Ans : Errors :
    i) Semi colon in if statement
    ii) Double quotes outside the System.out.println()
    Corrections :
    if ( age >= 65 )
    System.out.println( "Age greater than or equal to 65" );

    else

    System.out.println( "Age is less than 65" );

    B.) int x = 1, total;
    while ( x <= 10 )
    {

    Total += x;
    ++x;

    }
    Ans : Error :
    The variable Total is used in place of total
    Corrections :
    int x = 1, total;
    while ( x <= 10 )
    {

    total += x;
    ++x;

    }

    C.) while ( x <= 100 )
    total += x;

    ++x;

    Ans : The x value is incremented after the while loop. So the loop continues its ...

    Solution Summary

    The expert finds Java code errors.

    $2.19