Free Essay

Object Oriented Programming in Java ‐ Exercises

In:

Submitted By DMadhusree
Words 3130
Pages 13
OBJECT ORIENTED PROGRAMMING IN JAVA ‐ EXERCISES
CHAPTER 1
1. Write Text‐Based Application using Object‐Oriented Approach to display your name.
// filename: Name.java // Class containing display() method, notice the class doesnt have a main() method

public class Name { public void display() { System.out.println("Mohamed Faisal"); } }
// filename: DisplayName.java // place in same folder as the Name.java file // Class containing the main() method

public class DisplayName { public static void main(String[] args) { Name myname = new Name(); // creating a new object of Name class myname.display(); // executing the display() method in the Name class } }

2. Write a java Applet to display your age.
// filename: DisplayNameApplet.java

import java.applet.Applet; // import necessary libraries for an applet import java.awt.Graphics; public class DisplayNameApplet extends Applet { public void paint(Graphics g) { g.drawString("Mohamed Faisal", 50, 25); } }
// filename: DisplayNameApplet.htm // place in same folder as the compiled DisplayNameApplet.class file

Displaying my Name

CHAPTER 2 3. Write a program that calculates and prints the product of three integers.
// filename: Q1.java

import java.util.Scanner; // import Scanner libraries for input public class Q1 { public static void main(String[] args) { Scanner input = new Scanner (System.in); int number1; int number2; int number3; System.out.println("Enter the First Number"); www.oumstudents.tk number1 = input.nextInt(); System.out.println("Enter the Second Number"); number2 = input.nextInt(); System.out.println("Enter the Third Number"); number3 = input.nextInt(); System.out.printf("The product of three number is %d:", number1 * number2 * number3); } }

4. Write a program that converts a Fahrenheit degree to Celsius using the formula:
// filename: Q2.java

import java.util.*; public class Q2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); double celsius; double tempInFahrenheit = 0.0; celsius = (tempInFahrenheit - 32.0) * 5.0 / 9.0; System.out.println("Enter the fahrenheit value"); tempInFahrenheit = input.nextDouble(); System.out.printf("The celsious value of %10.2f is %2.2f",tempInFahrenheit, celsius); } }

5. Write an application that displays the numbers 1 to 4 on the same line, with each pair of adjacent numbers separated by one space. Write the application using the following techniques: a. Use one System.out.println statement. b. Use four System.out.print statements. c. Use one System. out. printf statement.
// filename: Printing.java

public class Printing { public static void main(String[] args) { int num1 = 1; int num2 = 2; int num3 = 3; int num4 = 4; System.out.println(num1 + " " + num2 + " " + num3 + " " + num4); System.out.print(num1 + " " + num2 + " " + num3 + " " + num4); System.out.printf("\n%d %d %d %d",num1,num2,num3,num4); } }

www.oumstudents.tk

6. Write an application that asks the user to enter two integers, obtains them from the user and prints their sum, product, difference and quotient (division).
// File: NumberCalc1.java

import java.util.Scanner; public class NumberCalc1 {

// include scanner utility for accepting keyboard input // begin class

public static void main(String[] args) { // begin the main method Scanner input=new Scanner (System.in); //create a new Scanner object to use int num1=0, num2=0; // initialize variables System.out.printf("NUMBER CALCULATIONS\n\n"); System.out.printf("Enter First Number:\t "); num1=input.nextInt(); // store next integer in num1 System.out.printf("Enter Second Number:\t "); num2=input.nextInt(); // store next integer in num2
// display the sum, product, difference and quotient of the two numbers

System.out.printf("---------------------------\n"); System.out.printf("\tSum =\t\t %d\n", num1+num2); System.out.printf("\tProduct =\t %d\n", num1*num2); System.out.printf("\tDifference =\t %d\n", num1-num2); System.out.printf("\tQuotient =\t %d\n", num1/num2); } }

CHAPTER 3 7. Write an application that asks the user to enter two integers, obtains them from the user and displays the larger number followed by the words “is larger”. If the numbers are equal, print “These numbers are equal”
// File: Question1.java // Author: Abdulla Faris

