Exercise: 4.19 (JHTP) (Sales Commission Calculator) A large company pays its salespeople on
a commission basis. The salespeople receive $200 per week plus 9% of their gross sales for
that week. For example, a salesperson who sells $5,000 worth of merchand
Exercise 3.14 JHTP (Employee Class) Create a class called Employee that includes 3 instance variablesa
first name (type String), a last name (type String), and a monthly salary (double). Provide a constructor
that initializes the 3 instance variables. Pro
Exercise 10.8 Payroll Modification Modify the payroll system of Figs 10.4 10.9 to include private
instance variable birthdate in class Employee. Use class Date of Fig 8.7 to represent an employees
birthday. Add get methods to class Date. Assume that payro
Exercise: 5.16 (JHTP) (Bar Chart Printing Program) One interesting application of computers is
to display graphs and bar charts. Write an application that reads 5 numbers between 1 and 30.
For each number that reads, your program should display the same n
Exercise 3.15 JHTP (Date Class) Create a class called Date that includes 3 instance variables
a month (type int), a day (type int), and a year (type int). Provide a constructor that initializes
the 3 instance variables and assumes the values provided are
Inheritance in Java (Defining subclass(es) ):
A sub class can be defined as follows:
class sub_class_name extends super_class_name
data members of the sub_class ;
member methods of the sub_class ;
The keyword extends indicates that the class
Exercise 3.11 (Modified GradeBook Class) Modify class Gradebook (fig. 3.10) as follows:
Include a String instance variable that represents the name of the courses instructor.
Provide a set method to change the instructors name and a get method to retrieve
Exercise 5.12 Write an application that calculates the product of the odd integers from 1 to 15.
public class IntProduct
public static void main(String args)
int product = 1; / results of calculation
/ calculation loop, starts calcul
Exercise 5.32 (JHTP) According to CNNMoney.com, Facebook hit 500 million users in July of 2010 and its
user base has been growing at a rate of 5% per month. Using the compound-growth technique you
learned in Fig 5.6 and assuming this growth rate continues
Ex 11.9 Write a program that shows that the order of catch blocks is important. If you try to catch
a superclass exception type before a subclass type, the compiler should generate errors.
public class ErrorDemo
Ex 11.17 Use inheritance to create an exception superclass (called ExceptionA) and exception
subclasses ExceptionB and ExceptionC, where ExceptionB inherits from ExceptionA and
ExceptionC inherits from ExceptionB. Write a program to demonstrate that the c
Introduction to Java
Java is an object-oriented language that was conceived by
James Gosling, Patrick Naughton, Chris Warth, Ed Frank,
and Mike Sherictan at Sun Microsystems, Inc. in 1991. This
language was initially called Oak but was renamed Java in
Interfaces in Java
Java does not support multiple inheritance.
In other words, classes in Java cannot have more
than one super class.
For example, a definition like
class One extends Two extends Three
is not permitted in Java.
Encapsulation and You
Thinking in boxes
Generally presented as a conflation of
public, private, protected
require getters/setters to access data (aka
Combining state (fields) and behavior
History of programming
Program is a sequence of bits interpreted by
Primitive operations (load, store, jump if a
register not zero, etc.)
1100 0000 0000 1101
Difficult to read, write, edit
= QPpart =
This is the main code for solving the (binary) graph partitioning problem
(BP) min -(1-x)'Ax subject to lo <= b <= hi, a'x = b, x_i \in cfw_0, 1.
The goal is to find the solution to this problem with all components
Starting with a simple Java application program:
public static void main( String args[ ] )
System.out.println(Welcome to the world of Java.);
1. Class declaration
The first line of the above program is given as:
Stack class in Java
private int maxSize ;
private double[ ] stackArray;
private int top ;
public StackX(int s)
maxSize = s ;
stackArray = new double[maxSize];
top = -1;
public void push(double j)
Wrapper Classes for converting simple types
Converting Primitive Numbers to Object Numbers, using
Defining a class in Java:
The general form of defining a class is:
variable declaration ; / data member
method declaration ; / member functions
The specifier starts with the keyword class, followed by
Packages are Javas way of grouping a variety
of classes / interfaces together.
Packages act as containers for classes.
Two classes in two different packages can have
the same name.
Packages provide a way to hide classes thus
It is common to make mistakes while developing as well as
typing a program.
A mistake might lead to an error causing the program to
produce unexpected results.
Errors are the wrong that can make a program go wrong.
An error may prod
Console Input and Output
System.out.println for console
System.out is an object that is part of the Java language
println is a method invoked by the System.out object
that can be used for console output
The data to be output is given as
COP4331 Quiz 1
January 10, 2013
Refactor QPpart.c to maximize the degree of abstraction oered by encapsulating its various concerns.
Actually compiling this code (as is) will not be possible. This is okay. There are structs an