Program 12 - Spring 2018
|
|
- Tamsin Norris
- 6 years ago
- Views:
Transcription
1 CIST 1400, Introduction to Computer Programming Programming Assignment Program 12 - Spring 2018 Overview of Program Earlier this semester, you have written programs that read and processed dates in various ways. You will read dates from an external text file and identify which two dates in the file have the fewest number of days between them and which two dates have the largest number of days between them and output those pairs of dates and the number of days between each pair. For this program, you will be provided with a Date class that you will use to store and process dates with so that you don't have to manage that information manually. This should enable you to focus on the logic of the program itself rather than adding in details of storing and processing the dates. NOTE: See later in the assignment for details on how the output should be formatted. Writing two methods on your own For this program, you will also need to implement at least two additional methods other than main(). These methods can accomplish whatever task you want them to, such as: read the file of dates, sort an array of dates, display the list of dates, find the smallest range between two dates, find the largest range of dates between two dates, etc. The methods you write will need to have complete Javadoc documentation and be used (called) at least once each during your program's execution. It is acceptable to write more than two additional methods if you would like in order to practice breaking programs into smaller, more manageable units of code.
2 Format of the file The file that you will read dates from will look like this: 5 1/1/1900 1/2/ /5/1798 7/4/3001 8/1/2028 The first value of the file will be an int value indicating how many dates will be present in the file. The value could be any value from 2 and up. Each file will be guaranteed to have at least two dates in it. Each date in the file will be on a line by itself and will be in the format of MM/DD/YYYY, where MM is the month, DD is the day, and YYYY is the year. Information about easily processing dates in this format is discussed later in this document. For this program, all dates in a file will be valid dates, but functionality is provided within the Date class to identify invalid dates and handle them appropriately. There may be duplicate entries for the same date in the file. Dates can be in the range 1/1/1753 to 12/31/3000. Reading input from a file instead of the keyboard In order to process a file for input instead of keyboard input, you'll need to be able to open and read from a separate text file in Java. There are a number of different ways to do this, and you'll explore more involved ways to process files if you take more programming courses, but for what we need this semester we'll create a Scanner that is attached to a file so that input will basically behave the same way that you've been processing things all semester, just from a file instead of the keyboard. To practice with this idea, first create a file named test.txt in the same directory that your program file will reside in that looks like this:
3 Now edit a file called TestingFileInput.java in jgrasp and place the following code into it. Compile and run the code to see what it does. Pay close attention to the throws FileNotFoundException code added to the header of the main() method, which is new and only necessary right now when processing external files: import java.util.scanner; import java.io.file; Import java.io.filenotfoundexception; Java public class TestingFileInput { public static void main (String args[]) throws FileNotFoundException { // Create a regular Scanner for keyboard input Scanner keyboard = new Scanner(System.in); // Now create a String variable and read the filename System.out.println("Enter input filename: "); String infile; // Notice the use of the System.in Scanner for this input infile = keyboard.next(); // Need to create a File variable based on the infile file name File file = new File(inFile); // Now create a Scanner attached to the file instead of System.in // This Scanner will be used for file input!!! Scanner fileinput = new Scanner(file); // Read something out of the file, which is an integer int v1 = fileinput.nextint(); System.out.println("First int of the file is : " + v1); // Set up a loop that reads the rest of the int data from the file System.out.println ( "Now reading the rest of the data!" ); for (int which = 0; which < v1; which++) { int v = fileinput.nextint(); System.out.printf("A value from the file: %d\n", v); } } }
4 The code doesn't compile with a really weird error! Your program may not compile with an error that looks like this: FileInput.java:18: error: unreported exception FileNotFoundException; must be caught or declared to be thrown Scanner fileinput = new Scanner(file); If this happens, make sure you go back and add in the throws FileNotFoundException code on the main() method header line. This should take care of that situation. The program uses multiple Scanner variables! What? You should notice that the example program creates two different Scanner variables. Variable keyboard is used to read the filename from the keyboard, as we've been doing all semester so far. Variable fileinput is connected to an external file to pull data from. Okay, it compiles and runs... what now? When you run the code and are prompted for a file name, enter test.txt or whatever you called the file you created. If the file exists, the program should read the data from that file and output it to the screen. Notice what happens when you enter a filename that doesn't exist; the program should exit with some sort of error like this: Exception in thread "main" java.io.filenotfoundexception: test.data (No such file or directory) at java.base/java.io.fileinputstream.open0(native Method) at java.base/java.io.fileinputstream.open(fileinputstream.java:196) at java.base/java.io.fileinputstream.<init>(fileinputstream.java:139) at java.base/java.util.scanner.<init>(scanner.java:611) at FileInput.main(FileInput.java:18) It is important and imperative that you work with this code until you are certain you have a good handle on how it's setting up an external file for reading before moving on to the next part of the assignment.
5 What can objects of the Date class do? A Date object can store a date between 1/1/1753 and 12/31/3000. Objects of Date class have the following public methods available for you to use. Please note that you do not need to write these methods; they are available for you to use in the Date class that is provided in the Date.class file you will download. You don't need to use any import statements or anything fancy to use the Date class. Just create a new Date object in your program using the constructor as described below and you can move forward from there. Method Date() Description and Example Default constructor, used to create a new Date object. The date is set to 1/1/1753. Date d1 = new Date(); Date(int m, int d, int y) Specific constructor, used to create a new Date object with a given date. Date d2 = new Date(11,27,2017); setdate(int m, int d, int y) Attempts to set the date to the given month m, day d, and year y. Returns true if the date was valid. Returns false and sets the date to 1/1/1753 if the attempted date was invalid. d1.setdate(4,1,2018); dayssince1753() Returns an int value denoting how many days since 1/1/1753 the object's date is. int w = d2.dayssince1753(); tostring() Allows printing of the object's date. System.out.print(d2);
6 Determining Closest and Furthest Dates Closest Dates The closest dates will be determined by comparing each date to all of the dates in the file except for itself. The result may be 0, but only if there are duplicate dates in the file. Furthest Dates The furthest dates will also be determined by comparing each date to all of the dates in the file except itself. Given the storage range of dates possible in a Date object, the maximum number of days between dates could be Examples See the sample runs at the end of the file for examples of different results. Considerations for Entering and Validating Dates Entering Dates For previous assignments when entering dates, the month, day, and year needed to be entered separately. For this assignment, you'll change a property of the Scanner attached to the file that you create so that you can read dates in MM/DD/YYYY format. By default, a Scanner uses whitespace like spaces and newlines (enter/return) to identify different pieces of input, like this: Scanner get = new Scanner( System.in ); Java System.out.print("Enter your date: "); int m = get.nextint(); int d = get.nextint(); int y = get.nextint();
7 Input to this code could be entered like this: Enter your date: or like this: Enter your date: Either way, variable m would get a value of 4, variable d would get a value of 16 and variable y would get a value of Changing Scanner behavior In order to enter dates in MM/DD/YYYY format, using slashes, the Scanner attached to your file needs to behave differently. The easiest way to do this is to change the way the Scanner reads values from the keyboard. As mentioned in the last section, a Scanner uses whitespace as a delimiter between input by default. To change this behavior, you can use the usedelimiter() method from the Scanner class. More information about the usedelimiter() method can be found at To enable a Scanner to use, for instance, slashes / as delimiters in addition to spaces, you can use the following code in your program: Scanner get = new Scanner( System.in ); get.usedelimiter("[/\\s+]+"); // notice two backslashes here! Java System.out.print("Enter your date: "); int m = get.nextint(); int d = get.nextint(); int y = get.nextint(); Now, dates can be entered in any of the following four ways: Enter your date:
8 or Enter your date: or Enter your date: 4/16/2018 or Enter your date: 4 / 16 / 2018 The usedelimiter() method changes the behavior of the Scanner by providing a list of items that can be seen as delimiters between pieces of information. [/\\s+]+ tells Java that it can use either a forward slash / or a whitespace character \s (such as space, return, etc) to identify different inputs. The key to having this work with input from a text file is to apply the.usedelimiter() method to the Scanner you would like to change the behavior of. So, if you have a Scanner attached to a file, then you want to use the.usedelimiter() method on that Scanner.
9 Output The output of your program should look like the following sample: Enter filename to process: d1.txt The sorted dates from the file are: 1: 11/30/1955 2: 11/23/2015 3: 11/24/2015 4: 11/25/2015 5: 11/26/2015 6: 11/28/2015 7: 11/29/2015 8: 11/30/2015 9: 12/02/ : 02/23/2016 Closest (1): 11/23/2015 and 11/24/2015 Furthest (22000): 11/30/1955 and 02/23/2016 Make sure to include the following items in the format seen above: The program should output a list of the dates themselves, one per line, sorted from earliest date to latest date. Then output the dates that are "closest" to each other, including the number of days between the two dates, in "sorted" order with the earlier date listed first. Finally, output the dates that are the "furthest" from each other, including the number of days between the two dates, in sorted order with the earlier date listed first. Get a copy of the files to work with, including the Date class You can download a ZIP file containing 8 sample data files, the Date.class file containing the Date class to work with, and starter code that sets up the code to read from a file for you to work with from Canvas.
10 Download and unzip the compressed file and you should have the following files: File Date.class FileOfDates.java d1.txt - d8.txt Description The compiled class file that you can use for the Date class The starter code you can use to begin your program The files of dates to process Goals Use a non-standard, predefined class to implement a solution to a program. Read data from a text file Perform sorting on an array of objects Class and File Naming Name your class FileOfDates and source file FileOfDates.java. Testing Your Program Check out the sample run at the end of the assignment as well as some other example data values to test. Working With New Concepts / Developing This Program Before diving into working with the Date class for this program, it would be useful to write a small program that uses the Date class in a number of different ways so that you practice with the methods of this class and are familiar with the way they work. You will need to store the dates you read from the file into an array. Working with an array of Date objects behaves the same way that working with an array of String objects does. Grading Notes For the output, follow the format of the sample runs as closely as possible. The order of the dates for the closest and furthest dates can be in either order. Additionally, you must have a completed Collaboration document on file in order for the program to be graded.
11 Grading Rubric NOTE: If your submitted assignment does not compile, you will receive 0 points. We are unable to test code that does not compile. Insuring that your code compiles is critical when developing programs. We would rather grade an incomplete yet operational program than a program that we can't test. Item Points Notes Style/Coding (WebCAT): Documentation/style of source code Design/Readability (GA): Useful variable names Write additional methods (GA) Have header documentation that includes your name and other relevant information and javadoc for all methods. Meets expectations in CIST1400-checkstyle_intermediate.xml. Consistently use descriptive variable names, and code is well thought out. Implement, use, and adequately document at least two additional methods in your program Correctness/Testing: TaskXX() testing 24 Follow expected output as shown in Sample runs.
12 Sample Run for file d2.txt Enter filename to process: d2.txt The dates from the file are: 1: 01/01/1753 2: 11/27/2017 Closest (96754): 01/01/1753 and 11/27/2017 Furthest (96754): 01/01/1753 and 11/27/2017 Some Other Test Data From Files Included in Copied Directory File Number of Dates Closest Days Closest Dates Furthest Days Furthest Dates d1.txt /23/2015 and 11/24/ /23/2016 and 11/30/1955 d2.txt /01/1753 and 11/27/ /27/2017 and 01/01/1753 d3.txt /27/2017 and 11/28/ /29/2019 and 11/27/2017 d4.txt /06/2679 and 01/22/ /04/1826 and 01/15/2969 d5.txt /17/1928 and 08/21/ /22/1763 and 09/05/2993 d6.txt /29/2100 and 05/29/ /23/2096 and 07/07/2972 d7.txt /22/2648 and 12/19/ /22/1774 and 02/18/2998 d8.txt /14/2577 and 07/15/ /19/1781 and 11/30/3000
Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics
WIT COMP1000 Java Basics Java Origins Java was developed by James Gosling at Sun Microsystems in the early 1990s It was derived largely from the C++ programming language with several enhancements Java
More informationSelec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal
Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program
More informationCOMP-202 Unit 9: Exceptions
COMP-202 Unit 9: Exceptions Course Evaluations Please do these. -Fast to do -Used to improve course for future. (Winter 2011 had 6 assignments reduced to 4 based on feedback!) 2 Avoiding errors So far,
More informationWentworth Institute of Technology. Engineering & Technology WIT COMP1000. File Input and Output
WIT COMP1000 File Input and Output I/O I/O stands for Input/Output So far, we've used a Scanner object based on System.in for all input (from the user's keyboard) and System.out for all output (to the
More informationFirst Java Program - Output to the Screen
First Java Program - Output to the Screen These notes are written assuming that the reader has never programmed in Java, but has programmed in another language in the past. In any language, one of the
More informationCOMP-202 Unit 9: Exceptions
COMP-202 Unit 9: Exceptions Announcements - Assignment 4: due Monday April 16th - Assignment 4: tutorial - Final exam tutorial next week 2 Exceptions An exception is an object that describes an unusual
More informationComputer Science is...
Computer Science is... Computational complexity theory Complexity theory is the study of how algorithms perform with an increase in input size. All problems (like is n a prime number? ) fit inside a hierarchy
More informationReading Input from Text File
Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Lab 5 Reading Input from Text File Eng. Mohammed Alokshiya November 2, 2014 The simplest
More informationSelec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal
Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program
More informationMidterm Examination (MTA)
M105: Introduction to Programming with Java Midterm Examination (MTA) Spring 2013 / 2014 Question One: [6 marks] Choose the correct answer and write it on the external answer booklet. 1. Compilers and
More informationAdvanced Java Concept Unit 1. Mostly Review
Advanced Java Concept Unit 1. Mostly Review Program 1. Create a class that has only a main method. In the main method create an ArrayList of Integers (remember the import statement). Add 10 random integers
More informationObject-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 informationIntroduction to Computer Science Unit 2. Exercises
Introduction to Computer Science Unit 2. Exercises Note: Curly brackets { are optional if there is only one statement associated with the if (or ) statement. 1. If the user enters 82, what is 2. If the
More informationCOMP200 INPUT/OUTPUT. OOP using Java, based on slides by Shayan Javed
1 1 COMP200 INPUT/OUTPUT OOP using Java, based on slides by Shayan Javed Input/Output (IO) 2 3 I/O So far we have looked at modeling classes 4 I/O So far we have looked at modeling classes Not much in
More informationBBM 102 Introduction to Programming II Spring Exceptions
BBM 102 Introduction to Programming II Spring 2018 Exceptions 1 Today What is an exception? What is exception handling? Keywords of exception handling try catch finally Throwing exceptions throw Custom
More informationWhen we reach the line "z = x / y" the program crashes with the message:
CSCE A201 Introduction to Exceptions and File I/O An exception is an abnormal condition that occurs during the execution of a program. For example, divisions by zero, accessing an invalid array index,
More informationFile class in Java. Scanner reminder. File methods 10/28/14. 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". Input is received from the keyboard, mouse, files.
More informationCISC-124. Passing Parameters. A Java method cannot change the value of any of the arguments passed to its parameters.
CISC-124 20180215 These notes are intended to summarize and clarify some of the topics that have been covered recently in class. The posted code samples also have extensive explanations of the material.
More informationThere are several files including the start of a unit test and the method stubs in MindNumber.java. Here is a preview of what you will do:
Project MindNumber Collaboration: Solo. Complete this project by yourself with optional help from section leaders. Do not work with anyone else, do not copy any code directly, do not copy code indirectly
More information2.8. Decision Making: Equality and Relational Operators
Page 1 of 6 [Page 56] 2.8. Decision Making: Equality and Relational Operators A condition is an expression that can be either true or false. This section introduces a simple version of Java's if statement
More informationCSE 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 informationCOSC 123 Computer Creativity. I/O Streams and Exceptions. Dr. Ramon Lawrence University of British Columbia Okanagan
COSC 123 Computer Creativity I/O Streams and Exceptions Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Objectives Explain the purpose of exceptions. Examine the try-catch-finally
More informationCheck out how to use the random number generator (introduced in section 4.11 of the text) to get a number between 1 and 6 to create the simulation.
Chapter 4 Lab Loops and Files Lab Objectives Be able to convert an algorithm using control structures into Java Be able to write a while loop Be able to write an do-while loop Be able to write a for loop
More informationChapter 6 Lab Classes and Objects
Gaddis_516907_Java 4/10/07 2:10 PM Page 51 Chapter 6 Lab Classes and Objects Objectives Be able to declare a new class Be able to write a constructor Be able to write instance methods that return a value
More informationUniversity of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007
Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ 2007 Final Examination Question Max
More informationCIS 110: Introduction to Computer Programming
CIS 110: Introduction to Computer Programming Lecture 15 Our Scanner eats files ( 6.1-6.2) 10/31/2011 CIS 110 (11fa) - University of Pennsylvania 1 Outline Programming assertion recap The Scanner object
More informationBBM 102 Introduction to Programming II Spring 2017
BBM 102 Introduction to Programming II Spring 2017 Exceptions Instructors: Ayça Tarhan, Fuat Akal, Gönenç Ercan, Vahid Garousi Today What is an exception? What is exception handling? Keywords of exception
More informationLAB 13: ARRAYS (ONE DIMINSION)
Statement Purpose: The purpose of this Lab. is to practically familiarize student with the concept of array and related operations performed on array. Activity Outcomes: As a second Lab on Chapter 7, this
More informationing execution. That way, new results can be computed each time the Class The Scanner
ing execution. That way, new results can be computed each time the run, depending on the data that is entered. The Scanner Class The Scanner class, which is part of the standard Java class provides convenient
More informationChapter 4: Loops and Files
Chapter 4: Loops and Files Chapter Topics Chapter 4 discusses the following main topics: The Increment and Decrement Operators The while Loop Using the while Loop for Input Validation The do-while Loop
More informationA+ Computer Science -
import java.util.scanner; or just import java.util.*; reference variable Scanner keyboard = new Scanner(System.in); object instantiation Scanner frequently used methods Name nextint() nextdouble() nextfloat()
More informationChapter 3. Selections
Chapter 3 Selections 1 Outline 1. Flow of Control 2. Conditional Statements 3. The if Statement 4. The if-else Statement 5. The Conditional operator 6. The Switch Statement 7. Useful Hints 2 1. Flow of
More information12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.
Java How to Program, 9/e Education, Inc. All Rights Reserved. } Java application programming } Use tools from the JDK to compile and run programs. } Videos at www.deitel.com/books/jhtp9/ Help you get started
More informationSummary. Recursion. Overall Assignment Description. Part 1: Recursively Searching Files and Directories
Recursion Overall Assignment Description This assignment consists of two parts, both dealing with recursion. In the first, you will write a program that recursively searches a directory tree. In the second,
More informationCSCI 1103: File I/O, Scanner, PrintWriter
CSCI 1103: File I/O, Scanner, PrintWriter Chris Kauffman Last Updated: Wed Nov 29 13:22:24 CST 2017 1 Logistics Reading from Eck Ch 2.1 on Input, File I/O Ch 11.1-2 on File I/O Goals Scanner for input
More informationCOMP 110 Project 1 Programming Project Warm-Up Exercise
COMP 110 Project 1 Programming Project Warm-Up Exercise Creating Java Source Files Over the semester, several text editors will be suggested for students to try out. Initially, I suggest you use JGrasp,
More informationAL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: Text-printing program. CSC 209 JAVA I
AL GHURAIR UNIVERSITY College of Computing CSC 209 JAVA I week 2- Arithmetic and Decision Making: Equality and Relational Operators Objectives: To use arithmetic operators. The precedence of arithmetic
More informationEXCEPTION HANDLING. // code that may throw an exception } catch (ExceptionType parametername) {
EXCEPTION HANDLING We do our best to ensure program correctness through a rigorous testing and debugging process, but that is not enough. To ensure reliability, we must anticipate conditions that could
More informationSt. Edmund Preparatory High School Brooklyn, NY
AP Computer Science Mr. A. Pinnavaia Summer Assignment St. Edmund Preparatory High School Name: I know it has been about 7 months since you last thought about programming. It s ok. I wouldn t want to think
More informationBuilding Java Programs
Building Java Programs Chapter 5 Lecture 5-1: while Loops, Fencepost Loops, and Sentinel Loops reading: 4.1, 5.1 self-check: Ch. 4 #2; Ch. 5 # 1-10 exercises: Ch. 4 #2, 4, 5, 8; Ch. 5 # 1-2 Copyright 2009
More informationJAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to write programs for executing statements repeatedly using a while, do while and for loop
Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Computer Programming Lab (ECOM 2114) ABSTRACT In this Lab you will learn to write programs for executing statements repeatedly
More informationWhat did we talk about last time? Examples switch statements
Week 4 - Friday What did we talk about last time? Examples switch statements History of computers Hardware Software development Basic Java syntax Output with System.out.print() Mechanical Calculation
More informationAssoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.
Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All rights reserved. Java application A computer program that executes when you use the java command to launch the Java Virtual Machine
More informationComputer Science 210 Data Structures Siena College Fall Topic Notes: Methods
Computer Science 210 Data Structures Siena College Fall 2017 Topic Notes: Methods As programmers, we often find ourselves writing the same or similar code over and over. We learned that we can place code
More informationChapter 6 Lab Classes and Objects
Lab Objectives Chapter 6 Lab Classes and Objects Be able to declare a new class Be able to write a constructor Be able to write instance methods that return a value Be able to write instance methods that
More informationPlease answer the following questions. Do not re-code the enclosed codes if you have already completed them.
Dec. 9 Loops Please answer the following questions. Do not re-code the enclosed codes if you have already completed them. What is a loop? What are the three loops in Java? What do control structures do?
More informationCP122 CS I. Chapter 11: File I/O and Exceptions
CP122 CS I Chapter 11: File I/O and Exceptions Waymo full autonomy vehicles Tech News! Tech News! Waymo full autonomy vehicles CMU and Pitt researchers use AI with fmri to detect suicidal thoughts with
More informationLoops. Eng. Mohammed Abdualal. Islamic University of Gaza. Faculty of Engineering. Computer Engineering Department
Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 6 Loops
More informationExample Program. public class ComputeArea {
COMMENTS While most people think of computer programs as a tool for telling computers what to do, programs are actually much more than that. Computer programs are written in human readable language for
More informationLab 3: Call to Order CSCI 2101 Fall 2018
Due: Monday, October 15, 11:59 pm Collaboration Policy: Level 1 Group Policy: Pair-Optional Lab 3: Call to Order CSCI 2101 Fall 2018 This week s lab will explore sorting, lists, and basic data analysis.
More informationCS 302: Introduction to Programming in Java. Lectures 17&18. It s insanely hot. People desperately need some snowflakes
CS 302: Introduction to Programming in Java Lectures 17&18 It s insanely hot. People desperately need some snowflakes Static variables Again (class variables) Variables unique to the class (all objects
More informationChapter 4: Loops and Files
Chapter 4: Loops and Files Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter Topics Chapter 4 discusses the following main topics: The Increment and Decrement
More informationUniversity of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007
Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ 2007 Supplementary Examination Question
More informationCP122 CS I. Chapter 11: File I/O and Exceptions
CP122 CS I Chapter 11: File I/O and Exceptions Amazon completes first commercial drone delivery Tech News! Tech News! Amazon completes first commercial drone delivery DNC hack was due to phishing scam.
More informationDPCompSci.Java.1718.notebook April 29, 2018
Option D OOP 1 if Test a condition to decide whether to execute a block of code. Java Tutorials int x = 10; if (x < 20 { System.out.println(x + " < 20"); Prints 10 < 20 if else Test a condition to decide
More informationCS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 19: NOV. 15TH INSTRUCTOR: JIAYIN WANG
CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 19: NOV. 15TH INSTRUCTOR: JIAYIN WANG 1 Notice Assignment Class Exercise 19 is assigned Homework 8 is assigned Both Homework 8 and Exercise 19 are
More informationLab 3: Call to Order CSCI 2101 Fall 2017
Lab 3: Call to Order CSCI 2101 Fall 2017 Due: Part 1: Tuesday, Oct 3, 11:59 pm, Part 2: Wednesday, Oct 11, 11:59 pm Collaboration Policy: Level 1 Group Policy: Part 1: Individual, Part 2: Pair-Optional
More information! definite loop: A loop that executes a known number of times. " The for loops we have seen so far are definite loops. ! We often use language like
Indefinite loops while loop! indefinite loop: A loop where it is not obvious in advance how many times it will execute.! We often use language like " "Keep looping as long as or while this condition is
More informationCS 455 Midterm Exam 2 Fall 2015 [Bono] Nov. 10, 2015
Name: USC NetID (e.g., ttrojan): CS 455 Midterm Exam 2 Fall 2015 [Bono] Nov. 10, 2015 There are 9 problems on the exam, with 54 points total available. There are 8 pages to the exam (4 pages double-sided),
More informationBjarne Stroustrup. creator of C++
We Continue GEEN163 I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone. Bjarne Stroustrup creator
More informationHomework Assignment: Sudoku Board
Homework Assignment: Sudoku Board Back Overview of the project This assignment is part of a larger project to create a Sudoku application. Assignment: Sudoku Board Assignment: Sudoku Model Assignment:
More informationLab 13. Name: Checked:
Lab 13 Name: Checked: Objectives: Learn how to input data from text files using Scanner. We will also use Scanner in other novel ways, including reading data directly from a webpage! Preparation: Processing
More informationM105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014
M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014 Question One: Choose the correct answer and write it on the external answer booklet. 1. Java is. a. case
More informationBuilding Java Programs
Building Java Programs Chapter 6 File Input with Scanner reading: 6.1 6.2, 5.4 2 Input/output (I/O) import java.io.*; Create a File object to get info about a file on your drive. (This doesn't actually
More informationConstants. Why Use Constants? main Method Arguments. CS256 Computer Science I Kevin Sahr, PhD. Lecture 25: Miscellaneous
CS256 Computer Science I Kevin Sahr, PhD Lecture 25: Miscellaneous 1 main Method Arguments recall the method header of the main method note the argument list public static void main (String [] args) we
More informationProgramming Project 5: NYPD Motor Vehicle Collisions Analysis
: NYPD Motor Vehicle Collisions Analysis Due date: Dec. 7, 11:55PM EST. You may discuss any of the assignments with your classmates and tutors (or anyone else) but all work for all assignments must be
More informationLecture Set 2: Starting Java
Lecture Set 2: Starting Java 1. Java Concepts 2. Java Programming Basics 3. User output 4. Variables and types 5. Expressions 6. User input 7. Uninitialized Variables 0 This Course: Intro to Procedural
More informationJava Assignment 3: Loop Practice Ver 3.0 Last Updated: 12/1/2015 8:57 AM
Java Assignment 3: Loop Practice Ver 3.0 Last Updated: 12/1/2015 8:57 AM Let s get some practice creating programs that repeat commands inside of a loop in order to accomplish a particular task. You may
More informationText User Interfaces. Keyboard IO plus
Text User Interfaces Keyboard IO plus User Interface and Model Model: objects that solve problem at hand. User interface: interacts with user getting input from user giving output to user reporting on
More informationChapter 5 Lab Methods
Chapter 5 Lab Methods Lab Objectives Be able to write methods Be able to call methods Be able to write javadoc comments Be able to create HTML documentation for our Java class using javadoc Introduction
More informationCSCI 261 Computer Science II
CSCI 261 Computer Science II Department of Mathematics and Computer Science Lecture 2 Exception Handling New Topic: Exceptions in Java You should now be familiar with: Advanced object-oriented design -
More informationCSCI 1103: File I/O, Scanner, PrintWriter
CSCI 1103: File I/O, Scanner, PrintWriter Chris Kauffman Last Updated: Mon Dec 4 10:03:11 CST 2017 1 Logistics Reading from Eck Ch 2.1 on Input, File I/O Ch 11.1-2 on File I/O Goals Scanner for input Input
More informationDecisions: Logic Java Programming 2 Lesson 7
Decisions: Logic Java Programming 2 Lesson 7 In the Java 1 course we learned about if statements, which use booleans (true or false) to make decisions. In this lesson, we'll dig a little deeper and use
More information************ THIS PROGRAM IS NOT ELIGIBLE FOR LATE SUBMISSION. ALL SUBMISSIONS MUST BE RECEIVED BY THE DUE DATE/TIME INDICATED ABOVE HERE
Program 10: 40 points: Due Tuesday, May 12, 2015 : 11:59 p.m. ************ THIS PROGRAM IS NOT ELIGIBLE FOR LATE SUBMISSION. ALL SUBMISSIONS MUST BE RECEIVED BY THE DUE DATE/TIME INDICATED ABOVE HERE *************
More informationIntroduction to Java Applications
2 Introduction to Java Applications OBJECTIVES In this chapter you will learn: To write simple Java applications. To use input and output statements. Java s primitive types. Basic memory concepts. To use
More informationSection 2.2 Your First Program in Java: Printing a Line of Text
Chapter 2 Introduction to Java Applications Section 2.2 Your First Program in Java: Printing a Line of Text 2.2 Q1: End-of-line comments that should be ignored by the compiler are denoted using a. Two
More informationExceptions, try - catch - finally, throws keyword. JAVA Standard Edition
Exceptions, try - catch - finally, throws keyword JAVA Standard Edition Java - Exceptions An exception (or exceptional event) is a problem that arises during the execution of a program. When an Exception
More informationLecture 8 " INPUT " Instructor: Craig Duckett
Lecture 8 " INPUT " Instructor: Craig Duckett Assignments Assignment 2 Due TONIGHT Lecture 8 Assignment 1 Revision due Lecture 10 Assignment 2 Revision Due Lecture 12 We'll Have a closer look at Assignment
More informationCS 211: Existing Classes in the Java Library
CS 211: Existing Classes in the Java Library Chris Kauffman Week 3-2 Logisitics Logistics P1 Due tonight: Questions? Late policy? Lab 3 Exercises Thu/Fri Play with Scanner Introduce it today Goals Class
More informationCP122 CS I. Chapter 7: File I/O and Exceptions
CP122 CS I Chapter 7: File I/O and Exceptions Tech News! Triathlete in Australia hit by falling drone Tech News! Triathlete in Australia hit by falling drone 3D Printed drones in 24 hours using Stratasys
More informationLecture Set 2: Starting Java
Lecture Set 2: Starting Java 1. Java Concepts 2. Java Programming Basics 3. User output 4. Variables and types 5. Expressions 6. User input 7. Uninitialized Variables 0 This Course: Intro to Procedural
More informationA token is a sequence of characters not including any whitespace.
Scanner A Scanner object reads from an input source (keyboard, file, String, etc) next() returns the next token as a String nextint() returns the next token as an int nextdouble() returns the next token
More informationCSC 222: Object-Oriented Programming. Fall 2017
CSC 222: Object-Oriented Programming Fall 2017 Lists, data storage & access ArrayList class methods: add, get, size, remove, contains, set, indexof, tostring generics, for-each loop example: Dictionary
More informationExcep&ons and file I/O
Excep&ons and file I/O Exception in thread "main" java.lang.numberformatexception: For input string: "3.5" at java.lang.numberformatexception.forinputstring(numberformatexception.java:48) at java.lang.integer.parseint(integer.java:458)
More informationExceptions in Java
Exceptions in Java 3-10-2005 Opening Discussion Do you have any questions about the quiz? What did we talk about last class? Do you have any code to show? Do you have any questions about the assignment?
More informationClaremont McKenna College Computer Science
Claremont McKenna College Computer Science CS 51 Handout 4: Problem Set 4 February 10, 2011 This problem set is due 11:50pm on Wednesday, February 16. As usual, you may hand in yours until I make my solutions
More informationCS141 Programming Assignment #8
CS141 Programming Assignment #8 Due Sunday, April 14th. 1- Write a class with methods to do the following output: a) 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1 b) 1 2 3 4 5 4 3 2 1 1 2 3 4 * 4 3 2 1 1 2 3 * * * 3 2
More informationCOMP 202 File Access. CONTENTS: I/O streams Reading and writing text files. COMP File Access 1
COMP 202 File Access CONTENTS: I/O streams Reading and writing text files COMP 202 - File Access 1 I/O Streams A stream is a sequence of bytes that flow from a source to a destination In a program, we
More informationDCS/100: Procedural Programming
DCS/100: wk 12 p.1/23 DCS/100: Procedural Programming Week 12: Classes Queen Mary, University of London DCS/100: wk 12 p.2/23 Last Week: Learning Outcomes From last week you should be able to: explain
More informationExceptions and I/O: sections Introductory Programming. Errors in programs. Exceptions
Introductory Programming Exceptions and I/O: sections 80 83 Anne Haxthausen a IMM, DTU 1 Exceptions (section 80) 2 Input and output (I/O) (sections 81-83) a Parts of this material are inspired by/originate
More informationIntroductory Programming Exceptions and I/O: sections
Introductory Programming Exceptions and I/O: sections 80 83 Anne Haxthausen a IMM, DTU 1 Exceptions (section 80) 2 Input and output (I/O) (sections 81-83) a Parts of this material are inspired by/originate
More informationdownload instant at
2 Introduction to Java Applications: Solutions What s in a name? That which we call a rose By any other name would smell as sweet. William Shakespeare When faced with a decision, I always ask, What would
More informationChapter 5 Lab Methods
Chapter 5 Lab Methods Lab Objectives Be able to write methods Be able to call methods Be able to write javadoc comments Be able to create HTML documentation using the javadoc utility Introduction Methods
More informationFile I/O Array Basics For-each loop
File I/O Array Basics For-each loop 178 Recap Use the Java API to look-up classes/method details: Math, Character, String, StringBuffer, Random, etc. The Random class gives us several ways to generate
More informationCOMP102: Test 1 Model Solutions
Family Name:.......................... Other Names:.......................... ID Number:............................ COMP102: Test 1 Model Solutions 27 July, 2007 Instructions Time allowed: 45 minutes.
More information4. Java Project Design, Input Methods
4-1 4. Java Project Design, Input Methods Review and Preview You should now be fairly comfortable with creating, compiling and running simple Java projects. In this class, we continue learning new Java
More informationChapter 15. Exception Handling. Chapter Goals. Error Handling. Error Handling. Throwing Exceptions. Throwing Exceptions
Chapter 15 Exception Handling Chapter Goals To learn how to throw exceptions To be able to design your own exception classes To understand the difference between checked and unchecked exceptions To learn
More informationIntroduction to Java Applications; Input/Output and Operators
www.thestudycampus.com Introduction to Java Applications; Input/Output and Operators 2.1 Introduction 2.2 Your First Program in Java: Printing a Line of Text 2.3 Modifying Your First Java Program 2.4 Displaying
More informationProject 1: Remote Method Invocation CSE 291 Spring 2016
Project 1: Remote Method Invocation CSE 291 Spring 2016 Assigned: Tuesday, 5 April Due: Thursday, 28 April Overview In this project, you will implement a remote method invocation (RMI) library. RMI forwards
More informationWentworth Institute of Technology. Engineering & Technology WIT COMP1000. Testing and Debugging
WIT COMP1000 Testing and Debugging Testing Programs When testing your code, always test a variety of input values Never test only one or two values because those samples may not catch some errors Always
More information