import java.util.Scanner; public class Question1 {

// include scanner utility for accepting keyboard input

// begin class

public static void main(String[] args) { // begin the main method Scanner input=new Scanner (System.in); //create a new Scanner object to use (system.in for Keyboard inputs) int num1=0, num2=0, bigger=0;

// initialize variables

System.out.printf("Enter First Number: "); num1=input.nextInt(); // store next integer in num1 System.out.printf("Enter Second Number: "); num2=input.nextInt(); // store next integer in num2 if (num1>num2){ // checks which number is larger bigger=num1; System.out.printf("%d Is Larger", bigger); } else if (num1num2?num1:num2; // checks the biggest number in and assigns it to bigger variable bigger=bigger>num3?bigger:num3; smaller=num1 0.0) {price=prc;} else {price=0.0;} } public double getInvoiceAmount(){ return (double)quantity*price; } }

//filename: InvoiceTest.java // Invoice testing class with the main() method

public class InvoiceTest { public static void main (String args[]){ Invoice invoice1=new Invoice ("A5544", "Big Black Book", 500, 250.00); Invoice invoice2=new Invoice ("A5542", "Big Pink Book", 300, 50.00); System.out.printf("Invoice 1: %s\t%s\t%d\t$%.2f\n", invoice1.getPartNum(), invoice1.getPartDesc(), invoice1.getQuantity(), invoice1.getPrice()); System.out.printf("Invoice 2: %s\t%s\t%d\t$%.2f\n", invoice2.getPartNum(), invoice2.getPartDesc(), invoice2.getQuantity(), invoice2.getPrice()); } }

18. Create a class called Employee that includes three pieces of information as instance variables—a first name (typeString), a last name (typeString) and a monthly salary (double). Your class should have a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, set it to 0.0. Write a test application named EmployeeTest that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary. Then give each Employee a 10% raise and display each Employee’s yearly salary again.
//filename: Employee.java // Employee class

public class Employee { private String firstName; private String lastName; private double salary; public Employee(String fName, String lName, double sal) { if (fName != null) firstName =fName; if (lName != null) lastName = lName; if (sal > 0.0) { salary=sal; } else { salary=0.0; } }
//set methods

public String getFirstName(){ return firstName; } public String getLastName(){ return lastName; } public double getSalary(){ return salary; }

www.oumstudents.tk

//get methods

public void setFirstName(String fName){ if (fName != null) firstName = fName; } public void setLastName(String lName){ if (lName != null) lastName = lName; } public void setSalary(double sal){ if (sal > 0.0){ salary = sal; } else { salary = 0.0; } } }

//filename: EmployeeTest.java // Employee testing class with the main() method

public class EmployeeTest { public static void main (String args[]){ Employee employee1=new Employee ("Mohamed", "Ali", 20000.00); Employee employee2=new Employee ("Ahmed", "Ibrahim", 50000.00); System.out.printf("\nNO:\t NAME\t\t\tYEARLY SALARY\n"); System.out.printf("--\t ----\t\t\t-------------\n"); System.out.printf("1:\t %s %s\t\t$%.2f\n", employee1.getFirstName(), employee1.getLastName(), employee1.getSalary()); System.out.printf("2:\t %s %s\t\t$%.2f\n", employee2.getFirstName(), employee2.getLastName(), employee2.getSalary());
//set raise 10%

employee1.setSalary( (.1*employee1.getSalary())+employee1.getSalary()); employee2.setSalary( (.1*employee2.getSalary())+employee2.getSalary()); System.out.printf("\n10 Percent Salary Raised!! Yoohooooo!\n"); System.out.printf("\nNO:\t NAME\t\t\tYEARLY SALARY\n"); System.out.printf("--\t ----\t\t\t-------------\n"); System.out.printf("1:\t %s %s\t\t$%.2f\n", employee1.getFirstName(), employee1.getLastName(), employee1.getSalary()); System.out.printf("2:\t %s %s\t\t$%.2f\n", employee2.getFirstName(), employee2.getLastName(), employee2.getSalary()); } }

19. Create a class called Date that includes three pieces of information as instance variables—a month (typeint), a day (typeint) and a year (typeint). Your class should have a constructor that initializes the three instance variables and assumes that the values provided are correct. Provide a set and a get method for each instance variable. Provide a method displayDate that displays the month, day and year separated by forward slashes(/). Write a test application named DateTest that demonstrates classDate’s capabilities.
//filename: Date.java // Date class

public class Date { private int month; private int day; private int year; public Date(int myMonth,int myDay, int myYear) { www.oumstudents.tk month = myMonth; day = myDay; year = myYear; } public void setMonthDate(int myMonth) { month = myMonth; } public int getMonthDate() { return month; } public void setDayDate(int myDay) { day = myDay; } public int getDayDate() { return month; } public void setYearDate(int myYear) { year = myYear; } public int getYearDate() { return year; } public void displayDate() { System.out.printf("%d/%d/%d", month,day,year); } }

//filename: DateTest.java // Date testing class with the main() method

import java.util.*; public class DateTest { public static void main(String[] args) { Scanner input = new Scanner(System.in); Date myDate = new Date(9, 11, 1986); System.out.println("Enter The Month"); int myMonth = input.nextInt(); myDate.setMonthDate(myMonth); System.out.println("Enter the Date"); int myDay = input.nextInt(); myDate.setDayDate(myDay); System.out.println("Enter the Year"); int myYear = input.nextInt(); myDate.setYearDate(myYear); myDate.displayDate(); } }

CHAPTER 6
20. Create class SavingsAccount. Usea static variable annualInterestRate to store the annual interest rate for all account holders. Each object of the class contains a private instance variable savingsBalance indicating the amount the saver currently has ondeposit. Provide method calculateMonthlyInterest to calculate the monthly www.oumstudents.tk interest by multiplying the savingsBalance by annualInterestRate divided by 12 this interest should be added to savingsBalance. Provide a static method modifyInterestRate that sets the annualInterestRate to a new value. Write a program to test class SavingsAccount. Instantiate two savingsAccount objects, saver1 and saver2, with balances of $2000.00 and $3000.00, respectively. Set annualInterestRate to 4%, then calculate the monthly interest and print the new balances for both savers. Then set the annualInterestRate to 5%, calculate the next month’s interest and print the new balances for both savers.
//filename: SavingAccount.java // SavingAccount class

public class SavingsAccount { public static double annualInterestRate; private double savingsBalance; public SavingsAccount() { annualInterestRate = 0.0; savingsBalance = 0.0; } public SavingsAccount(double intRate, double savBal) { annualInterestRate = intRate; savingsBalance = savBal; } public double calculateMonthlyInterest() { double intRate = (savingsBalance * annualInterestRate/12); savingsBalance = savingsBalance + intRate; return intRate; } public static void modifyInterestRate(double newInteresRate) { annualInterestRate = newInteresRate; } public void setSavingsBalance(double newBal) { savingsBalance = newBal; } public double getSavingsBalance() { return savingsBalance; } public double getAnnualInterestRate() { return annualInterestRate; } }

//filename: SavingsAccountTest.java // SavingsAccount testing class with the main() method

public class SavingsAccountTest { public static void main(String[] args) { SavingsAccount saver1 = new SavingsAccount(); SavingsAccount saver2 = new SavingsAccount(); saver1.setSavingsBalance(2000.00); saver2.setSavingsBalance(3000.00); SavingsAccount.modifyInterestRate(0.04); saver1.calculateMonthlyInterest(); saver2.calculateMonthlyInterest(); System.out.printf("New Balance for Saver1=%f\n",saver1.getSavingsBalance()); System.out.printf("New Balance for Saver2=%f\n",saver2.getSavingsBalance());

www.oumstudents.tk

SavingsAccount.modifyInterestRate(0.05); saver1.calculateMonthlyInterest(); saver2.calculateMonthlyInterest(); System.out.printf("New Balance for Saver1=%f\n",saver1.getSavingsBalance()); System.out.printf("New Balance for Saver2=%f\n",saver2.getSavingsBalance()); } }

21. Create a class called Book to represent a book. A Book should include four pieces of information as instance variables‐a book name, an ISBN number, an author name and a publisher. Your class should have a constructor that initializes the four instance variables. Provide a mutator method and accessor method (query method) for each instance variable. Inaddition, provide a method named getBookInfo that returns the description of the book as a String (the description should include all the information about the book). You should use this keyword in member methods and constructor. Write a test application named BookTest to create an array of object for 30 elements for class Book to demonstrate the class Book's capabilities.
//filename: Book.java // Book class

public class Book { private String Name; private String ISBN; private String Author; private String Publisher; public Book() { Name = "NULL"; ISBN = "NULL"; Author = "NULL"; Publisher = "NULL"; } public Book(String name, String isbn, String author, String publisher) { Name = name; ISBN = isbn; Author = author; Publisher = publisher; } public void setName(String Name) { this.Name = Name; } public String getName() { return Name; } public void setISBN(String ISBN) { this.ISBN = ISBN; } public String getISBN() { return ISBN; } public void setAuthor(String Author) { this.Author = Author; } public String getAuthor() { return Author; } public void setPublisher(String Publisher) { this.Publisher = Publisher; } public String getPublisher() { return Publisher; }

www.oumstudents.tk

public void getBookInfo() { System.out.printf("%s %s %s %s", Name,ISBN,Author,Publisher); } }

//filename: SavingsAccountTest.java // SavingsAccount testing class with the main() method

public class BookTest { public static void main(String[] args) {

Book test[] = new Book[13]; test[1] = new Book(); test[1].getBookInfo(); } }

CHAPTER 7 22. a. Create a super class called Car. The Car class has the following fields and methods. ◦intspeed; ◦doubleregularPrice; ◦Stringcolor; ◦doublegetSalePrice();
//filename: Car.java //Car class

public class Car { private int speed; private double regularPrice; private String color; public Car (int Speed,double regularPrice,String color) { this.speed = Speed; this.regularPrice = regularPrice; this.color = color; }

public double getSalePrice() { return regularPrice; } }

b. Create a sub class of Car class and name it as Truck. The Truck class has the following fields and methods. ◦intweight; ◦doublegetSalePrice();//Ifweight>2000,10%discount.Otherwise,20%discount.
//filename: Truck.java // Truck class, subclass of Car

public class Truck extends private int weight;

Car {

public Truck (int Speed,double regularPrice,String color, int weight) { super(Speed,regularPrice,color); this.weight = weight; } www.oumstudents.tk public double getSalePrice() { if (weight > 2000){ return super.getSalePrice() - (0.1 * super.getSalePrice()); } else { return super.getSalePrice(); } } }

c. Create a subclass of Car class and name it as Ford. The Ford class has the following fields and methods ◦intyear; ◦intmanufacturerDiscount; ◦doublegetSalePrice();//FromthesalepricecomputedfromCarclass,subtractthemanufacturerDiscount.
//filename: Ford.java // Ford class, subclass of Car

public class Ford extends Car { private int year; private int manufacturerDiscount; public Ford (int Speed,double regularPrice,String color, int year, int manufacturerDiscount) { super (Speed,regularPrice,color); this.year = year; this.manufacturerDiscount = manufacturerDiscount; } public double getSalePrice() { return (super.getSalePrice() - manufacturerDiscount); } }

d. Create a subclass of Car class and name it as Sedan. The Sedan class has the following fields and methods. ◦intlength; ◦doublegetSalePrice();//Iflength>20feet,5%discount,Otherwise,10%discount.
//filename: Sedan.java // Sedan class, subclass of Car

public class Sedan extends Car { private int length; public Sedan (int Speed,double regularPrice,String color, int length) { super (Speed,regularPrice,color); this.length = length; } public double getSalePrice() { if (length > 20) { return super.getSalePrice() - (0.05 * super.getSalePrice()); } else { return super.getSalePrice() - (0.1 * super.getSalePrice()); } } }

e. Create MyOwnAutoShop class which contains the main() method. Perform the following within the main() method. ◦Create an instance of Sedan class and initialize all the fields with appropriate values. Use super(...) method in the constructor for initializing the fields of the superclass. ◦Create two instances of the Ford class and initialize all the fields with appropriate values. Use super(...) method in the constructor for initializing the fields of the super class. www.oumstudents.tk ◦Create an instance of Car class and initialize all the fields with appropriate values. Display the sale prices of all instance.
//filename: MyOwnAutoShop.java // Testing class with the main() method

public class MyOwnAutoShop { (int Speed,double regularPrice,String color, int year, int manufacturerDiscount) public static void main(String[] args) { Sedan mySedan = new Sedan(160, 20000, "Red", 10); Ford myFord1 = new Ford (156,4452.0,"Black",2005, 10); Ford myFord2 = new Ford (155,5000.0,"Pink",1998, 5); Car myCar - new Car (555, 56856.0, "Red"); System.out.printf("MySedan Price %.2f", mySedan.getSalePrice()); System.out.printf("MyFord1 Price %.2f", myFord1.getSalePrice()); System.out.printf("MyFord2 Price %.2f", myFord2.getSalePrice()); System.out.printf("MyCar Price %.2f", myCar.getSalePrice()); } }

CHAPTER 8 CHAPTER 9
23. Write an applet that asks the user to enter two floating‐point numbers, obtains the two numbers from the user and draws their sum, product (multiplication), difference and quotient (division). Use the techniques shown in example.

//filename: simpleApplet1.java

import java.awt.*; import javax.swing.*; public class simpleApplet1 extends JApplet { double sum; double product; double difference; double quotient; public void init() { String firstNumber; String secondNumber; double number1; double number2; firstNumber = JOptionPane.showInputDialog("Enter the first number"); secondNumber = JOptionPane.showInputDialog("Enter the second number"); number1 = Double.parseDouble(firstNumber); number2 = Double.parseDouble(secondNumber); sum = number1 + number2; product = number1 * number2; difference = number1 - number2; quotient = number1 % number2; } public void paint(Graphics g) { www.oumstudents.tk super.paint(g); g.drawRect(15, 10, 270, 60); g.drawString("Sum "+sum, 25, 25); g.drawString("Product "+product, 25, 35); g.drawString("Difference "+difference, 25, 45); g.drawString("Quotient "+quotient, 25, 55); }

}

CHAPTER 10 24. Create an applet that can display the following component. No event handling is needed for the components.
//filename: simpleAppet2.java

import javax.swing.*; import java.awt.*; public class simpleAppet2 extends JApplet { private JLabel lblName; private JLabel lblAddress; private JLabel lblEmail; private JTextField txtName; private JTextField txtAddress; private JTextField txtEmail; public void init() { Container conpane = getContentPane(); conpane.setLayout(new FlowLayout()); lblName = new JLabel("name"); lblAddress = new JLabel("address"); lblEmail = new JLabel("email"); txtName = new JTextField(10); txtAddress = new JTextField(10); txtEmail = new JTextField(10); conpane.add(lblName); conpane.add(txtName); conpane.add(lblAddress); conpane.add(txtAddress); conpane.add(lblEmail); conpane.add(txtEmail); } }

25. Create an applet that can display the following component. No event handling is needed for the components.
//filename: simpleAppet3.java

import javax.swing.*; import java.awt.*; public class simpleAppet3 extends JApplet { private JButton button1, button2, button3, button4, button5; public void init( ){ Container conpane = getContentPane(); conpane.setLayout(new BorderLayout()); JPanel panel = new JPanel(); panel.setLayout(new GridLayout(1,5)); www.oumstudents.tk button1 button2 button3 button4 button5

= = = = =

new new new new new

JButton("Button JButton("Button JButton("Button JButton("Button JButton("Button

1"); 2"); 3"); 4"); 5");

panel.add(button1); panel.add(button2); panel.add(button3); panel.add(button4); panel.add(button5); conpane.add("South",panel); } }

CHAPTER 11 26. Temperature Conversion a. Write a temperature conversion applet that converts from Fahrenheit to Celsius. The Fahrenheit temperature should be entered from the keyboard (via a JTextField). A JLabel should be used to display the converted temperature. Use the following formula for the conversion: Celcius = ((5/9)*(Ferenheit‐32)). b. Enhance the temperature conversion applet of Q1 by adding the Kelvin temperature scale. The applet should also allow the user to make conversions between any two scales. Use the following formula for the conversion between Kelvin and Celsius (in addition to the formulain Q1): Kelvin = Celcius + 273.15
/* * Filename: tempCon.java * Author: Abdulla Faris * Date: 13/04/2010 */

import import import import

javax.swing.*; java.awt.*; java.awt.event.*; java.text.*;

public class tempCon extends JApplet implements ActionListener { JTextField txtInput; JLabel lblResult; JRadioButton rbCelcius, rbKelvin; public void init(){ Container conpane = getContentPane(); conpane.setLayout (new FlowLayout()); txtInput = new JTextField("",10); conpane.add(txtInput); rbCelcius= new JRadioButton ("to Celcius", true); conpane.add(rbCelcius); rbKelvin = new JRadioButton("to Kelvin", false); conpane.add(rbKelvin); ButtonGroup selection = new ButtonGroup(); selection.add(rbCelcius); selection.add(rbKelvin); JButton button1 = new JButton ("Show Result"); button1.addActionListener(this); conpane.add(button1); www.oumstudents.tk lblResult= new JLabel ("Enter Ferenheit, Choose an option to convert and Click Show Result"); conpane.add(lblResult); } public void actionPerformed(ActionEvent e) { DecimalFormat df = new DecimalFormat ("#.##"); double ferenheit = Double.parseDouble(txtInput.getText()); double answer = 0.0; answer = ((5.0/9.0)*(ferenheit - 32.0)); if (rbKelvin.isSelected()) answer += 273.15; lblResult.setText(String.valueOf(df.format(answer))); } }

www.oumstudents.tk

Similar Documents

Premium Essay

Bout This

...Pasig campus pangilinan DSITI-AI Oct 27 15 Java Programming java programming Introduction in java programming Objectives * Object-Oriented Programming Language * Object-Oriented Programming Principle * Benefits Of Object-Oriented Programming * Introduction To Java Programming * Resources Used To Create a Java Programming *Structures Of a Java Programming * Result Of Executing The Java Programing Object Oriented Programming Language (OOPL) OOPL Is An Extension Of Procedural Language. Involves Creating Program Components as Object Related To The Real Word. Writing Object-Oriented Programs Involves Creating Object And Application That Uses Those Objects. An Object Contains Both Data Procedures Can be packaged Into a Single Unit. Based On Three Concepts Encapsulation Ability To Bind Data And Procedures Into an Object. Inheritance Ability Of Objects To Acquire The Attributes Or Behavior Of Other Objects Or Classes. Polymorphism Ability of An Object To Take Many Forms Or Identities. Benefits Of Object-Oriented Programming *Reusability -Able To Reuse The Defined Objects. *Adaptability –Able to fit in different environment. *maintainability –Able to change easily. *reliability –Able to operate...

Words: 1445 - Pages: 6

Premium Essay

Java Programming Language Sl-275

...Sun Educational Services Java Programming Language SL-275 Sun Educational Services Java Programming Language September 1999 Copyright 1999 Sun Microsystems, Inc., 901 San Antonio Road, Palo Alto, California 94303, U.S.A. All rights reserved. This product or document is protected by copyright and distributed under licenses restricting its use, copying, distribution, and decompilation. No part of this product or document may be reproduced in any form by any means without prior written authorization of Sun and its licensors, if any. Third-party software, including font technology, is copyrighted and licensed from Sun suppliers. Parts of the product may be derived from Berkeley BSD systems, licensed from the University of California. UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open Company, Ltd. Sun, Sun Microsystems, the Sun Logo, Solstice, Java, JavaBeans, JDK, and Solaris are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the U.S. and other countries. Products bearing SPARC trademarks are based upon an architecture developed by Sun Microsystems, Inc. The OPEN LOOK and Sun Graphical User Interface was developed by Sun Microsystems, Inc. for its users and licensees. Sun acknowledges the pioneering efforts of Xerox in researching and developing the...

Words: 6064 - Pages: 25

Free Essay

Java Page

...Tolkien Object-Oriented Programming: Polymorphism OBJECTIVES In this chapter you will learn: ■ ■ ■ ■ ■ General propositions do not decide concrete cases. —Oliver Wendell Holmes A philosopher of imposing stature doesn’t think in a vacuum. Even his most abstract ideas are, to some extent, conditioned by what is or is not known in the time when he lives. —Alfred North Whitehead The concept of polymorphism. To use overridden methods to effect polymorphism. To distinguish between abstract and concrete classes. To declare abstract methods to create abstract classes. How polymorphism makes systems extensible and maintainable. To determine an object’s type at execution time. To declare and implement interfaces. Why art thou cast down, O my soul? —Psalms 42:5 ■ ■ © Copyright 1992-2007 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Chapter 10 Object-Oriented Programming: Polymorphism 307 Assignment Checklist Name: Section: Date: Exercises Assigned: Circle assignments Date Due Prelab Activities Matching Fill in the Blank Short Answer Programming Output Correct the Code YES YES YES YES YES YES 1 NO NO 1 YES NO NO NO NO NO NO Lab Exercises Exercise 1 — Payroll System Modification Follow-Up Question and Activity Follow-Up Question and Activity Debugging Exercise 2 — Accounts Payable System Modification YES Labs Provided by Instructor 1. 2. 3. Postlab Activities Coding Exercises Programming Challenges...

Words: 4624 - Pages: 19

Free Essay

Concepts of Programming Language Solutions

...Instructor’s Solutions Manual to Concepts of Programming Languages Tenth Edition R.W. Sebesta ©2013 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. Preface Changes for the Tenth Edition T he goals, overall structure, and approach of this tenth edition of Concepts of Programming Languages remain the same as those of the nine earlier editions. The principal goals are to introduce the main constructs of contemporary programming languages and to provide the reader with the tools necessary for the critical evaluation of existing and future programming languages. A secondary goal is to prepare the reader for the study of compiler design, by providing an indepth discussion of programming language structures, presenting a formal method of describing syntax and introducing approaches to lexical and syntatic analysis. The tenth edition evolved from the ninth through several different kinds of changes. To maintain the currency of the material, some of the discussion of older programming languages has been removed. For example, the description of COBOL’s record operations was removed from Chapter 6 and that of Fortran’s Do statement was removed from Chapter 8. Likewise, the description of Ada’s generic subprograms was removed from Chapter 9 and the discussion of Ada’s asynchronous message passing was removed from Chapter 13. On the other hand, a section on closures, a section on calling subprograms indirectly, and a section on generic functions in...

Words: 7025 - Pages: 29

Premium Essay

Essay

...For Exercises 1- 10 , match the activity with the phase of the object-oriented methodology. A. Brainstorming B. Filtering C. Scenarios D. Responsibility algorithms |1. |Reviewing a list of possible classes, looking for duplicates or missing classes. | | |B | |2. |Asking "what if" questions. | | |C | |3. |Assigning responsibilities to classes. | | |C | |4. |Generating first approximation to the list of classes in a problem. | | |A | |5. |Assigning collaborators to a responsibility. | | |C ...

Words: 2569 - Pages: 11

Free Essay

Macoii

...1.1 Introduction Object-Oriented Strategies Object-oriented programming embodies in software structures a number of powerful design strategies that are based on practical and proven software engineering techniques. By incorporating support for these strategies in software structures, object-oriented programming enables the manageable construction of more complex systems of software than was previously possible. The nature of these software structures has been shaped by decades of software engineering experience. The basic design strategies that are embodied in object-oriented programming are presented in the Table 1.1. The design strategies evolved as techniques for dealing with complex natural and man-made system. Because these strategies are so fundamental, they are encountered in other contexts and in other programming language forms. What is stressed here is the relationship of these strategies to the design and construction of object-oriented software. These strategies are widely supported by existing object-oriented languages though different languages may present them in different ways and some languages may support other variations of each one. For example, some object-oriented languages have additional ways of supporting generalization. The design strategies in object-oriented programming are effective for constructing software models of entities in the problem domain. In fact, some have argued that software design is largely about constructing a software model of the...

Words: 16718 - Pages: 67

Free Essay

With the Development of Technology, More and More Robots Are Used in Various Fields,

...University of Mumbai B.E Information Technology Scheme of Instruction and Evaluation Third Year -Semester VI Scheme of Instructions Sr. Subjects Lect/ No 1 Information and Network Security Middleware and Enterprise Integration Technologies Software Engineering Data Base Technologies Programming for Mobile and Remote Computers Information Technology for Management of Enterprise TOTAL Week 4 Scheme of Examinations Theory T/W Practical Oral Total Hours Marks Marks Marks Marks Marks 3 100 25 -25 150 Pract/ Week 2 Tut/ Week -- 2 4 2 -- 3 100 25 -- 25 150 3 4 5 4 4 4 2 2 2 ---- 3 3 3 100 100 100 25 25 25 --25 25 25 -- 150 150 150 6 4 24 10 1 1 3 -- 100 600 25 150 -25 25 125 150 900 INFORMATION AND NETWORK SECURITY CLASS T.E. ( INFORMATION TECHNOLOGY) HOURS PER LECTURES : WEEK TUTORIALS : PRACTICALS EVALUATION SYSTEM: THEORY PRACTICAL ORAL TERM WORK : SEMESTER VI 04 -02 HOURS 3 ---- MARKS 100 25 25 1. Introduction What is Information Security? Security Goals. 2. Cryptography Crypto Basic, Classic Cryptography, Symmetric Key Cryptography: Stream Ciphers, A5/1, RC4, Block Ciphers, Feistel Cipher, DES, Triple DES, AES, Public Key Cryptography: Kanpsack, RSA, Defiie-Hellman, use of public key crypto- Signature and Non-repudiation, Confidentiality and Non-repudiation, Public Key Infrastructure, Hash Function: The Birthday Problem, MD5, SHA-1, Tiger Hash, Use of Hash Function. 3. Access...

Words: 3868 - Pages: 16

Free Essay

Mmmmm

...Jaipur Engineering College & Research Centre, Jaipur Manual Of TCP/IP Programming Lab (7CP8) Session 2007-2008 Computer Engineering Department Prepared By: Mahesh Jangid cc Exercise No. 1 AIM: Study of Data Communication System, Connectionless and connection oriented service, programming with TCP and UDP. Theory: - [pic] Networking Basics • computers running on the Internet communicate to each other using either Transmission Control (TCP) or the User Datagram (UDP) protocol • when we write Java programs that communicate over the network, we are programming at the application layer • however, to decide which Java classes our programs should use, we need to understand how TCP and UDP differ UDP (User Datagram Protocol) • connectionless - sends independent packets of data, called datagram, from one computer to another with no guarantees about arrival • each time a datagram is sent, the local and receiving socket address need to be sent as well TCP (Transmission Control Protocol) • connection-oriented - provides a reliable flow of data between two computers _ data sent from one end of the connection gets to the other end in the same order • in order to communicate using TCP protocol, a connection must first be established between the pair of sockets • once two sockets have been connected, they can be used to transmit data in both (or either one of the) directions UDP vs. TCP: Which Protocol...

Words: 2326 - Pages: 10

Premium Essay

Cd Key

...Java Quick Reference Console Input Scanner input = new Scanner(System.in); int intValue = input.nextInt(); long longValue = input.nextLong(); double doubleValue = input.nextDouble(); float floatValue = input.nextFloat(); String string = input.next(); Console Output System.out.println(anyValue); JOptionPane.showMessageDialog(null, "Enter input"); GUI Input Dialog String string = JOptionPane.showInputDialog( "Enter input"); int intValue = Integer.parseInt(string); double doubleValue = Double.parseDouble(string); Message Dialog Primitive Data Types byte short int long float double char boolean 8 bits 16 bits 32 bits 64 bits 32 bits 64 bits 16 bits true/false Arithmetic Operators + * / % ++var --var var++ var-addition subtraction multiplication division remainder preincrement predecrement postincrement postdecrement Assignment Operators = += -= *= /= %= assignment addition assignment subtraction assignment multiplication assignment division assignment remainder assignment Relational Operators < >= == != less than less than or equal to greater than greater than or equal to equal to not equal Logical Operators && || ! ^ short circuit AND short circuit OR NOT exclusive OR if Statements if (condition) { statements; } if (condition) { statements; } else { statements; } if (condition1) { statements; } else if (condition2) { statements; } else { statements; } switch Statements switch (intExpression) { case value1: statements; break; ... case valuen: statements; break;...

Words: 73366 - Pages: 294

Premium Essay

Java

...that has made his work popular with programmers for many years. Michael Schidlowsky and Sedgewick have developed concise new Java implementations that both express the methods in a natural and direct manner and also can be used in real applications. Algorithms in Java, Third Edition, Part 5: Graph Algorithms is the second book in Sedgewick's thoroughly revised and rewritten series. The first book, Parts 1-4, addresses fundamental algorithms, data structures, sorting, and searching. A forthcoming third book will focus on strings, geometry, and a range of advanced algorithms. Each book's expanded coverage features new algorithms and implementations, enhanced descriptions and diagrams, and a wealth of new exercises for polishing skills. The natural match between Java classes and abstract data type (ADT) implementations makes the code more broadly useful and relevant for the modern object-oriented programming environment. The Web site for this book (www.cs.princeton.edu/~rs/) provides additional source code for programmers along with a variety of academic support materials for educators. Coverage includes: A complete overview of graph properties and types Diagraphs and DAGs Minimum spanning trees Shortest paths Network flows Diagrams, sample Java code, and detailed algorithm descriptions A landmark revision, Algorithms in Java, Third Edition, Part 5 provides a complete tool set for programmers to implement, debug, and use graph algorithms...

Words: 281 - Pages: 2

Free Essay

Java Programming

...A Programmer’s Guide to Java™ SCJP Certification Third Edition This page intentionally left blank A Programmer’s Guide to Java™ SCJP Certification A Comprehensive Primer Third Edition Khalid A. Mughal Rolf W. Rasmussen Upper Saddle River, New Jersey • Boston • Indianapolis • San Francisco New York • Toronto • Montreal • London • Munich • Paris • Madrid Capetown • Sidney • Tokyo • Singapore • Mexico City Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals. The authors and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests. For more information, please contact: U.S. Corporate and Government Sales (800) 382-3419 corpsales@pearsontechgroup.com For sales outside the United...

Words: 15086 - Pages: 61

Free Essay

Case Study

...Anx.31 J - M Sc CS (SDE) 2007-08 with MQP Page 1 of 16 Annexure No. SCAA Dated BHARATHIAR UNIVERSITY, COIMBATORE – 641 046 M. Sc COMPUTER SCIENCE For School of Distance Education (Effective from the academic Year 2007-2008) Scheme of Examinations 31 J 29.02.2008 Year Subject and Paper I Paper I Paper II Paper III Paper IV Practical I Paper V Paper VI Paper VII Practical II Project Advanced Computer Architecture Computer Graphics & Multimedia Software Engineering Computer Networks Computer Graphics and Multimedia Lab Advanced Operating System Internet programming and Web Design Data Mining and Warehousing Internet programming and Web Design Lab Project Work and Viva Voce Total University Examinations Durations Max in Hrs Marks 3 100 3 100 3 100 3 100 3 100 3 3 3 3 100 100 100 100 100 1000 II For project work and viva voce (External) Breakup: Project Evaluation : 75 Viva Voce : 25 1 Anx.31 J - M Sc CS (SDE) 2007-08 with MQP Page 2 of 16 YEAR – I PAPER I: ADVANCED COMPUTER ARCHITECTURE Subject Description: This paper presents the concept of parallel processing, solving problem in parallel processing, Parallel algorithms and different types of processors. Goal: To enable the students to learn the Architecture of the Computer. Objectives: On successful completion of the course the students should have: Understand the concept of Parallel Processing. Learnt the different types of Processors. Learnt the Parallel algorithms. Content: Unit I...

Words: 3613 - Pages: 15

Free Essay

Ds Java

...A Practical Introduction to Data Structures and Algorithm Analysis Third Edition (Java) Clifford A. Shaffer Department of Computer Science Virginia Tech Blacksburg, VA 24061 April 16, 2009 Copyright c 2008 by Clifford A. Shaffer. This document is the draft of a book to be published by Prentice Hall and may not be duplicated without the express written consent of either the author or a representative of the publisher. Contents Preface xiii I Preliminaries 1 1 Data Structures and Algorithms 1.1 A Philosophy of Data Structures 1.1.1 The Need for Data Structures 1.1.2 Costs and Benefits 1.2 Abstract Data Types and Data Structures 1.3 Design Patterns 1.3.1 Flyweight 1.3.2 Visitor 1.3.3 Composite 1.3.4 Strategy 1.4 Problems, Algorithms, and Programs 1.5 Further Reading 1.6 Exercises 3 4 4 6 8 12 13 14 15 16 17 19 21 2 Mathematical Preliminaries 2.1 Sets and Relations 2.2 Miscellaneous Notation 2.3 Logarithms 2.4 Summations and Recurrences 25 25 29 31 33 iii iv Contents 2.5 2.6 2.7 2.8 2.9 3 II 4 Recursion Mathematical Proof Techniques 2.6.1 Direct Proof 2.6.2 Proof by Contradiction 2.6.3 Proof by Mathematical Induction Estimating Further Reading Exercises Algorithm Analysis 3.1 Introduction 3.2 Best, Worst, and Average Cases 3.3 A Faster Computer, or a Faster Algorithm? 3.4 Asymptotic Analysis 3.4.1 Upper Bounds 3.4.2 Lower Bounds 3.4.3 Θ Notation 3.4.4 Simplifying...

Words: 30587 - Pages: 123

Free Essay

Seven Languages in Seven Weeks

... Venkat Subramaniam Award-winning author and founder, Agile Developer, Inc. As a programmer, the importance of being exposed to new programming languages, paradigms, and techniques cannot be overstated. This book does a marvelous job of introducing seven important and diverse languages in a concise—but nontrivial—manner, revealing their strengths and reasons for being. This book is akin to a dim-sum buffet for any programmer who is interested in exploring new horizons or evaluating emerging languages before committing to studying one in particular. Antonio Cangiano Software engineer and technical evangelist, IBM Fasten your seat belts, because you are in for a fast-paced journey. This book is packed with programming-language-learning action. Bruce puts it all on the line, and the result is an engaging, rewarding book that passionate programmers will thoroughly enjoy. If you love learning new languages, if you want to challenge your mind, if you want to take your programming skills to the next level—this book is for you. You will not be disappointed. Frederic Daoud Author, Stripes ...and Java Web Development Is Fun Again and Getting Started with Apache Click Prepared exclusively for Montelymard Do you want seven kick starts into learning your “language of the year”? Do you want your thinking challenged about programming in general? Look no further than this book. I personally was taken back in time to my...

Words: 85787 - Pages: 344

Free Essay

Concepts of Programming Languages

...CONCEPTS OF PROGRAMMING LANGUAGES TENTH EDITION This page intentionally left blank CONCEPTS OF PROGRAMMING LANGUAGES TENTH EDITION R O B E RT W. S EB ES TA University of Colorado at Colorado Springs Boston Columbus Indianapolis New York San Francisco Upper Saddle River Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto Delhi Mexico City Sao Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo Vice President and Editorial Director, ECS: Marcia Horton Editor in Chief: Michael Hirsch Executive Editor: Matt Goldstein Editorial Assistant: Chelsea Kharakozova Vice President Marketing: Patrice Jones Marketing Manager: Yez Alayan Marketing Coordinator: Kathryn Ferranti Marketing Assistant: Emma Snider Vice President and Director of Production: Vince O’Brien Managing Editor: Jeff Holcomb Senior Production Project Manager: Marilyn Lloyd Manufacturing Manager: Nick Sklitsis Operations Specialist: Lisa McDowell Cover Designer: Anthony Gemmellaro Text Designer: Gillian Hall Cover Image: Mountain near Pisac, Peru; Photo by author Media Editor: Dan Sandin Full-Service Vendor: Laserwords Project Management: Gillian Hall Printer/Binder: Courier Westford Cover Printer: Lehigh-Phoenix Color This book was composed in InDesign. Basal font is Janson Text. Display font is ITC Franklin Gothic. Copyright © 2012, 2010, 2008, 2006, 2004 by Pearson Education, Inc., publishing as Addison-Wesley. All rights reserved. Manufactured in the United States...

Words: 142253 - Pages: 570