Lab9Objects

Lab9Objects - : Shadow.x = " + Shadow.x);...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Background: Here we see a new way of writing a program with classes. We have a main method, and it creates an object of our type!!! What is it doing???? Well, it calls the constructor, and that object has access to the instance variables. Also note the use of the instance variables with the syntax: object'svariablename.instancevariablename. This is because the instance variables are public. So look at these examples and identify any spots where there is something that you don't understand. After checking everyone off, the TA will go over the solutions for these two questions. pre-lab: what are the outputs of the following programs? Q1: public class Shadow { public int a; public int b; public Shadow(int a, int b) { a = a; this.b = b; } public static void main(String args[]) { Shadow s = new Shadow(37, 47); System.out.println("a = " + s.a); System.out.println("b = " + s.b); } } Q2: public class Shadow { static int x = 1; public static void main(String[] args) { int x = 10; System.out.println("main : x = " + x); System.out.println("main
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: : Shadow.x = " + Shadow.x); printa(); printb(100); } static void printa() { System.out.println("printa: x = " + x); } static void printb(int x) { System.out.println("printb: x = " + x); } }-------------------------------------------------------------Lab: Implement a Cashier class to compute the number of Dollar, Quarter, Dime, Nickel, and Penny to be returned to the customer. You class should be called from the following program: public class CashierTester { public static void main(String args) { double due = 9.28; double received = 10; Cashier john = new Cashier(due, received); double dollars = john.returnDollars(); double quarters = john.returnQuarters(); double dimes = john.returnDimes(); double nickels = john.returnNickels(); double pennies = john.returnPennies(); System.out.println( "Give the customer \n" + dollars + " dollars,\n" + quarters + " quarters,\n" + dimes + " dimes,\n" + nickels + " nickels,\n" + pennies + " pennies\n"); } }...
View Full Document

Page1 / 2

Lab9Objects - : Shadow.x = " + Shadow.x);...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online