Lab #2 Java s Basic Elements and Loan Calculator

Size: px
Start display at page:

Download "Lab #2 Java s Basic Elements and Loan Calculator"

Transcription

1 Lab #2 Java s Basic Elements and Loan Calculator Objectives: Introduce Java s primitive data types, assignment, arithmetic operators, and the String class. Walkthrough examples of the above. Problem Statement I: Write a Java program that extracts the digits in a four-digit number. 1. Consider the six steps in the SDLC. Analyze the problem. We assume the user will input a 4-digit number (no input validation at this stage), such as 3948, and the program should output the digits. e.g., 3, 9, 4, and 8. Develop an algorithm. To get first digit is easy: divide by 1000 integer division truncates remainder. But we need to capture the remainder in order to get the other digits. The modulus function captures the remainder. So, divide by 1000 first, print the result, replace the number by the modulus of that division, divide it by 100, and continue in similar fashion. Write the code. Here it is. Compile and execute the program in command prompt. /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Class: ExtractDigits * File: ExtractDigits.java * Description: Extract and display the four digits of a * four-digit number * Environment: PC, Windows XP Pro, jdk6.18, NetBeans 6.8 * Date: 9/30/ javax.swing.joptionpane * History Log: Updated from 10/2/2001, 4/13/2005, 9/14/2006 import javax.swing.joptionpane; public class ExtractDigits public static void main(string[] args) /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Method: main() * Description: Displays 4 digits and accesses command-line * arguments void args are the command line strings * Date: 9/30/2010 // Java, unlike C/C++, does not need argument count (argc) if (args.length < 2) 1

2 System.out.println("usage: java ExtractDigits <month> <year>"); System.exit(1); //Unlike C,C++, args[0] is the first argument int month = Integer.valueOf(args[0]).intValue(); int year = Integer.valueOf(args[1]).intValue(); //first arg on command line if (month < 1 month > 12) //illegal month System.out.println("Month must be between 1 and 12"); System.exit(1); if (year < 1970) System.out.println("Year must be greater than 1969"); System.exit(1); //display results System.out.print("The month you entered is "); System.out.println(month); System.out.print("The year you entered is "); System.out.println(year); String input = JOptionPane.showInputDialog("Please enter a 4-digit number"); String output = ""; int number = Integer.parseInt(input); System.out.print("The digits of " + number + " are "); output += "The digits of " + number + " are "; System.out.print(number/ ", "); // display thousand's digit output += number/ ", "; number %= 1000; // number = 814 System.out.print(number/100 + ", "); // display hudred's digit output += number/100 + ", "; number %= 100; // number = 14 System.out.print(number/10 + ", "); // display ten's digit output += number/10 + ", "; number %= 10; // number = 4 System.out.println(number + "."); output += number + "."; JOptionPane.showMessageDialog(null,output); System.exit(0); Test the program Compile and test the application with java ExtractDigits Document the program. Create a set of document files using javadoc ExtractDigits.java. Name all files that were generated. 2

3 2. Some detail comments are in order. Here are several notable points in the code above: The entire file consists of defining a public class, ExtractDigits, which has only the public static method main() every Java application must have this method (see my document Understanding Static.pdf for the keyword static). Two types of comments are used (there are three in all in Java): o Single line comments that begin anywhere with // o Javadoc comments that begin with /** and end with */ o The third kind of comment is the C/C++ style comment that begins with /* and ends with */ not seen in this example. Every lab and project that you do should have a class-level Javadoc comments for each class and method comments for each method, as shown above. Read my document JavaDocs.pdf on this requirement. The labs demonstrates the use of the String array variable args. Note that arrays in Java are 0-based (as in C/C++/C#/VB 2005) so args[0] contains 9 and args[1] reads and stores 2006 from the input line. Note also that the argument of main could be represented in two different ways: o public static void main(string[] args) o public static void main(string args[]) The second is more C/C++ like, but the first is preferred. There is nothing magical about the name args you could have named the argument mango, like this: o public static void main(string[] mango) In that case, however, any reference to args should be replaced with mango. Note that the 4-digit number is read via an InputDialog from the JOptionPane class hence the need for the line import javax.swing.joptionpane; At the heart of the calculations is the mod operator: % in Java. The mod operator returns the remainder in a division. Thus, 20 % 7 = 6 because 7 goes into 20 two times (that gives 14) with a remainder of 6. Also 5814 % 1000 = 814, 814 % 100 = 8, and so on. This is how the program extracts the digits. The division operator in Java, /, may seem bizarre. For example, 5814/1000 = 5, not Also 9/5 = 1, but 9.0/5=1.8. The logic is this: if both divisor and dividend are integers, / performs integer division with no remainder or decimals; if either one is a double or float, / performs real division with decimals as you might expect. Java allows for combined operators such as +=, -=, %=, *=, /=, and so on. Thus the lines output += number/100 + ", "; number %= 100; // number = 14 are just a short and more efficient version of 3

