Home‎ > ‎CIS36A‎ > ‎CIS-36A-Schedule‎ > ‎

allassignments

Assignment 4.1: About My Friend (10 pts)

  • Open up a new Java project in Eclipse.
  • Name the project friend
  • Add a new class to your project also named Friend
  • Inside of Friend.java, write your name and section info at the very top of the file by placing them inside of a multi-line comment, like so:
/**
* @author Your Name Here
* @author Your Partner's Name (optional)
* CIS 36A, Assignment 4.1
*/
  • The objective of your program is to store some values in a variable and then print those values to the console.
  • Now, declare 5 new variables at the top of your program
  1. One integer
  2. Two chars
  3. One double
  4. One boolean
  • The integer variable will be used to store the number of years you have known your friend. Give it an appropriate name of your choice.
  • The char variable will be used to store the first initial of your friend's first name. Give it an appropriate name of your choice.
  • The other char variable will be used to store the first initial of your friend's last name. Give it an appropriate name of your choice.
  • The double variable will be used to store your friend's age. Give it an appropriate name of your choice.
  • The boolean variable will be used to store whether you plan friend is also a student at de Anza.
  • Next, assign the correct value to each of these variables. You many do this on the same line in which you declared the variables, or on a separate line.
  • For example, you might have a statement that looks like this:

int numYears = 5;

  • Or, you might have 2 statements that look like this:

int numYears;
numYears = 5;
  • Both options are correct.
  • Next, you will print out the contents of these variables using System.out.print() statements.
  • You need one System.out.println statement per variable.
  • statement 1 should say: I have known my friend for <number of years here> years.
  • statement 2 should say: My friend's initials are: <initials here>
  • statement 3 should say: My friend is <age here> years old.
  • statement 4 should say: My friend is also a student at de Anza: <true or false here>
  • Thus, when your program is run, the output should be identical to the following (except your information will be below, not my sample information):
I have known my friend for 5 years.
My friend's initials are: KZ
My friend is 19.0 years old.
My friend is also a student at de Anza: true
  • When you are finished, and your output is identical to the sample output above (but with your information, not mine), submit the Friend.java file to Canvas.
  • Reminder: Look under workspace -> student -> src  -> Friend.java


Assignment 4.2: Tallest Mountains in Our Solar System (10 pts)

highest mountains in solar system

  • Open up Eclipse.
  • Open a project named mountains and create a Java file called Mountains.java
  • Put a block comment at the start of your program with your name and section information (@author)
  • Write your main method
  • Declare a variable called rheasilvia and assign it the value 22000 (meters)
  • Declare a variable called olympusMons and assign it the value 21230 (meters)
  • Declare a variable called maunaKea and assign it the value 10200 (meters)
  • Declare a variable called mtEverest and assign it the value 5200 (meters)
  • Run the program and verify that there are no errors.
  • Now, add four print statements to display the names and locations of the above four mountains, along with their heights.
  • When you run your program, you should now see the following displayed:
Rheasilvia, on the asteroid Vesta, is 22000 meters tall.
Olympus Mons, on Mars, is 21230 meters tall.
Mauna Kea, on Earth, is 10200 meters tall.
Mt Everest, on Earth, is 5200 meters tall.
  • Note that you want to print out the rheasilvia, olympusMons, maunaKea, and mtEverest variables inside your print statement. Therefore, this should NOT be one of your print statements:

System.out.println("Rheasilvia, on the asteroid Vesta, is 22000 meters tall."); <--don't do this!!!

  • How can you change the above print statement to replace the number 22000 with the rheasilvia variable?
  • Now, add two more variables and assign them the following values:
int diffRheaMauna = rheasilvia - maunaKea; //11800
int diffRheaEverest = rheasilvia - mtEverest; //16800

  • Note that in the first statement above, you are calculating the difference in height between Rheasilvia and Mauna Kea, and assigning the resulting number to a variable named diffRheaMauna.
  • Likewise, in the second statement, you are calculating the difference in height between Rheasilvia and Mt Everest, and assigning the resulting number to a variable named diffRheaEverest.
  • Finally, display the differences between the Rheasilvia (the highest mountain in our solar system) and the two tallest mountains on earth, by adding an additional print statement that displays the values of the two new variables along with the following message:
Rheasilvia is 11800 meters taller than Mauna Kea and 16800 meters taller than Mt Everest.
  • Note that you should use the above diffRheaMauna and diffRheaEverest variables in the above print statement.
  • No credit if you do not use the variables inside of your System.out.println statements.
  • Submit your program to Canvas when you are finished.
  • Reminder: Look under workspace -> mountains -> src  -> Mountains.java

Output of your program should be *identical* to the output below:

Rheasilvia, on the asteroid Vesta, is 22000 meters tall.
Olympus Mons, on Mars, is 21230 meters tall.
Mauna Kea, on Earth, is 10200 meters tall.
Mt Everest, on Earth, is 5200 meters tall.
Rheasilvia is 11800 meters taller than Mauna Kea and 16800 meters taller than Mt Everest.
Comments