Style guide in JAVA From a lecture by Dr. Rahman.

Slides:



Advertisements
Similar presentations
CS102--Object Oriented Programming Discussion 2: (programming strategy in java) – Two types of tasks – The use of arrays Copyright © 2008 Xiaoyan Li.
Advertisements

1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Building Java Programs
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 5 Lecture 5-1: while Loops, Fencepost Loops, and Sentinel Loops reading: 4.1, 5.1.
Scanner & Stepwise Refinement Pepper With credit to Dr. Siegfried.
11 Chapter 5 METHODS. 22 INTRODUCTION TO METHODS A method is a named block of statements that performs a specific task. Other languages use the terms.
LAB 10.
1 Interactive Applications (CLI) Interactive Applications Command Line Interfaces Project 1: Calculating BMI Example: Factoring the Solution Reading for.
Computer Programming Lab(4).
Intro to Java Programming  A computer follows the instruction precisely and exactly.  Anything has to be declared and defined before it can be used.
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
Welcome to CS 3260 Dennis A. Fairclough. Overview Course Canvas Web Site Course Materials Lab Assignments Homework Grading Exams Withdrawing from Class.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Simple Programs from Chapter 2 Putting the Building Blocks All Together (corresponds with Chapter 2)
Getting Started with Java Recitation – 1/23/2009 CS 180 Department of Computer Science, Purdue University.
Lecture 2: Classes and Objects, using Scanner and String.
Java Fundamentals 3 Input and Output statements. Standard Output Window Using System.out, we can output multiple lines of text to the standard output.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
1 Fencepost loops “How do you build a fence?”. 2 The fencepost problem Problem: Write a class named PrintNumbers that reads in an integer called max and.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Java Programming: From Problem Analysis to Program Design, 5e Chapter 2 Basic Elements of Java.
A First Look at Java Chapter 2 1/29 & 2/2 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Can we talk?. In Hello World we already saw how to do Standard Output. You simply use the command line System.out.println(“text”); There are different.
1 Building Java Programs Chapter 5 Lecture 5-1: while Loops, Fencepost Loops, and Sentinel Loops; Procedural Design reading: 5.1 – 5.2; 4.5.
Introduction to Programming
CSC Programming I Lecture 6 September 4, 2002.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
FUNDAMENTALS 2 CHAPTER 2. OPERATORS  Operators are special symbols used for:  mathematical functions  assignment statements  logical comparisons 
Lecture 4 – Scanner & Style. Console Output The console that starts a Java application is typically known as the standard output device. The standard.
CSC 1051 M.A. Papalaskari, Villanova University Algorithms Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
CSCI 1226 FALL 2015 MIDTERM #1 REVIEWS.  Types of computers:  Personal computers  Embedded systems  Servers  Hardware:  I/O devices: mice, keyboards,
Building Java Programs Program Logic and Indefinite Loops.
The Hashemite University Computer Engineering Department
COP 2551 Introduction to Object Oriented Programming with Java Topics –Introduction to the Java language –Code Commenting –Java Program Structure –Identifiers.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Copyright © Curt Hill Simple I/O Input and Output using the System and Scanner Objects.
Computer Programming Lab 9. Exercise 1 Source Code package excercise1; import java.util.Scanner; public class Excercise1 { public static void main(String[]
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Interactive Programs Programs that get input from the user 1 In PowerPoint, click on the speaker icon then click the "Play" button to hear the narration.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
1 Building Java Programs Chapter 5 Lecture 5-1: while Loops, Fencepost Loops, and Sentinel Loops reading: 5.1 – 5.2.
Lecture 4.1: More on Scanner, Methods, and Codingbat Michael Hsu CSULA.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Variable scope. Variable Scope Variables do not live forever. Failing to take that into account leads to problems. Let's look at an example. Let's write.
Lecture 4 – Scanner & Style
CompSci 230 S Programming Techniques
Introduction to Computer Science / Procedural – 67130
CSC 1051 – Data Structures and Algorithms I
Data types, Expressions and assignment, Input from User
Something about Java Introduction to Problem Solving and Programming 1.
Control Statement Examples
Program Style Console Input and Output
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
Introduction to Classes and Methods
AP Java Review If else.
Building Java Programs
CS 200 Primitives and Expressions
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
Seating “chart” Front Back 4 rows 5 rows 5 rows 2 rows 4 rows 2 rows
Building Java Programs
AP Java Review If else.
CSC 1051 – Data Structures and Algorithms I
Building Java Programs
Building Java Programs
Random Numbers while loop
Building Java Programs
Building Java Programs
Presentation transcript:

Style guide in JAVA From a lecture by Dr. Rahman

Followup from lab Could you have done this without integer division? Is it easier with integer division? If you have not yet done this lab…make sure you do so before part 2. You will not get credit for part 2 if you do not get 10 points on part 1.

public class anyclass { public static void main (String [] args) { int a; double b; final double c=2.54; Scanner d ; d=new Scanner(System.in) ; a=d.nextInt(); System.out.print(" How many inches ?"); b=a*c; System.out.print(a+ “ in= “) ; System.out.println(b+“ cm”); } } Joe’s code has a bug, now fix it

/** * Application converts inches to centimeters. * Farzana Rahman 09/13/2014 */ public class ConvertInches { public static void main ( String [] args ) { int inch; double cent; final double CENT_PER_INCH; CENT_PER_INCH = 2.54; // create a scanner for standard input Scanner keyboard; keyboard = new Scanner( System.in ); // prompt the user and get the value System.out.print(" How many inches ? "); inch = keyboard.nextInt(); // convert and output the result cent = inch * CENT_PER_INCH; System.out.print( inch + " in = "); System.out.println( cent + " cm"); } }

Which do you prefer? Why?

What are Coding Standards Coding standards are guidelines for code style and documentation. This course will more or less follow industry standard Code Conventions for the Java. Some portion of the grade for PA is based on conformance to these standards. Program Design Naming Conventions Formatting Conventions Documentation Declaration…

Our class Style Guide is found in the Resources tab of Java The checklist in your packet follows this exactly.

Style guide highlights A.1 All names should be descriptive and readable. B.1 In CS 139, do NOT combine declaration and assignment. B.2 All constants/variables must be declared at the top. No OK int h;int hrs;int hours; int m;int mns;int minutes; int s;int scs;int seconds; NOOK Scanner input = new Scanner(System.in); int total = input.nextInt(); Scanner input; int total; input = new Scanner(System.in); total = input.nextInt();

Other notes Constants – any value that you can describe should be a constant. For this program, the constants would be either the 60 conversion factor if you used it only or both the 3600 and the 60 you used. Constants make a program more readable than the corresponding literal. Constants should be declared and initialized at the top of the program.

Why Have Coding Standards Greater consistency between developers Easier to develop and maintain Saves time and money

In your groups Look at the three payroll solutions. They all do the same thing. What do you like better and why? What is an example of one good practice? What is an example of one bad practice?

Apply the checklist to the last problem. Given one point for each instance of a problem for a maximum of 2 and 5 points for any one category, how would you score it. Put answers on the board. Presenter, be prepared to defend your answer.

In your groups Look at the one or two examples of SecondsToHours. Each pair (or solo) should score their program. Then share your code and score with the group. Each team should try to help the others on the team achieve a perfect style score. What common errors did you find?

Homework Resubmit your SecondsToHours.java program to WebCAT, taking care to both get the 100% correct and to follow the Style Guide. The assignment to submit to is SecondsToHours V2. This assignment will be graded just like we would grade a PA for Style. You will be able to see the feedback in WebCAT. No credit will be given for Lab 2 if you do not get 10 points on V1. (no credit for V1 late, but its your entrance pass to V2).

As you leave Erase the whiteboard and fill in the exit pass for today. What is still fuzzy about operations, data, and now Style? What is going well? OR What did you learn?