4 output = output + number/100 + ", "; number = number % 100; // number = 14 Note also that the + sign for strings is an overloaded operator for concatenation (but Java does not allow overloading of operators!!). 3. How would you change the program to allow input of any number of digits in a number? Problem Statement II: Write a Java program that calculates monthly payment for a loan, given the loan amount and annual interest rate. This is a totally separate problem from the above. Here is the code you should analyze the problem and write an algorithm before you code, checking with a calculator on known values. Note that two versions for reading the input are given: the older version using BufferedReader and InputStreamReader (commented out) with a separate method to do the reading, and the newer version using the Scanner class. /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Class: Ammortize * File: Ammortize.java * Description: Calculates monthly payment given * loan amount, interest, and years of loan * Environment: PC, Windows XP Pro, jdk6.0, NetBeans 5.5 * Date: 9/29/ java.io javax.text.numberformat * History Log: Updated from 10/2/2001, 4/13/2005, 6/29/2007 import java.io.*; import java.text.numberformat; import java.util.scanner; class Ammortize /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Method: main() * Description: Calculates monthly payment. Relies on two * member methods: inputfouble and payment void args are the command line strings * Date: 6/29/2007 public static void main (String args[]) double loanamount=0, interest=0, years=0; //create decimal format for currency NumberFormat moneyformat = NumberFormat.getCurrencyInstance(); // BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); // loanamount = inputdouble ("Enter the loan amount in dollars > ", in); // interest = inputdouble ("Enter the interest rate in percent > ", in); // years = inputdouble ("Enter the number of years > ", in); 4

5 Scanner keyboard = new Scanner(System.in); System.out.print ("Enter the loan amount in dollars > "); loanamount = keyboard.nextdouble(); System.out.print ("Enter the interest rate in percent > "); interest = keyboard.nextdouble(); System.out.print ("Enter the number of years > "); years = keyboard.nextdouble(); System.out.print ("The payment is: "); System.out.println (moneyformat.format(payment(loanamount, interest, years))); // end of main () /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Method: inputdouble() * Description: Prints a prompt and reads a double * BufferedReader double String: prompt BufferedReader: in java.io.bufferedreader * Date: 6/29/2007 static double inputdouble (String prompt, BufferedReader in) boolean error; // error detector String input = ""; // read input variable double value = 0; // converted input to a double type do error = false; System.out.print(prompt); System.out.flush(); try input = in.readline(); catch(ioexception e) System.out.println ("An input error was caught"); System.exit (1); try value = Double.valueOf(input).doubleValue(); catch (NumberFormatException e) System.out.println("Please try again"); error = true; while(error); return value; // end of inputdouble() /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Method: payment() * Description: prints a prompt and reads a double * BufferedReader 5

6 double double: amount double: interest double: years * Date: 6/29/2007 /* * payment method does the magic calculation * double amount loan amount * double interest interest rate, as a percentage * double years number of years */ static double payment(double amount, double interest, double years) /* * call the exponentiation and natural log functions as * static methods from the Math class */ double top = amount * interest / 1200; //double bot = 1 - Math.exp (years*(-12) * Math.log (1 + interest/1200)); double bot = 1 - Math.pow((1 + interest /1200), years *(-12)); return (top / bot); // end of payment () Problem Statement III: Modify problem statement II in order to implement it as a JFrame (GUI based) in NetBeans. 1. Start NetBeans. Choose File > New Project. Alternatively, you can click the New Project icon in the IDE toolbar. 2. In the Categories pane, select the Java node. In the Projects pane, choose Java Application. Click Next. 6

7 3. Type Loan Calculator in the Project Name field and specify a path e.g. in your home directory as the project location. Ensure that the Set as Main Project checkbox is selected and deselect the Create Main Class checkbox if it is selected. Click Finish. 4. In the Projects window, right-click the Loan Calculator node and choose New > JFrame Form. Enter Loan as the class name and click Finish (leave Package empty we ll use the default package). 5. Select JFrame in the Inspector Window (Window->Navigaing->Inspector). Right-click on it, select Set Layout and choose GridLayout. 6. Select the GridLayout andset the Columns property to 2 and Rows property to 7 in the Properties Window. 7. Select JFrame in the Inspector Window and set the title property to Loan Calculator. 8. From the Swing Controls in the Pallete drag and drop a Label onto the JFrame. Change its name in the Inspector to counterjlabel and set the font property in the Properties Window to Tahoma 14. Set the text property to Calculation Counter and set the horizontalalignment property to RIGHT. 9. From the Swing Controls in the Pallete drag and drop a Text Field onto the JFrame. Change its name in the Inspector to counterjtextfield and set the text property in the Properties Window to Tahoma 14 Bold. Set the text property to 1 and uncheck the editable checkbox. 10. From the Swing Controls in the Pallete drag and drop a Label onto the JFrame. Change its name in the Inspector to principaljlabel and set the text property in the Properties Window to Tahoma 14. Set the text property to Loan Amount and set the horizontalalignment property to RIGHT. 11. From the Swing Controls in the Pallete drag and drop a Text Field onto the JFrame. Change its name in the Inspector to principaljtextfield and set the text property in the Properties Window to Tahoma 14. Set the text property to the empty string (delete current text) and set the horizontalalignment property to RIGHT. 7

