Expressions


Variables, Arithmetic Operators, and Expressions

VariableExample.java

ExpressionExample.java

More about % mod operator.

Deitel Chapter 2


Classwork

Note 1: I will not always bother telling you to do things that we always do.  We always need a netbeans project and in it a class with a main.

Note 2: Sometimes I will just tell you we need a variable for something, and it will be up to you to choose appropriate names and types.  If I explicitly give you a name or type for a variable, then part of the assignment is to use that name/type.


Part

In main  create two String variables, to hold a first name and last name (think about what you should name these variables). 

Assign the variables appropriate values (use a group member name or make one up).  (hint: people's names don't have extraneous spaces at the beginning or end)

Add a new double variable grade, representing the overall class grade, and assign it a value.

Now using the variables, print out something like

Constance de Coverlet is a Java student whose grade is 73.0%.
NOTE: when I give an example like this, it is intended to show the format, not the actual text. The first and last name you chose should appear instead of Constance and de Coverlet.

+ for concatenation is your friend. 

Remember that " " (the String consisting of a single space) is a valid string for concatenating, so 5+ " " + 17 ==> "5 17"

Go back before the printout you just wrote and add code with a new variable to hold the name of the course we are talking about.  Give it a value.  Change the printout you wrote to include the new variable so that instead of  "... is a Java student ..." it might say

Constance de Coverlet is a French Literature student whose grade is 73.0%.

Part B

Now add three new integer variables, h1, h2, and h3 representing homework grades.  Make up values for each.

Add a new double variable hAvg, and set it to the average of these grades. Print the result to make sure it makes sense. (Think about what problems we might have with division and make sure your code does it correctly.  hint: if you are getting a whole number for your average, try adjusting your grades up or down slightly.  Are you still getting a whole number?  Why might you get a whole number when you shouldn't?  How can you fix it?). 

Do the same for ints c1, c2,  c3, and double cAvg, representing classwork grades and their average.

Add a new integer variable tg, representing a test grade, make up a value for it.

  A weighted average is found by multiplying the average for each component by the weight for that component, and then adding up the results for all components.  If the course the student is taking has weights 40% classwork, 50% homework, and 10% test, change the value of the original grade variable to the weighted average based on hAvg, cAvg, and tg.  (hint: this says to change the value of the original grade variable.  Does that mean make a new variable with a different name?  no. Does that mean delete the previous lines with that variable? no.)

Put a copy of the previous printout  at the end of your code, and see if the final grade shown makes sense based on the values that went into your average. You should not have to change the printout, it will just print a new value for the existing grade variable.