Purchase Solution

Java code errors

Not what you're looking for?

Ask Custom Question

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.

Purchase this Solution

Solution Summary

The expert finds Java code errors.

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 ...

Purchase this Solution


Free BrainMass Quizzes
Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

C# variables and classes

This quiz contains questions about C# classes and variables.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.