hts.StevenWood.com

Lab Exercises Assignments

Home ] Up ] How to use Methods in Java ] Methods and Parameters in Java ] Creating User-Defined Methods ] Common Programming Errors ] Good Programming Practices ] [ Lab Exercises ] Labs 1 ] Labs 2 ] Rubric ][ Last Page ]

Lab Exercises Assignment

Complete the following programs in Java. Send your solutions to Mr. Wood.

This assignment is due before next class.

1.

Write a program in Java that asks the user to input:

  • The make and model of car.
  • The number of litres of gas in the tank when full.
  • The fuel efficiency in litres per 100 km.
  • The price of gas per litre.

Use methods to calculate the following items:

  1. how far the car can go with a tank of gas, and
  2. the cost per 100 km of travel.

Display your calculations in a manner VERY similar to what follows.
The highlighted items are entered by the user or calculated by the code:

The Nissan Altima holds 100 litres of gas.
This car can go 840 km on a tank of gas.
It costs $15.34 to drive 100 km.


2.

Write a Java Program which prompts the user to enter 4 numbers.

Create two methods, one that will compute their sum and another that will compute their product.

Enter the numbers from the main method, use the two methods described above and display the results (from the main method).

 


 
Home ] Up ] How to use Methods in Java ] Methods and Parameters in Java ] Creating User-Defined Methods ] Common Programming Errors ] Good Programming Practices ] [ Lab Exercises ] Labs 1 ] Labs 2 ] Rubric ][Last Page]
All material on this site is copyright © 1997- by Steven Wood or as credited. All right reserved. Use of this site indicates you agreement with the  terms of use.
Send comments or questions to about this page.
Every attempt has been made to credit work under copyright. If there are any claims that copyright has been missed please contact the .
+SDG+