Output Programs These slides will present a variety of small programs. Most of the programs deal with DecimalFormat objects or Polygon objects. Our concern.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

Review of Math Class Methods abssqrt minmax powround ceilfloor.
OOP & JAVA. HelloWorld.java /** * The HelloWorld class is an application that * displays "Hello World!" to the standard output. */ public class HelloWorld.
Unit 051 Packages What is a Package? Why use Packages? Creating a Package Naming a Package Using Package Members Managing Source and Class Files Visibility.
Do You Understand Methods and Parameters? In this section you will be shown 25 different programs. Most of these programs have some type of error. A few,
Functions Programming in C++ Computer Science Dept Va Tech August 2000 ©2000 William D McQuain 1 #include // for file streams for input/output #include.
Learn about the types of Graphics that are available Develop a basic Graphics applet Develop a basic Graphics application Review the Java API and use.
Review of Math Class Methods abssqrt minmax powround ceilfloor.
Java Keywords  Reserved Words Part of the Java language Examples: public, static, void  Pre-defined Java Identifiers Defined in Java Libraries Examples:
// Java0802.java // CardDeck Case Study #02 // Variables, called attributes or data fields, are added to the class. public class Java0802 { public static.
// Java0601.java // This program demonstrates that the methods of a class are not always // accessible, like they were with the class. In this case an.
User-defined parameters can be passed to an applet using the tags.
Exposure Java-A 2006 Chapter 4 Slides Using Methods and Parameters
The Drawing program – Java Applets
***** SWTJC STEM ***** Chapter 3-1 cg 39 Math Class The Math class provides a convenient way to access higher math functions. The Math class is automatically.
The String Class A String is an object. An object is defined by a class. In general, we instantiate a class like this: String myString = new String(“Crazy.
Primitive Data Types vs. Classes A simple/primitive data type can store only one single value. This means an int can only store one integer. A double.
Object Oriented Programming (OOP) is a style of programming that incorporates these 3 features: Encapsulation Polymorphism Class Interaction.
1 Windows program example import java.awt.*; import java.awt.event.*; public class wpexample extends Frame { public wpexample(String title) { super(title);
Additional Math Class Methods Math.exp(p)returns the antilog of p, or e p Math.log(p)returns the log (base e) of p Math.sin(p)returns the trigonometric.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Java Applet Basics (2). The Body Mass Index Calculator.
Primitive Data Types vs. Classes A simple/primitive data type can store only one single value. This means an int can only store one integer. A double.
Exposure Java 2014 For AP®CS Edition
Review of Math Class Methods abssqrt minmax powround ceilfloor.
2/18: Assignment Operators About Average2.java –while loop use –explicit casting –twoDigits object Assignment Operators Increment & Decrement Operators.
Visual Classes 1 Class: Bug 5 Objects: All Bug Objects.
Output Programs These slides will present a variety of small programs. Each program has a control structure that was introduced in this chapter. Our concern.
Take out a piece of paper and PEN. The quiz starts ONE minute after the tardy bell rings. You will have 45 – 90 seconds per question. Determine the output.
Chapter 2 Creating a Java Application and Applet.
Output Programs These slides will present a variety of small programs. Each program has some type of array that was introduced in this chapter. Our concern.
PHY281 Scientific Java Programming ArraysSlide 1 Arrays In this section we will learn how about storing groups of related variables that share the same.
CSI 3125, Preliminaries, page 1 Applet. CSI 3125, Preliminaries, page 2 Applet An applet is a Java program that runs in a Web browser. An applet can be.
1 Advanced Programming Examples Output. Show the exact output produced by the following code segment. char[,] pic = new char[6,6]; for (int i = 0; i
CSI 3125, Preliminaries, page 1 Adapter Class. CSI 3125, Preliminaries, page 2 Adapter Class Java provides a special feature, called an adapter class,
Primitive Data Types vs. Classes A simple/primitive data type can store only one single value. This means an int can only store one integer. A double.
Output Programs These slides will present a variety of small programs. Each program has a compound condition which uses the Boolean Logic that was introduced.
Lec 15 Writing an Applet Class. Agenda Writing an Applet class Java Graphics class.
Java Keywords  Reserved Words Part of the Java language Examples: public, static, void  Pre-defined Java Identifiers Defined in Java Libraries Examples:
Output Programs These slides will present a variety of small programs. Each program has a control structure that was introduced in this chapter. Our concern.
The 4 Stages of Program Design  Cryptic Programming Stage  Unstructured, Spaghetti-Programming Stage  Structured Programming Stage  Object Oriented.
Review of Math Class Methods abssqrt minmax powround ceilfloor.
Staples are our staple Building upon our solution.
The 4 Stages of Program Design  Cryptic Programming Stage  Unstructured, Spaghetti-Programming Stage  Structured Programming Stage  Object Oriented.
// Java0501.java // This program (and the next few programs) demonstrate user keyboard input // during program execution. This particular program demonstrates.
Object Oriented Programming (OOP) is a style of programming that incorporates these 3 features: Encapsulation Polymorphism Class Interaction.
User Interface Programming In Java
Exercise Java programming
using System; namespace Demo01 { class Program
Interface.
Multiple if-else boolean Data
PowerPoint Presentation From Materials Created
Exposure Java 2013 APCS Edition Chapter 12 Slides Focus on OOP:
Systems of Computation
Control Statement Examples
March 29th Odds & Ends CS 239.
Section 6.2 Classes & Objects.
TO COMPLETE THE FOLLOWING:
Package & Java Access Specifiers
PowerPoint Presentation Authors of Exposure Java
PowerPoint Presentation Authors of Exposure Java
Multiple if-else boolean Data
Section 9.1 Introduction.
class PrintOnetoTen { public static void main(String args[]) {
PowerPoint Presentation Authors of Exposure Java
PowerPoint Presentation Authors of Exposure Java
PowerPoint Presentation Authors of Exposure Java
Outline Declaring and Using Arrays Arrays of Objects
PowerPoint Presentation Authors of Exposure Java
Presentation transcript:

Output Programs These slides will present a variety of small programs. Most of the programs deal with DecimalFormat objects or Polygon objects. Our concern will be with the output of each program, and more importantly, to develop a way to determine program output correctly. You can expect that on quizzes and/or tests only a program segment or a method is shown.

Teacher/Student Versions, Tablet PCs, and Inking The “For Teachers” version of this presentation has 2 slides for each program. The first slide only shows the program. The second shows the program, worked out solution, and output. The “For Students” version only has 1 slide for each program with no provided solution or output. Students are expected to work out the solutions either on paper, or ideally they can “ink” directly on their laptops.

import java.text.DecimalFormat; public class Ex0601 { public static void main (String args[]) { DecimalFormat output = new DecimalFormat("0000"); int x = 1; int y = 21; int z = 321; System.out.println(output.format(x)); System.out.println(output.format(y)); System.out.println(output.format(z)); }

import java.text.DecimalFormat; public class Ex0601 { public static void main (String args[]) { DecimalFormat output = new DecimalFormat("0000"); int x = 1; int y = 21; int z = 321; System.out.println(output.format(x)); System.out.println(output.format(y)); System.out.println(output.format(z)); }

import java.text.DecimalFormat; public class Ex0602 { public static void main (String args[]) { DecimalFormat output = new DecimalFormat("0000"); int a = 1; int b = 21; int c = 321; int d = 4321; int e = 54321; System.out.println(output.format(a)); System.out.println(output.format(b)); System.out.println(output.format(c)); System.out.println(output.format(d)); System.out.println(output.format(e)); }

import java.text.DecimalFormat; public class Ex0602 { public static void main (String args[]) { DecimalFormat output = new DecimalFormat("0000"); int a = 1; int b = 21; int c = 321; int d = 4321; int e = 54321; System.out.println(output.format(a)); System.out.println(output.format(b)); System.out.println(output.format(c)); System.out.println(output.format(d)); System.out.println(output.format(e)); }

import java.text.DecimalFormat; public class Ex0603 { public static void main (String args[]) { DecimalFormat output = new DecimalFormat("0000"); int a = 10; int b = a + 25; int c = b * 2; int d = a + b + c; int e = d / 5; System.out.println(output.format(a)); System.out.println(output.format(b)); System.out.println(output.format(c)); System.out.println(output.format(d)); System.out.println(output.format(e)); }

import java.text.DecimalFormat; public class Ex0603 { public static void main (String args[]) { DecimalFormat output = new DecimalFormat("0000"); int a = 10; int b = a + 25; int c = b * 2; int d = a + b + c; int e = d / 5; System.out.println(output.format(a)); System.out.println(output.format(b)); System.out.println(output.format(c)); System.out.println(output.format(d)); System.out.println(output.format(e)); } variableprocess value aN/A 10 b c35 * 2 70 d e115 / 5 23

import java.text.DecimalFormat; public class Ex0604 { public static void main (String args[]) { DecimalFormat output = new DecimalFormat("0,000"); int a = 100; int b = a * 25; int c = b * 2; int d = a + b + c; int e = d / 5; System.out.println(output.format(a)); System.out.println(output.format(b)); System.out.println(output.format(c)); System.out.println(output.format(d)); System.out.println(output.format(e)); }

import java.text.DecimalFormat; public class Ex0604 { public static void main (String args[]) { DecimalFormat output = new DecimalFormat("0,000"); int a = 100; int b = a * 25; int c = b * 2; int d = a + b + c; int e = d / 5; System.out.println(output.format(a)); System.out.println(output.format(b)); System.out.println(output.format(c)); System.out.println(output.format(d)); System.out.println(output.format(e)); } variableprocess value aN/A 100 b100 * c2500 * d e7600 /

import java.text.DecimalFormat; public class Ex0605 { public static void main (String args[]) { DecimalFormat money = new DecimalFormat("$0.00"); double hoursWorked = 42; double hourlyRate = 9.75; double grossPay = hoursWorked * hourlyRate; double deductions = grossPay * 0.299; double netPay = grossPay - deductions; System.out.println(money.format(grossPay)); System.out.println(money.format(deductions)); System.out.println(money.format(netPay)); }

import java.text.DecimalFormat; public class Ex0605 { public static void main (String args[]) { DecimalFormat money = new DecimalFormat("$0.00"); double hoursWorked = 42; double hourlyRate = 9.75; double grossPay = hoursWorked * hourlyRate; double deductions = grossPay * 0.299; double netPay = grossPay - deductions; System.out.println(money.format(grossPay)); System.out.println(money.format(deductions)); System.out.println(money.format(netPay)); } variableprocess value hoursWorkedN/A 42 hourlyRateN/A 9.75 grossPay42 * deductions409.5 * netPay409.5 –

import java.awt.*; import java.applet.*; public class Ex0606 extends Applet { public void paint(Graphics g) { Expo.setFont(g,"Qwerty",Font.BOLD+Font.ITALIC,48); Expo.setColor(g,Expo.red); Expo.drawString(g,"I",400,200); Expo.drawString(g,"AM",600,300); Expo.drawString(g,"SAM",150,100); } The grid above is 800 X 500. Each square is 100 X 100. For the remaining questions if you have a tablet PC try to draw the output on the grid.

import java.awt.*; import java.applet.*; public class Ex0606 extends Applet { public void paint(Graphics g) { Expo.setFont(g,"Qwerty",Font.BOLD+Font.ITALIC,48); Expo.setColor(g,Expo.red); Expo.drawString(g,"I",400,200); Expo.drawString(g,"AM",600,300); Expo.drawString(g,"SAM",150,100); }

import java.awt.*; import java.applet.*; public class Ex0607 extends Applet { public void paint(Graphics g) { Expo.setColor(g,Expo.red); Expo.drawPolygon(g,100,200,300,100,500,100,700,200, 700,300,500,400,300,400,100,300); }

import java.awt.*; import java.applet.*; public class Ex0607 extends Applet { public void paint(Graphics g) { Expo.setColor(g,Expo.red); Expo.drawPolygon(g,100,200,300,100,500,100,700,200, 700,300,500,400,300,400,100,300); }

import java.awt.*; import java.applet.*; public class Ex0608 extends Applet { public void paint(Graphics g) { Expo.setColor(g,Expo.red); Expo. fill Polygon(g,100,200,300,100,500,100,700,200, 700,300,500,400,300,400,100,300); }

import java.awt.*; import java.applet.*; public class Ex0608 extends Applet { public void paint(Graphics g) { Expo.setColor(g,Expo.red); Expo. fill Polygon(g,100,200,300,100,500,100,700,200, 700,300,500,400,300,400,100,300); }

import java.awt.*; import java.applet.*; public class Ex0609 extends Applet { public void paint(Graphics g) { Expo.setColor(g,Expo.red); Expo.drawPolygon(g,300,400,300,100,700,300,100,300, 500,100,500,400,100,200,700,200); }

import java.awt.*; import java.applet.*; public class Ex0609 extends Applet { public void paint(Graphics g) { Expo.setColor(g,Expo.red); Expo.drawPolygon(g,300,400,300,100,700,300,100,300, 500,100,500,400,100,200,700,200); }

import java.awt.*; import java.applet.*; public class Ex0610 extends Applet { public void paint(Graphics g) { Expo.setColor(g,Expo.red); Expo.drawCircle(g,400,250,200); Expo.drawRegularPolygon(g,400,250,200,7); Expo.drawStar(g,400,250,200,7); }

import java.awt.*; import java.applet.*; public class Ex0610 extends Applet { public void paint(Graphics g) { Expo.setColor(g,Expo.red); Expo.drawCircle(g,400,250,200); Expo.drawRegularPolygon(g,400,250,200,7); Expo.drawStar(g,400,250,200,7); }