1 Calling within Static method /* We can call a non static method from a static method but by only through an object of that class. */ class Test1{ public.

Slides:



Advertisements
Similar presentations
Surface Area and Volume Nets Slide Presentation
Advertisements

UNIT II DATA TYPES OPERATORS AND CONTROL STATEMENT 1.
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.
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
1 Classes and Objects in Java Parameter Passing, Delegation, Visibility Control, and Object Cleanup.
Lecture 4 More on Java® Data Types, Control Structures.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Introduction to Programming
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
Chapter 8: Arrays.
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Copyright © Recursive GCD Demo public class.
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
Computer Programming Lab(7).
The Point Class public class Point { public double x; public double y; public Point(double x0, double y0) { x = x0; y = y0; } public double distance(Point.
1 MATH METHODS THAT RETURN VALUES. 2 JAVA'S MATH CLASS.
Inheritance // A simple class hierarchy. // A class for two-dimensional objects. class TwoDShape { double width; double height; void showDim() { System.out.println("Width.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.1 Chapter 3 Selections.
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 17.
10-5 and 10-6 Volumes of Prisms, Cylinders, Pyramids, and Cones
***** SWTJC STEM ***** Chapter 4-1 cg 42 Object Oriented Program Terms Up until now we have focused on application programs written in procedural oriented.
10-3 Surface Areas of Prisms and Cylinders
Density Lab Part One. Density Lab: Part One DESCRIBE Describe the color and the shape of the object using 2 words.
 Algebra 1 Remediation September 3 Start on page 208 of practice packet.
Övning 4. Repetition göra egna klasser class Rektangel { private double längd; private double bredd; public Rektangel(double l, double b) { this.längd.
A simple program: Area of a circle Problem statement: Given the radius of a circle, display its area Algorithm: 4. Display area To store values, we need.
Determining Earth's Density  What is needed?  Density = Mass / Volume  Volume = 4/3 * pi * Radius 3  How do we determine these?  Two friends for.
Computer Programming Lab(4).
Derived from Building Java Programs by Stuart Reges & Marty Stepp
What is a cylinder? A cylinder is a three-dimensional shape that has two identical circular bases connected by a curved surface. Radius Circumference.
Imaginary and Complex Numbers
10-4 Surface Areas of Pyramids and Cones
Lecture 3 Decisions (Conditionals). One of the essential features of computer programs is their ability to make decisions. Like a train that changes tracks.
The 1 st and 2 nd tutoring session of CSc2310 Fall, 2012 Haidong Xue.
Volume of prisms and cylinders
Objects and Classes Mostafa Abdallah
Methods. Overview Class/Library/static vs. Message/non-static return and void Parameters and arguments.
THIS IS With Host... Your Pythagorean Theorem 1 Pythagorean Theoorem 2 Functions 1 Functions 2 Volume 1 Volume
VOLUME OF SOLID FIGURES BY: How To Find The Volume First find the area ( A ). A =  r square Then multiply the area ( A ) times the height ( H ). V =
FINDING the VOLUME of a CYLINDER PRE383 V = Ah A = Area of the base h = height of the solid A circle =  r 2 Volume =  r 2 h 2 6 Find the area of the.
Calculating density Measuring density: 1 Find out the mass of each object with an electronic balance. Calculating density.
THIS IS With Host... Your AreaVolumeRectanglesCirclesPrisms Cylinders.
Volume of a Cylinder How much will I hold?. A cylinder has two identical flat ends that are circular and one curved side. Volume is the amount of space.
 A cylinder has two identical flat ends that are circular and one curved side.  Volume is the amount of space inside a shape, measured in cubic units.
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
+ Function Families Review Please answer each question completely and be sure to show all of your work.
Density. Definition Density is the mass of an object in comparison to the volume it occupies.
N# ____ ___/___/___ 2-8 Literal Equations. Steps: 1.Identify the variable you want to isolate. 2.Get it by itself. 1.Just like a normal problem 2.The.
By: Don.  Name all the numbers 1-40 that are composite.  What is a prime number?  This is a ___ by ___ table?
Import javax.swing.JOptionPane; public class Rectangle { public static void main(String[] args) { double width, length, area, perimeter; String lengthStr,
Volume of Prisms and Cylinders Algebra 2 1/18/2012.
Numbers How does computer understand numbers? Knows only two symbols
AKA the birth, life, and death of variables.
using System; namespace Demo01 { class Program
Experiment 2 Finding density of an object
Density Practice Problems
Unit-2 Objects and Classes
Code Animation Examples
DENSITY 7.P.2B.2 Use mathematical and computational thinking to describe the relationship between the mass, volume, and density of a given substance.
AKA the birth, life, and death of variables.
class PrintOnetoTen { public static void main(String args[]) {
BBIT 212/ CISY 111 Object Oriented Programming (OOP)
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
Method 2: Irregularly-shaped Object
Procedure for calculating density
class Box { double width; double height; double depth; }
Presentation transcript:

1 Calling within Static method /* We can call a non static method from a static method but by only through an object of that class. */ class Test1{ public static void meth1(){ Test1 t1 = new Test1(); t1.meth2(); Test2 t2 = new Test2(); t2.meth3(); } public void meth2(){ System.out.println("this is meth2"); } public static void main(String [] args){ meth1(); } } class Test2{ public void meth3(){ System.out.println("Inside meth3"); }

2 final /* Compute volume for a given mass and generate a table for values of mass = 1.0, 2.0, 3.0, 4.0, 5.0 using a for loop */ class cylinder { public static void main (String args[]) { final double pi = ; double radius, height, volume; radius = 1.0; height = 2.0; volume = pi * radius * radius * height; System.out.println("Volume is: "+volume); radius = 1.0; height = 2.0; // pi = 3.0; volume = pi * radius * radius * height; System.out.println("Volume is: "+volume); }

3 final /* Compute volume for a given mass and generate a table for values of mass = 1.0, 2.0, 3.0, 4.0, 5.0 using a for loop */ class densityTableFor { public static void main (String args[]) { double mass, volume; final double density = 13.6; for(mass = 1.0; mass <=5.0; mass = mass + 1.0){ volume = mass/density; System.out.println("If mass is " + mass + " then the volume is " + volume); } System.out.println(); // density = 13.0; for(mass = 1.0; mass <=2.0; mass = mass + 0.1){ volume = mass/density; System.out.println("If mass is " + mass + " then the volume is " + volume); }

4 StringTokenizer import java.util.StringTokenizer; class tokenizerdemo{ public static void main(String arg[]){ ConsoleReader console = new ConsoleReader(System.in); System.out.println("Pls give string input"); String z = console.readLine(); StringTokenizer st1 = new StringTokenizer(z); while (st1.hasMoreTokens()){ String token = st1.nextToken(); System.out.println(token); } StringTokenizer st2 = new StringTokenizer(z); int tokencount = st2.countTokens(); for (int i=0; i<tokencount; i++){ String token = st2.nextToken(); System.out.println(token); }

5 Roots of an equation /* Solve x*x-3x+1=0 x = 1/3(x*x+1) OR x = 3 - 1/x */ public class equation{ public static void main(String args[]){ double error= ; double x1=0.2; //double x1=1.0; //double x1=2.6; //double x1=3.0; double x2=(x1*x1+1)/3; while(Math.abs(x2-x1)>error){ System.out.println(x2); x1=x2; x2=(x1*x1+1)/3; } System.out.println(x1); System.out.println("FIRST LOOP ENDS");

6 Roots of an equation /* Solve x*x-3x+1=0 x = 1/3(x*x+1) OR x = 3 - 1/x */ x1=0.2; //x1=1.0; //x1=2.6; //x1=3.0; x2=3-1/x1; while(Math.abs(x2-x1)>error){ System.out.println(x2); x1=x2; x2=3-1/x1; } System.out.println(x1); }

FIRST LOOP ENDS

8 With x1= E E E E E E298 Infinity FIRST LOOP ENDS