CMPS 200 Homework Assignment 2, Fall 2016
American University of Beirut · Introduction to Programming · 2 pages · Dr. Ahmad Dhaini
More CMPS 200 files
- Homework 11 · Fall 2018HomeworkView
- Homework Last Assignment · Fall 2018HomeworkView
- Homework Asst10 · Fall 2017HomeworkView
- Homework 9 · Spring 2017HomeworkView
- Homework Assignment 4 · Fall 2016HomeworkView
- Homework Assignment 6 · Fall 2016HomeworkView
- Homework Assignment 7 · Fall 2016HomeworkView
- Homework 1 · Spring 2016HomeworkView
Show the text of this homework
Faculty of Arts & Sciences
Department of Computer Science
CMPS 200—Introduction to Programming
Assignment 2 – Due: Sep. 23, 2016 @ 11:55 pm
Fall 2016-17
1 of 2
Notes on the Development Environment
•
In order to compile and run your programs you will need a compiler (javac) and a runtime virtual machine
(java). Both tools are part of the Java Development Environment (JDK).
•
The JDK is installed on all lab machines in Bliss. Those of you who plan to write your programs on your own
laptops and desktops should download the appropriate version of JDK 8 from Moodle.
•
Detailed instructions for installation of the JDK may be found on the Moodle site as well. Please read and
follow the detailed instructions for verifying the installation.
Exercise 1
Write a program RocketShip.java that draws the following output (see below). You should write the
appropriate static methods to show structure and eliminate redundancy in your solution.
/**\
//**\\
///**\\\
+=*=*=*=*+
|o/\oo/\o|
|/\/\/\/\|
|\/\/\/\/|
|o\/oo\/o|
+=*=*=*=*+
|\/\/\/\/|
|o\/oo\/o|
|o/\oo/\o|
|/\/\/\/\|
+=*=*=*=*+
/**\
//**\\
///**\\\
Exercise 2
Write a program Weight.java that creates and declares two double variables to represent the mass of an object
and gravity. You should compute and display the weight of the object in both Newtons and pounds (1N = 0.23
pounds). A sample run of your program with a mass of 2.0 kg and a gravity value of 9.81 ms-2 should generate the
following output: (Note do not replicate the example. Use your own value for the mass.)
Exercise 3
Write a Java program, NetSalary.java, which computes your net salary by adding allowances to the basic
salary. The basic salary should be a double variable named basicSalary. Initialize “basicSalary” to any number
you like and then output the net salary to the screen. Assume that the transport allowance is 10% of the basic salary
and that the housing allowance is another 50% of the basic salary. The net salary is the sum of basic salary, transport
allowance and housing allowance. A sample run for a basic salary of 3000 is given below. The output of your
program should exactly match this sample output when the basic salary is 3000.
CMPS 200: Introduction to Programming
Fall 2016-17
2 of 2
Sample Run:
-> java NetSalary
Basic Salary: 3000.0
Transport Allowance: 300.0
Housing Allowance: 1500.0
Net Salary = 4800.0
Exercise 4
Write a program Coordinates.java that declares and initializes four-integer variables x0, y0, x1, y1 (denoting
the coordinates of two points A and B). You are to print (see below) the coordinates of the midpoint of A and B as
follows:
The coordinates of the midpoint: (x,y).
Exercise 5
Write a program Temp.java that declares and initializes a double variable that represents a temperature of a
certain day in degrees Celsius. You should covert the given temperature to Fahrenheit and print it out. To convert
to Fahrenheit, multiply by 1.8 and add 32
Submission Instructions
•
Your submission must consist of a single zip folder that contains .java files only (RocketShip.java,
Weight.java, NetSalary.java, Coordinates.java, and Temp.java). No additional files should exist
in the .zip folder.
•
Give meaningful names to your methods and variables in your code.
•
Include a comment at the beginning of your program with basic information about yourself and a description
of the program. Include also a comment at the start of each method.
•
The name of the zip file must adhere to the following naming convention s#_A$_netid, where # stands for your
section number (between 1 and 12), $ stands for the assignment number, and netid stands for your AUBnet
user name. For example, if your AUBnetid is abc65 and you are in section 4, you should submit Assignment 2
using following file: s4_A2_abc65.zip. The zip files will be processed automatically so please make sure you
use this naming convention.
•
Failing to follow these guidelines will result in deducting marks form your grade.