8 12. Continue in this fashion (you might want to copy and paste the JLabels, JButtons and the JTextFields) until you construct the UI to look like this: a. Note that you need to resize the JFrame. b. Set the mnemonic property of the Calculate JButton to C to enable the Alt-C combination as an accelerator key to fire the buton s event handler. Do the same for the Clear and Quit buttons. c. Note the names and the naming convention make sure yours are the same because the code refers to these controls by their names. d. Set the editable property of the counterjtextfield, paymentjtextfield and interestjtextfield to false (uncheck the editable check box) to make them read-only. 13. Declare a class instance variable counter and place it immediately after the class declation: int counter = 0; 14. Double-click on the Quit JButton and type the following code inside the event handler: // Exit the application System.exit(0); 15. Double-click on the Clear JButton and type the following code: // Clear the form and start afresh counter = 0; counterjtextfield.settext(""); principaljtextfield.settext(""); ratejtextfield.settext(""); yearsjtextfield.settext(""); paymentjtextfield.settext(""); interestjtextfield.settext(""); principaljtextfield.requestfocus(); 8

9 16. Right-click on the calculatejbutton and select Events->Action->actionPerformed (you could also double click on the calculatejbutton). This should take you to the code for the calculatejbutton event handler. 17. Inside the braces for this event handler type the following code and don t worry yet about the DecimalFormat error you need to import java.text. DecimalFormat coming up next. // Calculate payment on a loan try // get inputs double amount = Double.parseDouble(principalJTextField.getText()); double rate = Double.parseDouble(rateJTextField.getText()); double years = Double.parseDouble(yearsJTextField.getText()); boolean invalidinputs = (amount < 0 amount > rate < 0 rate > 100 years < 0 years > 100); if (invalidinputs) throw new NumberFormatException(); else // calculate payment using formula counter++; double payment = (amount * rate/1200)/(1 - Math.pow((1 + rate/1200), years * (-12))); double interest = years * payment * 12 - amount; DecimalFormat dollars = new DecimalFormat("$#,##0.00"); String result = dollars.format(payment); //display results counterjtextfield.settext(string.valueof(counter)); paymentjtextfield.settext(result); interestjtextfield.settext(dollars.format(interest)); catch(numberformatexception nume) JOptionPane.showMessageDialog(null, "Please enter a positive number for all required fields", "Input Error", JOptionPane.WARNING_MESSAGE); principaljtextfield.requestfocus(); principaljtextfield.selectall(); 18. Add the following three lines (plus comments) immediately after the initcomponents() in the default constructor in order to make the calculatejbutton default, add an icon to the form (required jpg image in the src folder) and set the cursor in the first input JTextField: // set calculatejbutton as default this.getrootpane().setdefaultbutton(calculatejbutton); // set icon for form this.seticonimage(toolkit.getdefaulttoolkit().getimage("src/javaconcepts.jpg")); principaljtextfield.requestfocus(); 9

