JAVA PROGRAMMING (340)

Similar documents
JAVA PROGRAMMING (340)

Visual Basic/C# Programming (330)

6 Pages Contestant Number Time Rank. Regional 2013 TOTAL POINTS (485)

Introduction to Computer Science Unit 2. Notes

JAVA PROGRAMMING (45) Technical Task KEY. Regional 2013

Introduction to Computer Science Unit 2. Notes

VISUAL BASIC PROGRAMMING (44) Technical Task KEY. Regional 2013 TOTAL POINTS (485)

AP CS Unit 3: Control Structures Notes

Visual Basic/C# Programming (330)

St. Edmund Preparatory High School Brooklyn, NY

Programming with Java

Midterm Examination (MTA)

CMPSCI 119 LAB #1 Bar Graphs Professor William T. Verts

Check 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.

Loops. Eng. Mohammed Abdualal. Islamic University of Gaza. Faculty of Engineering. Computer Engineering Department

while (/* array size less than 1*/){ System.out.print("Number of students is invalid. Enter" + "number of students: "); /* read array size again */

Example Program. public class ComputeArea {

Mandatory Assignment 1, INF 4130, 2017

Lesson 10: Quiz #1 and Getting User Input (W03D2)

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to write programs for executing statements repeatedly using a while, do while and for loop

AP Computer Science Unit 1. Programs

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

Express Yourself. The Great Divide

Lab 9: Creating a Reusable Class

Web-CAT submission URL: CAT.woa/wa/assignments/eclipse

FUNDAMENTAL SPREADSHEET APPLICATIONS (230)

CMPS 11 Introduction to Programming Midterm 1 Review Problems

Chapter 3. Selections

Expanded Guidelines on Programming Style and Documentation

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

Introduction to Java Unit 1. Using BlueJ to Write Programs

M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014

( &% class MyClass { }

Basic Operations jgrasp debugger Writing Programs & Checkstyle

2.2 - Making Decisions

Chapter 6 Recursion. The Concept of Recursion

CAT.woa/wa/assignments/eclipse

Chapter 5 Lab Methods

C Sc 227 Project 1: Three Main Methods

Question: Total Points: Score:

Oct Decision Structures cont d

c. First convert to base-10 by expanding out the powers of 2:

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

ECE 161 WEEK 4 Introduction to Programing in Java

AP Computer Science Unit 1. Writing Programs Using BlueJ

CMPE223/CMSE222 Digital Logic Design. Positional representation

COMP 202 Java in one week

The Big Picture. Linker. Module 1. Module 2. One Module. Module 3. Module 4

Reading Input from Text File

COMP-202A, Fall 2007, All Sections Assignment 1

Project #1 Computer Science 2334 Fall 2008

T02 Tutorial Slides for Week 2

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

CS141 Programming Assignment #6

Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently.

Supplement D: Expanded Guidelines on Programming Style and Documentation

Section 2.2 Your First Program in Java: Printing a Line of Text

COMP 202. Java in one week

DESKTOP PUBLISHING (24)

Software Practice 1 Basic Grammar

CMPSCI 187 / Spring 2015 Postfix Expression Evaluator

gcc o driver std=c99 -Wall driver.c bigmesa.c

Chapter 15. Exception Handling. Chapter Goals. Error Handling. Error Handling. Throwing Exceptions. Throwing Exceptions

There 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:

AP Computer Science Unit 1. Writing Programs Using BlueJ

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

Midterm Exam 2 CS 455, Fall 2012

ADVANCED SPREADSHEET APPLICATIONS (235)

Java is an objet-oriented programming language providing features that support

Page 2 Page 3 Page 4 Page 5 Page 7 Total

Chapter 5 Lab Methods

Department of Computer Science Purdue University, West Lafayette

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

International Journal of Advanced Research in Computer Science and Software Engineering

Object Oriented Programming with Java

CEN 414 Java Programming

CS Programming I: File Input / Output

CS159. Nathan Sprague

Computer Programming, I. Laboratory Manual. Experiment #3. Selections

Question: Total Points: Score:

McGill University School of Computer Science COMP-202A Introduction to Computing 1

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

1. [3 pts] What is your section number, the period your discussion meets, and the name of your discussion leader?

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

Object Oriented Programming. Java-Lecture 1

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Full file at

Full file at

1 DOMjudge Overview Scoreboard... 2

ADVANCED SPREADSHEET APPLICATIONS -PILOT EVENT-

Programming Project 5: NYPD Motor Vehicle Collisions Analysis

MACHINE LEVEL REPRESENTATION OF DATA

Pace University. Fundamental Concepts of CS121 1

Possible Exam Questions

Introduction. Arizona State University 1

Control Statements: Part 1

2.8. Decision Making: Equality and Relational Operators

Evaluating the Style of your programs

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Transcription:

Page 1 of 8 JAVA PROGRAMMING (340) REGIONAL 2016 Production Portion: Program 1: Base K Addition (335 points) TOTAL POINTS (335 points) Judge/Graders: Please double check and verify all scores and answer keys! Property of Business Professionals of America. May be reproduced only for use in the Business Professionals of America Workplace Skills Assessment Program competition.

Page 2 of 8 You will have 90 minutes to complete your work. Your name and/or school name should NOT appear on any work you submit for grading. Create a folder on the flash drive provided using your contestant number as the name of the folder. Copy your entire solution/project into this folder. You must submit your entire solution/project so that the graders may open your project to review the source code. You must ensure that the files required to run your program are present and will execute on the flash drive provided. Note that the flash drive letter may not be the same when the program is graded as it was when you created the program. It is recommended that you use relative paths rather than absolute paths to ensure that the program will run regardless of the flash drive letter. The graders will not compile or alter your source code to correct for this. Submissions that do not contain source code will not be graded. Assumptions to make when taking this assessment: The input file(s) will contain only ASCII characters. A test input file will be available and will be named, basekaddition.txt. Development Standards: Standard name prefixes must be utilized for variables. All subroutines, functions, and methods must be documented with comments explaining the purpose of the method, the input parameters (if any), and the output (if any). If you create a class, then you must use Javadoc comments.

Page 3 of 8 Your application will be graded on the following criteria: Solution and Project The project is present on the flash drive The project main class is named basekaddition Program Execution The program runs from the USB flash drive 15 points If the program does not execute, then the remaining items in this section receive a score of zero. The program runs and reads the input file The program displays an error message if the command line is empty The program displays an error message if the file cannot be found The program displays the base of the numbers The program displays the first number to add The program displays the second number to add The program displays the correct addition of the numbers The program displays all the output for all of the numbers in the file 30 points 40 points Source Code Review The source code is properly commented A comment containing the contestant number is present Methods and code sections are commented A method exists to perform the display of output A method exists to perform the addition Code uses try catch for file exception Code uses a consistent variable naming convention Methods are used appropriately Total Points: 335 points

Page 4 of 8 Base K Addition The simple idea is that the program will be able to perform addition, in decimal, binary, octal, hexadecimal (base 16), or any other base that it is given. In this problem, you will be given two numbers in base K and asked to add them. Input: The input to this problem consists of a text file. The first line of the text file contains a single decimal integer that indicates the number of times the program should perform the addition. The next three lines will repeat for the number indicated in the first line. The first line of these three numbers contains a single decimal integer indicating the base in which the arithmetic is to be done. This integer will be between 2 and 20 inclusive. The second and third lines of text each consists of a single non-negative number in that base. In keeping with mathematical tradition, numerals 10-19 (if needed) will be indicated by the letters A-J respectively upper case only. The sum of the numbers represented in the second and third lines will be smaller than the decimal value 2,014,003,021. Output: The output consists of four lines of text. The first line describes the base of the numbers. The second line shows the first number. The third line shows the second number. The fourth line shows the result of the addition. Example: The base of the numbers to add is 10 The first number is 173 The second number is 169 The sum is: 342 Requirements: 1. You must create an application named basekaddition. 2. Your name and contestant number must appear as a comment at the top of the main source code file. 3. The program must read the name of the input file from the command line. If the file does not exist, then the program needs to display an appropriate message and exit. If the file name is not entered on the command line, then the program should display an appropriate message and exit. 4. The program will perform the addition correctly for however many numbers are in the input file. 5. The program must implement methods for output and the addition. 6. The program will display the output like the example above for all of the values in the input file.

Page 5 of 8 Note to Graders: The contestants have been given a file named basekaddition.txt. You will run their program with a file named graderaddition.txt. This will produce different results than the file they were given. Thus you will be able to detect if they hardcoded the name of the file into their program. You must copy graderaddition.txt into the folder where their program runs from. Listed below are test cases and their results. The first line is what you type at the command prompt. The second line is the output produced by the program. The wording does not have to be exact. When running the program, perform the following test cases: Test Case #1: basekaddition Please enter the name of the text file to use on the command line. Test Case #2 basekaddition grader.txt The file grader.txt was not found. Test Case #3 basekaddition graderaddition.txt The base of the numbers to add is 10 The first number is 173 The second number is 169 The sum is: 342 The base of the numbers to add is 8 The first number is 173 The second number is 147 The sum is: 342 The base of the numbers to add is 14 The first number is 2BC The second number is 84D The sum is: B2B The base of the numbers to add is 2 The first number is 00101101 The second number is 11100101 The sum is: 100010010 The base of the numbers to add is 16 The first number is 000BBBB The second number is 8888888 The sum is: 8894443 The base of the numbers to add is 3 The first number is 222222 The second number is 111111 The sum is: 1111110 The base of the numbers to add is 9 The first number is 804 The second number is 027 The sum is: 832

Page 6 of 8 The base of the numbers to add is 7 The first number is 0 The second number is 0 The sum is: 0 The base of the numbers to add is 4 The first number is 123123 The second number is 000123 The sum is: 123312 The base of the numbers to add is 20 The first number is ABCDEF The second number is 0GH0IJ The sum is: AB8ECD The base of the numbers to add is 15 The first number is 965DF The second number is 01120 The sum is: 97710 Sample Code, student code should and will vary: import java.io.filenotfoundexception; import java.io.filereader; import java.util.scanner; /** * BPA Java Programming Contest Problem : Base K Addition * * @author contestant number goes here * @version 2014 September 10 */ public class Add { public static void main(string[] args) throws FileNotFoundException { String sum = ""; // if the file was not put onto the command line prompt show an error message if (args.length > 0) { // try to open the file that was entered on the command prompt try { FileReader fr = new FileReader(args[0]); Scanner sc = new Scanner(fr); //get the number of times to do the summation int numberoftimestorun = sc.nextint(); for (int j = 0; j < numberoftimestorun; j++) { //get the base and two numbers int radix = sc.nextint(); String first = sc.next(); String second = sc.next(); //ensure the two numbers are the same length while (first.length() < second.length()) { first = "0" + first;

Page 7 of 8 while (second.length() < first.length()) { second = "0" + second; else { sum = sumnumbers(radix, first, second); showoutput(radix,first,second,sum); //if the file can not be found, show an error message catch (FileNotFoundException ec) { System.out.println("The file " + args[0] + " was not found."); //Display an erro if there was not a file entered on the command line System.out.println("Please enter the name of the text file to use on the command line."); // This method will produce the output for all of the data pre-processing // It takes as input the base of the numbers, the first and second number, and the result // It does not return anything public static void showoutput(int radix, String first, String second, String sum) { System.out.println("The base of the numbers to add is " + radix); System.out.println("The first number is " + first); System.out.println("The second number is " + second); System.out.println("The sum is: " + sum + '\n'); // This method will perform the summation of the two numbers // It takes as input the base, and the two numbers // It returns the sum of the addition public static String sumnumbers(int radix, String first, String second) { String numerals = "0123456789ABCDEFHIJ"; String sum=""; int carry = 0; //loop for the length of the numbers for (int i=first.length()-1; i>=0; i--) { int a = numerals.indexof(first.charat(i)); int b = numerals.indexof(second.charat(i)); //add the characters together int c = a+b+carry; //adjust for greater than base if (c>=radix) { carry = 1; c -= radix; else { carry = 0; //sum up the numbers using the numbers and letters sum = numerals.charat(c) + sum;

Page 8 of 8 if (carry == 1) { sum = "1" + sum; return sum;