You are on page 1of 4

CSC 212: Programming In Java

Assignment 1

1. Write a program that asks the user to enter the name, ID in


parenthesis, and list of at most three children’s first name
(each separated by number then '.' dot) in one single line. The
program then displays all information in the format shown below
(see run time example). The program also finds the password
created from last character from each child’s name plus a last
three digit of ID. The program should be general.

Run-time example:
Enter the name(ID),and at most 3 children's names (separated by
number then '.' Dot)
Mohammad(317856) 1. Yousuf 2. Ibrahim 3. Nabila

Your Name : Mohammad


Your ID: 317856
Your first child: Yousuf
Your Second child: Ibrahim
Your Third child: Nabila
Your Password: fma856

2. Write an application that prompts the user for the values, all to
be entered in one line through the keyboard, separated by spaces.
Then the program displays out the count of the values, the
average, the maximum value, the minimum value, and the standard
deviation. The program must be general. The standard deviation

formula is:

Run-time example:
Enter a set of values: 1.2 3 4 5 3.75
There are 5 data
The maximum value is 5
The minimum value is 1.2
The sum is 16.95

Page 1 of 4
The average is 3.39
The standard deviation is 1.4179

3. Write a class Statistics that contains an array of integers. It


should conatin a methods to return the average and standard
deviation of all numbers (formula in Exercise 2). Also write a
method that searches for a particular number in array and returns
its index.
In the Test class that asks the user the total count of numbers
and then let user enter all of the numbers. Then print the
average and standard deviation of the numbers.
At the end ask a number to search and print the result.

Sample Output

Please enter total count of numbers to be entered : 5


Please enter the 5 numbers :
1
2
3
4
5

Average : 3
Standard Deviation : 1.58

Please enter the number to search : 3


The number exists at index 3

4. Write a class Book with Instance variables to store the title,


author names separeted by comma and publisher name. Write a
toString() method that prints the title of book and author names
on separate line. Also add static method that takes a books array
as a parameter and then prints all the titles of book followed by
author names on separate lines.

Then in test program do the following:


 Create 2 books with different titles, author names and
publisher
 Store them in an array
 Pass this array to the method that prints all the books

Page 2 of 4
Sample Output

Books :
Title
Let us C
Authors
Richtie
Dennis

Title
Thinking in Java
Authors
Booch
Grade

5. Write a new class called Point3D which has three coordinate


points namely x, y and z. You can extend the Point class. Write a
Test class to test Point3D class. Call the super class
constructors from the relevant places in the constructors of
Point3D class.

The Point3D class should have the following methods along with
the constructors. Override the relevant methods.

public double distanceToOrigin()


public double distanceToPoint(Point p)
public void move(int x, int y, int z)
public void translate(int dx, int dy, int dz)
public String toString()
public boolean equals(Point3D p)

6. Write a superclass Worker and subclasses HourlyWorker and


SalariedWorker. Every worker has a name and salary. The hourly
worker has a salary rate. Write a method computePay(int hours)
that computes the weekly pay for every worker. An hourly worker
gets paid the hourly wage for the actual number of hours worked
if hours is at most 40. If the hourly worker worked more than 40,
the excess is paid at time and half. The salaried worker gets
paid the hourly wage for 40 hours regardless of the actual number
of hours worked. Write also toString() methods to print out the

Page 3 of 4
worker information: name and weekly salary. Supply a test program
to test these classes and methods.

Page 4 of 4

You might also like