10 19. Add the javadocs and import statements for the DecimalFormat, Toolkit, and for the JOptionPane class on the top of the source code but after the package statements. The entire top several lines should look like this: /**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Class: Loan * File: Loan.java * Description: Calculate loan payment given loan amount, interest * rate, and time of loan * Environment: PC, Windows XP Pro, jdk6.18, NetBeans 6.5 * Date: 9/29/ javax.swing.jframe * History Log: Updated from 10/2/2001, 4/13/2005, 6/29/2007 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ import java.awt.dimension; import java.awt.toolkit; import java.text.decimalformat; import javax.swing.*; 20. Choose Run > Run Main Project (F6). 21. If all is well, test the program against the following input/output: 22. Otherwise, debug it. 23. What can you do to improve this program? a. Disable the maximization of the form. b. Validate the input. c. Provide event handlers for at least the loan text field (so that pressing Enter calls the Calculate button event handler. d. Build a *.jar file (Shift-F11) in order to execute the program outside the NetBeans IDE. e. Create the Javadocs for the lab. 10

http://netbeans.org/kb/docs/java/gui-functionality.html?print=yes

http://netbeans.org/kb/docs/java/gui-functionality.html?print=yes Page 1 of 6 Introduction to GUI Building Contributed by Saleem Gul and Tomas Pavek, maintained by Ruth Kusterer and Irina Filippova This beginner tutorial teaches you how to create a simple graphical user

More information

Chapter 2. println Versus print. Formatting Output withprintf. System.out.println for console output. console output. Console Input and Output

Chapter 2. println Versus print. Formatting Output withprintf. System.out.println for console output. console output. Console Input and Output Chapter 2 Console Input and Output System.out.println for console output System.out is an object that is part of the Java language println is a method invoked dby the System.out object that can be used

More information

During the process of creating ColorSwitch, you will learn how to do these tasks:

During the process of creating ColorSwitch, you will learn how to do these tasks: GUI Building in NetBeans IDE 3.6 This short tutorial guides you through the process of creating an application called ColorSwitch. You will build a simple program that enables you to switch the color of

More information

Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane.

Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane. Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6 Handout 3 Strings and String Class. Input/Output with JOptionPane. Strings In Java strings are represented with a class type String. Examples:

More information

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language Translation Translating to Java Introduction to Computer Programming The job of a programmer is to translate a problem description into a computer language. You need to be able to convert a problem description

More information

Chulalongkorn University International School of Engineering Department of Computer Engineering 2140105 Computer Programming Lab.

Chulalongkorn University International School of Engineering Department of Computer Engineering 2140105 Computer Programming Lab. Chulalongkorn University Name International School of Engineering Student ID Department of Computer Engineering Station No. 2140105 Computer Programming Lab. Date Lab 2 Using Java API documents, command

More information

Introduction to Java

Introduction to Java Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high

More information

Tutorial: Time Of Day Part 2 GUI Design in NetBeans

Tutorial: Time Of Day Part 2 GUI Design in NetBeans Tutorial: Time Of Day Part 2 GUI Design in NetBeans October 7, 2010 Author Goals Kees Hemerik / Gerard Zwaan Getting acquainted with NetBeans GUI Builder Illustrate the separation between GUI and computation

More information

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca

More information

Comp 248 Introduction to Programming

Comp 248 Introduction to Programming Comp 248 Introduction to Programming Chapter 2 - Console Input & Output Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University, Montreal, Canada These slides has been

More information

Homework/Program #5 Solutions

Homework/Program #5 Solutions Homework/Program #5 Solutions Problem #1 (20 points) Using the standard Java Scanner class. Look at http://natch3z.blogspot.com/2008/11/read-text-file-using-javautilscanner.html as an exampleof using the

More information

Chapter 2 Introduction to Java programming

Chapter 2 Introduction to Java programming Chapter 2 Introduction to Java programming 1 Keywords boolean if interface class true char else package volatile false byte final switch while throws float private case return native void protected break

More information

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java

More information

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved. 1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays

More information

WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.

WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc. WA2099 Introduction to Java using RAD 8.0 Student Labs Web Age Solutions Inc. 1 Table of Contents Lab 1 - The HelloWorld Class...3 Lab 2 - Refining The HelloWorld Class...20 Lab 3 - The Arithmetic Class...25

More information

AP Computer Science Java Subset

AP Computer Science Java Subset APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall

More information

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

System.out.println(\nEnter Product Number 1-5 (0 to stop and view summary) : Benjamin Michael Java Homework 3 10/31/2012 1) Sales.java Code // Sales.java // Program calculates sales, based on an input of product // number and quantity sold import java.util.scanner; public class

More information

Chapter 3. Input and output. 3.1 The System class

Chapter 3. Input and output. 3.1 The System class Chapter 3 Input and output The programs we ve looked at so far just display messages, which doesn t involve a lot of real computation. This chapter will show you how to read input from the keyboard, use

More information

Introduction to Java. CS 3: Computer Programming in Java

Introduction to Java. CS 3: Computer Programming in Java Introduction to Java CS 3: Computer Programming in Java Objectives Begin with primitive data types Create a main class with helper methods Learn how to call built-in class methods and instance methods

More information

Sample CSE8A midterm Multiple Choice (circle one)

Sample CSE8A midterm Multiple Choice (circle one) Sample midterm Multiple Choice (circle one) (2 pts) Evaluate the following Boolean expressions and indicate whether short-circuiting happened during evaluation: Assume variables with the following names

More information

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4 JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4 NOTE: SUN ONE Studio is almost identical with NetBeans. NetBeans is open source and can be downloaded from www.netbeans.org. I

More information

Lab 5: Bank Account. Defining objects & classes

Lab 5: Bank Account. Defining objects & classes Lab 5: Bank Account Defining objects & classes Review: Basic class structure public class ClassName Fields Constructors Methods Three major components of a class: Fields store data for the object to use

More information

Creating a Simple, Multithreaded Chat System with Java

Creating a Simple, Multithreaded Chat System with Java Creating a Simple, Multithreaded Chat System with Java Introduction by George Crawford III In this edition of Objective Viewpoint, you will learn how to develop a simple chat system. The program will demonstrate

More information

In this Chapter you ll learn:

In this Chapter you ll learn: Now go, write it before them in a table, and note it in a book. Isaiah 30:8 To go beyond is as wrong as to fall short. Confucius Begin at the beginning, and go on till you come to the end: then stop. Lewis

More information

Example of a Java program

Example of a Java program Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);

More information

How to Install Java onto your system

How to Install Java onto your system How to Install Java onto your system 1. In your browser enter the URL: Java SE 2. Choose: Java SE Downloads Java Platform (JDK) 7 jdk-7- windows-i586.exe. 3. Accept the License Agreement and choose the

More information

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)

More information

IRA EXAMPLES. This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account).

IRA EXAMPLES. This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account). IRA EXAMPLES This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account). Definite Counting Loop Example IRA After x Years This first example illustrates

More information

Using Files as Input/Output in Java 5.0 Applications

Using Files as Input/Output in Java 5.0 Applications Using Files as Input/Output in Java 5.0 Applications The goal of this module is to present enough information about files to allow you to write applications in Java that fetch their input from a file instead

More information

How to test and debug an ASP.NET application

How to test and debug an ASP.NET application Chapter 4 How to test and debug an ASP.NET application 113 4 How to test and debug an ASP.NET application If you ve done much programming, you know that testing and debugging are often the most difficult

More information

2 Getting Started with jgrasp 2.0

2 Getting Started with jgrasp 2.0 2 Getting Started with jgrasp 2.0 After you have successfully installed the Java JDK and jgrasp, you are ready to get started. For the examples in this section, Microsoft Windows and Java will be used.

More information

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasket { public static void main(string[]

More information

IBM Operational Decision Manager Version 8 Release 5. Getting Started with Business Rules

IBM Operational Decision Manager Version 8 Release 5. Getting Started with Business Rules IBM Operational Decision Manager Version 8 Release 5 Getting Started with Business Rules Note Before using this information and the product it supports, read the information in Notices on page 43. This

More information

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java

More information

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75 Preet raj Core Java and Databases CS4PR Time Allotted: 3 Hours Final Exam: Total Possible Points 75 Q1. What is difference between overloading and overriding? 10 points a) In overloading, there is a relationship

More information

CSS 543 Program 3: Online Tic-Tac-Toe Game Professor: Munehiro Fukuda Due date: see the syllabus

CSS 543 Program 3: Online Tic-Tac-Toe Game Professor: Munehiro Fukuda Due date: see the syllabus CSS 543 Program 3: Online Tic-Tac-Toe Game Professor: Munehiro Fukuda Due date: see the syllabus 1. Purpose This assignment exercises how to write a peer-to-peer communicating program using non-blocking

More information

Chapter 2 Elementary Programming

Chapter 2 Elementary Programming Chapter 2 Elementary Programming 2.1 Introduction You will learn elementary programming using Java primitive data types and related subjects, such as variables, constants, operators, expressions, and input

More information

Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard

Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard INPUT & OUTPUT I/O Example Using keyboard input for characters import java.util.scanner; class Echo{ public static void main (String[] args) { Scanner sc = new Scanner(System.in); // scanner for the keyboard

More information

public static void main(string[] args) { System.out.println("hello, world"); } }

public static void main(string[] args) { System.out.println(hello, world); } } Java in 21 minutes hello world basic data types classes & objects program structure constructors garbage collection I/O exceptions Strings Hello world import java.io.*; public class hello { public static

More information

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction INTRODUCTION TO COMPUTER PROGRAMMING Richard Pierse Class 7: Object-Oriented Programming Introduction One of the key issues in programming is the reusability of code. Suppose that you have written a program

More information

CS170 Lab 11 Abstract Data Types & Objects

CS170 Lab 11 Abstract Data Types & Objects CS170 Lab 11 Abstract Data Types & Objects Introduction: Abstract Data Type (ADT) An abstract data type is commonly known as a class of objects An abstract data type in a program is used to represent (the

More information

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner java.util.scanner java.util.scanner is a class in the Java API used to create a Scanner object, an extremely versatile object that you can use to input alphanumeric characters from several input sources

More information

To launch the Microsoft Excel program, locate the Microsoft Excel icon, and double click.

To launch the Microsoft Excel program, locate the Microsoft Excel icon, and double click. EDIT202 Spreadsheet Lab Assignment Guidelines Getting Started 1. For this lab you will modify a sample spreadsheet file named Starter- Spreadsheet.xls which is available for download from the Spreadsheet

More information

Object-Oriented Programming in Java

Object-Oriented Programming in Java CSCI/CMPE 3326 Object-Oriented Programming in Java Class, object, member field and method, final constant, format specifier, file I/O Dongchul Kim Department of Computer Science University of Texas Rio

More information

Part I. Multiple Choice Questions (2 points each):

Part I. Multiple Choice Questions (2 points each): Part I. Multiple Choice Questions (2 points each): 1. Which of the following is NOT a key component of object oriented programming? (a) Inheritance (b) Encapsulation (c) Polymorphism (d) Parallelism ******

More information

Microsoft Access 3: Understanding and Creating Queries

Microsoft Access 3: Understanding and Creating Queries Microsoft Access 3: Understanding and Creating Queries In Access Level 2, we learned how to perform basic data retrievals by using Search & Replace functions and Sort & Filter functions. For more complex

More information

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O 1 Sending Output to a (Text) File import java.util.scanner; import java.io.*; public class TextFileOutputDemo1 public static void

More information

Course Intro Instructor Intro Java Intro, Continued

Course Intro Instructor Intro Java Intro, Continued Course Intro Instructor Intro Java Intro, Continued The syllabus Java etc. To submit your homework, do Team > Share Your repository name is csse220-200830-username Use your old SVN password. Note to assistants:

More information

6.1. Example: A Tip Calculator 6-1

6.1. Example: A Tip Calculator 6-1 Chapter 6. Transition to Java Not all programming languages are created equal. Each is designed by its creator to achieve a particular purpose, which can range from highly focused languages designed for

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

Advanced Network Programming Lab using Java. Angelos Stavrou

Advanced Network Programming Lab using Java. Angelos Stavrou Advanced Network Programming Lab using Java Angelos Stavrou Table of Contents A simple Java Client...3 A simple Java Server...4 An advanced Java Client...5 An advanced Java Server...8 A Multi-threaded

More information

AP Computer Science Static Methods, Strings, User Input

AP Computer Science Static Methods, Strings, User Input AP Computer Science Static Methods, Strings, User Input Static Methods The Math class contains a special type of methods, called static methods. A static method DOES NOT operate on an object. This is because

More information

Chapter 2: Elements of Java

Chapter 2: Elements of Java Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction

More information

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013 Masters programmes in Computer Science and Information Systems Object-Oriented Design and Programming Sample module entry test xxth December 2013 This sample paper has more questions than the real paper

More information

CS 111 Classes I 1. Software Organization View to this point:

CS 111 Classes I 1. Software Organization View to this point: CS 111 Classes I 1 Software Organization View to this point: Data Objects and primitive types Primitive types operators (+, /,,*, %). int, float, double, char, boolean Memory location holds the data Objects

More information

VB.NET Programming Fundamentals

VB.NET Programming Fundamentals Chapter 3 Objectives Programming Fundamentals In this chapter, you will: Learn about the programming language Write a module definition Use variables and data types Compute with Write decision-making statements

More information

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10) File class in Java File Input and Output (Savitch, Chapter 10) TOPICS File Input Exception Handling File Output Programmers refer to input/output as "I/O". The File class represents files as objects. The

More information

BIGPOND ONLINE STORAGE USER GUIDE Issue 1.1.0-18 August 2005

BIGPOND ONLINE STORAGE USER GUIDE Issue 1.1.0-18 August 2005 BIGPOND ONLINE STORAGE USER GUIDE Issue 1.1.0-18 August 2005 PLEASE NOTE: The contents of this publication, and any associated documentation provided to you, must not be disclosed to any third party without

More information

J a v a Quiz (Unit 3, Test 0 Practice)

J a v a Quiz (Unit 3, Test 0 Practice) Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points

More information

Lab 1A. Create a simple Java application using JBuilder. Part 1: make the simplest Java application Hello World 1. Start Jbuilder. 2.

Lab 1A. Create a simple Java application using JBuilder. Part 1: make the simplest Java application Hello World 1. Start Jbuilder. 2. Lab 1A. Create a simple Java application using JBuilder In this lab exercise, we ll learn how to use a Java integrated development environment (IDE), Borland JBuilder 2005, to develop a simple Java application

More information

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq Introduction to Programming using Java wertyuiopasdfghjklzxcvbnmqwertyui

More information

Microsoft PowerPoint 2010 Handout

Microsoft PowerPoint 2010 Handout Microsoft PowerPoint 2010 Handout PowerPoint is a presentation software program that is part of the Microsoft Office package. This program helps you to enhance your oral presentation and keep the audience

More information

Introduction to Java Applets (Deitel chapter 3)

Introduction to Java Applets (Deitel chapter 3) Introduction to Java Applets (Deitel chapter 3) 1 2 Plan Introduction Sample Applets from the Java 2 Software Development Kit Simple Java Applet: Drawing a String Drawing Strings and Lines Adding Floating-Point

More information

AP Computer Science Java Mr. Clausen Program 9A, 9B

AP Computer Science Java Mr. Clausen Program 9A, 9B AP Computer Science Java Mr. Clausen Program 9A, 9B PROGRAM 9A I m_sort_of_searching (20 points now, 60 points when all parts are finished) The purpose of this project is to set up a program that will

More information

SQL Server 2005: Report Builder

SQL Server 2005: Report Builder SQL Server 2005: Report Builder Table of Contents SQL Server 2005: Report Builder...3 Lab Setup...4 Exercise 1 Report Model Projects...5 Exercise 2 Create a Report using Report Builder...9 SQL Server 2005:

More information

13 File Output and Input

13 File Output and Input SCIENTIFIC PROGRAMMING -1 13 File Output and Input 13.1 Introduction To make programs really useful we have to be able to input and output data in large machinereadable amounts, in particular we have to

More information

Lab 9 Access PreLab Copy the prelab folder, Lab09 PreLab9_Access_intro

Lab 9 Access PreLab Copy the prelab folder, Lab09 PreLab9_Access_intro Lab 9 Access PreLab Copy the prelab folder, Lab09 PreLab9_Access_intro, to your M: drive. To do the second part of the prelab, you will need to have available a database from that folder. Creating a new

More information

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C Basic Java Constructs and Data Types Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C 1 Contents Hello World Program Statements Explained Java Program Structure in

More information

Building and Using Web Services With JDeveloper 11g

Building and Using Web Services With JDeveloper 11g Building and Using Web Services With JDeveloper 11g Purpose In this tutorial, you create a series of simple web service scenarios in JDeveloper. This is intended as a light introduction to some of the

More information

Debugging Java Applications

Debugging Java Applications Debugging Java Applications Table of Contents Starting a Debugging Session...2 Debugger Windows...4 Attaching the Debugger to a Running Application...5 Starting the Debugger Outside of the Project's Main

More information

Install Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html

Install Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html CS 259: Data Structures with Java Hello World with the IntelliJ IDE Instructor: Joel Castellanos e-mail: joel.unm.edu Web: http://cs.unm.edu/~joel/ Office: Farris Engineering Center 319 8/19/2015 Install

More information

An Overview of Java. overview-1

An Overview of Java. overview-1 An Overview of Java overview-1 Contents What is Java Major Java features Java virtual machine Java programming language Java class libraries (API) GUI Support in Java Networking and Threads in Java overview-2

More information

Ohio University Computer Services Center August, 2002 Crystal Reports Introduction Quick Reference Guide

Ohio University Computer Services Center August, 2002 Crystal Reports Introduction Quick Reference Guide Open Crystal Reports From the Windows Start menu choose Programs and then Crystal Reports. Creating a Blank Report Ohio University Computer Services Center August, 2002 Crystal Reports Introduction Quick

More information

Manual For Using the NetBeans IDE

Manual For Using the NetBeans IDE 1 Manual For Using the NetBeans IDE The content of this document is designed to help you to understand and to use the NetBeans IDE for your Java programming assignments. This is only an introductory presentation,

More information

C++ INTERVIEW QUESTIONS

C++ INTERVIEW QUESTIONS C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get

More information

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand: Introduction to Programming and Algorithms Module 2 CS 146 Sam Houston State University Dr. Tim McGuire Introduction To Computers And Java Chapter Objectives To understand: the meaning and placement of

More information

Some Scanner Class Methods

Some Scanner Class Methods Keyboard Input Scanner, Documentation, Style Java 5.0 has reasonable facilities for handling keyboard input. These facilities are provided by the Scanner class in the java.util package. A package is a

More information

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. Scanner The Scanner class is intended to be used for input. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. For example, suppose the input

More information

Explain the relationship between a class and an object. Which is general and which is specific?

Explain the relationship between a class and an object. Which is general and which is specific? A.1.1 What is the Java Virtual Machine? Is it hardware or software? How does its role differ from that of the Java compiler? The Java Virtual Machine (JVM) is software that simulates the execution of a

More information

www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 www.virtualians.pk

www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 Which of the following is a general purpose container? JFrame Dialog JPanel JApplet Which of the following package needs to be import while handling

More information

Graphical User Interfaces

Graphical User Interfaces M14_REGE1813_02_SE_C14.qxd 2/10/10 3:43 PM Page 822 Chapter14 Graphical User Interfaces 14.1 GUI Basics Graphical Input and Output with Option Panes Working with Frames Buttons, Text Fields, and Labels

More information

Getting Started with Excel 2008. Table of Contents

Getting Started with Excel 2008. Table of Contents Table of Contents Elements of An Excel Document... 2 Resizing and Hiding Columns and Rows... 3 Using Panes to Create Spreadsheet Headers... 3 Using the AutoFill Command... 4 Using AutoFill for Sequences...

More information

Creating Database Tables in Microsoft SQL Server

Creating Database Tables in Microsoft SQL Server Creating Database Tables in Microsoft SQL Server Microsoft SQL Server is a relational database server that stores and retrieves data for multi-user network-based applications. SQL Server databases are

More information

BID2WIN Workshop. Advanced Report Writing

BID2WIN Workshop. Advanced Report Writing BID2WIN Workshop Advanced Report Writing Please Note: Please feel free to take this workbook home with you! Electronic copies of all lab documentation are available for download at http://www.bid2win.com/userconf/2011/labs/

More information

Solutions from SAP. SAP Business One 2005 SP01. User Interface. Standards and Guidelines. January 2006

Solutions from SAP. SAP Business One 2005 SP01. User Interface. Standards and Guidelines. January 2006 Solutions from SAP SAP Business One 2005 SP01 User Interface Standards and Guidelines January 2006 Table of Contents Icons... 5 Typographic Conventions... 5 1. Overview... 6 2. General Issues... 6 2.1

More information

Statgraphics Getting started

Statgraphics Getting started Statgraphics Getting started The aim of this exercise is to introduce you to some of the basic features of the Statgraphics software. Starting Statgraphics 1. Log in to your PC, using the usual procedure

More information

Java CPD (I) Frans Coenen Department of Computer Science

Java CPD (I) Frans Coenen Department of Computer Science Java CPD (I) Frans Coenen Department of Computer Science Content Session 1, 12:45-14:30 (First Java Programme, Inheritance, Arithmetic) Session 2, 14:45-16:45 (Input and Programme Constructs) Materials

More information

WRITING DATA TO A BINARY FILE

WRITING DATA TO A BINARY FILE WRITING DATA TO A BINARY FILE TEXT FILES VS. BINARY FILES Up to now, we have looked at how to write and read characters to and from a text file. Text files are files that contain sequences of characters.

More information

Java Programming Fundamentals

Java Programming Fundamentals Lecture 1 Part I Java Programming Fundamentals Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Introduction to Java We start by making a few

More information

Syllabus for CS 134 Java Programming

Syllabus for CS 134 Java Programming - Java Programming Syllabus Page 1 Syllabus for CS 134 Java Programming Computer Science Course Catalog 2000-2001: This course is an introduction to objectoriented programming using the Java language.

More information

JustClust User Manual

JustClust User Manual JustClust User Manual Contents 1. Installing JustClust 2. Running JustClust 3. Basic Usage of JustClust 3.1. Creating a Network 3.2. Clustering a Network 3.3. Applying a Layout 3.4. Saving and Loading

More information

Visual Basic 2010 Essentials

Visual Basic 2010 Essentials Visual Basic 2010 Essentials Visual Basic 2010 Essentials First Edition 2010 Payload Media. This ebook is provided for personal use only. Unauthorized use, reproduction and/or distribution strictly prohibited.

More information

Excel 2003 Tutorial I

Excel 2003 Tutorial I This tutorial was adapted from a tutorial by see its complete version at http://www.fgcu.edu/support/office2000/excel/index.html Excel 2003 Tutorial I Spreadsheet Basics Screen Layout Title bar Menu bar

More information

IBM Tivoli Workload Scheduler Integration Workbench V8.6.: How to customize your automation environment by creating a custom Job Type plug-in

IBM Tivoli Workload Scheduler Integration Workbench V8.6.: How to customize your automation environment by creating a custom Job Type plug-in IBM Tivoli Workload Scheduler Integration Workbench V8.6.: How to customize your automation environment by creating a custom Job Type plug-in Author(s): Marco Ganci Abstract This document describes how

More information

Programming with Java GUI components

Programming with Java GUI components Programming with Java GUI components Java includes libraries to provide multi-platform support for Graphic User Interface objects. The multi-platform aspect of this is that you can write a program on a

More information

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be: Lecture 7 Picking Balls From an Urn The problem: An urn has n (n = 10) balls numbered from 0 to 9 A ball is selected at random, its' is number noted, it is set aside, and another ball is selected from

More information

Netbeans IDE Tutorial for using the Weka API

Netbeans IDE Tutorial for using the Weka API Netbeans IDE Tutorial for using the Weka API Kevin Amaral University of Massachusetts Boston First, download Netbeans packaged with the JDK from Oracle. http://www.oracle.com/technetwork/java/javase/downloads/jdk-7-netbeans-download-

More information

Lecture J - Exceptions

Lecture J - Exceptions Lecture J - Exceptions Slide 1 of 107. Exceptions in Java Java uses the notion of exception for 3 related (but different) purposes: Errors: an internal Java implementation error was discovered E.g: out

More information

Tutorial: Building a Dojo Application using IBM Rational Application Developer Loan Payment Calculator

Tutorial: Building a Dojo Application using IBM Rational Application Developer Loan Payment Calculator Tutorial: Building a Dojo Application using IBM Rational Application Developer Loan Payment Calculator Written by: Chris Jaun (cmjaun@us.ibm.com) Sudha Piddaparti (sudhap@us.ibm.com) Objective In this

More information

Hands-On Lab. Building a Data-Driven Master/Detail Business Form using Visual Studio 2010. Lab version: 1.0.0. Last updated: 12/10/2010.

Hands-On Lab. Building a Data-Driven Master/Detail Business Form using Visual Studio 2010. Lab version: 1.0.0. Last updated: 12/10/2010. Hands-On Lab Building a Data-Driven Master/Detail Business Form using Visual Studio 2010 Lab version: 1.0.0 Last updated: 12/10/2010 Page 1 CONTENTS OVERVIEW... 3 EXERCISE 1: CREATING THE APPLICATION S

More information