CS 111A Lecture Notes - Calculations - Chapter 2 part 2

Primitive Datatypes

Calculations, Assignments

Shortcut Operators

Formatting Output using printf

  • In-class exercise 1: Write a program that has the user enter 3 numeric homework grades, and outputs their average. Make sure to use a floating point data type for the grades. Use "printf" to show the average rounded to the nearest tenth (showing just 1 digit after the decimal point)
  • GradeAverage.java: Solution to above in-class exercise averaging grades

    Mathematical Functions (Methods)

    Type Casting

    Constants

    In-class exercise 2: You're planning a wedding, and you need to transport all your wedding guests from the ceremony to the reception. A bus can carry 40 passengers. Your program should ask the user how many guests are expected, and it should output how many busses are needed, and the number of extra people you could carry with those busses. You may find it helpful to use the Math.ceil method (which rounds a double up to the next higher integer)

    Busses.java: Solution to above in-class exercise

    Reference Variables, Memory Allocation, and Variable Scope

    String methods

    Return to CS 111A page