Java 進 階 程 式 設 計 03/14~03/21
|
|
|
- Deborah Townsend
- 9 years ago
- Views:
Transcription
1 Java 進 階 程 式 設 計 03/14~03/21 Name: 邱 逸 夫 NO: Write an application that inputs one number consisting of five digits from the user, separates the number into its individual digits and prints the digits separated from one another by three spaces each. For example, if the user types in the number 42339, the program should print Assume that the user enters the correct number of digits. What happens when you execute the program and type a number with more than five digits? What happens when you execute the program and type a number with fewer than five digits? [Hint: It is possible to do this exercise with the techniques you learned in this chapter. You will need to use both division and remainder operations to "pick off" each digit.] c:\>java num2dig Enter an number: c:\>java num2dig Enter an number:12 Number must in 5 digit! c:\>java num2dig Enter an number: Number must in 5 digit! SteveHome Workstation HW List Page 1
2 E:\THUWorks\java 程 式 設 計 \num2dig.java 2007 年 3 月 28 日 上 午 04:17 1 // Prog.Name:number to digit 2 // StdNo.:s 邱 逸 夫 3 // input: none 4 // output: see code. 5 // Date: 03/21/07 6 import java.util.scanner; // program uses Scanner 7 8 public class num2dig { 9 public static void main (String args[]) { int input_value; 12 Scanner input = new Scanner( System.in ); System.out.print("Enter an number:"); 15 input_value = input.nextint(); if ((input_value > 99999) (input_value < 9999)) { 18 System.out.println("Number must in 5 digit!"); 19 } else { 20 //Do something int leader_digit = input_value/10000; 23 System.out.print(leader_digit); 24 System.out.print(" "); 25 input_value = input_value - (leader_digit * 10000); int second_digit = input_value/1000; 28 System.out.print(second_digit); 29 System.out.print(" "); 30 input_value = input_value - (second_digit * 1000); int third_digit = input_value/100; 33 System.out.print(third_digit); 34 System.out.print(" "); 35 input_value = input_value - (third_digit * 100); int fouth_digit = input_value/10; 38 System.out.print(fouth_digit); 39 System.out.print(" "); 40 input_value = input_value - (fouth_digit * 10); System.out.print(input_value); 44 System.out.println(); 45 } } 48 } SteveHome Computing Workstation, Inc. Page 1
3 2.31 Using only the programming techniques you learned in this chapter, write an application that calculates the squares and cubes of the numbers from 0 to 10 and prints the resulting values in table format, as shown below. [Note: This program does not require any input from the user.] c:\>java shownum number square cube SteveHome Workstation HW List Page 2
4 E:\THUWorks\java 程 式 設 計 \shownum.java 2007 年 3 月 28 日 上 午 04:17 1 // Prog.Name: 2 // StdNo.:s 邱 逸 夫 3 // input: none 4 // output: see code. 5 // Date: 03/21/07 6 public class shownum { 7 8 public static void main (String args[]) { 9 10 System.out.println("number\tsquare\tcube"); for (int i = 1; i <=10 ; i++) { System.out.printf("%d\t%d\t%d\n", i, i*i, i*i*i); } } 19 } SteveHome Computing Workstation, Inc. Page 1
5 3.13 Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables a part number (type String), a part description (type String), a quantity of the item being purchased (type int) and a price per item (double). Your class should have a constructor that initializes the four instance variables. Provide a set and a get method for each instance variable. In addition, provide a method named getinvoiceamount that calculates the invoice amount (i.e., multiplies the quantity by the price per item), then returns the amount as a double value. If the quantity is not positive, it should be set to 0. If the price per item is not positive, it should be set to 0.0. Write a test application named InvoiceTest that demonstrates class Invoice's capabilities. c:\>java InvoiceTest Enter Number:5562 Enter Description:Some voice about you. Enter Quantity:6 Enter Price:39.9 The current item info: Number:5562 Description:Some voice about you. Quantity:6 Price:39.90 The current invoice amount: SteveHome Workstation HW List Page 3
6 E:\THUWorks\java 程 式 設 計 \Invoice.java 2007 年 3 月 28 日 上 午 04:16 1 // Prog.Name:Invoice 2 // StdNo.:s 邱 逸 夫 3 // input: none 4 // output: see code. 5 // Date: 03/21/07 6 public class Invoice { 7 8 private String part_number; 9 private String part_description; 10 private int part_quantity; 11 private double part_price; public void setnumber (String number) { 14 part_number = number; 15 } 16 public void setdescription (String description) { 17 part_description = description; 18 } 19 public void setquantity (int quantity) { 20 if (quantity < 0) { 21 part_quantity = 0; 22 } else { 23 part_quantity = quantity; 24 } 25 } 26 public void setprice (double price) { 27 part_price = price; 28 } public Invoice() { 31 } public Invoice(String number, String description, int quantity, double price) { 34 setnumber(number); 35 setdescription(description); 36 setquantity(quantity); 37 setprice(price); 38 } public String getnumber () { 41 return part_number; 42 } 43 public String getdescription () { 44 return part_description; 45 } 46 public int getquantity () { 47 return part_quantity; 48 } 49 public double getprice () { 50 return part_price; 51 } 52 public void showinvoice() { 53 System.out.printf("Number:%s\n", getnumber()); 54 System.out.printf("Description:%s\n", getdescription()); 55 System.out.printf("Quantity:%d\n", getquantity()); SteveHome Computing Workstation, Inc. Page 1
7 E:\THUWorks\java 程 式 設 計 \Invoice.java 2007 年 3 月 28 日 上 午 04:16 56 System.out.printf("Price:%.2f\n", getprice()); 57 } 58 public double getinvoiceamount() { 59 return part_quantity * part_price; 60 } } SteveHome Computing Workstation, Inc. Page 2
8 E:\THUWorks\java 程 式 設 計 \InvoiceTest.java 2007 年 3 月 28 日 上 午 04:17 1 // Prog.Name:InvoiceTest (depend on Invoice) 2 // StdNo.:s 邱 逸 夫 3 // input: none 4 // output: see code. 5 // Date: 03/21/07 6 import java.util.scanner; // program uses Scanner 7 8 public class InvoiceTest { 9 10 public static void main (String args[]) { Scanner input = new Scanner( System.in ); String part_number; 15 String part_description; 16 int part_quantity; 17 double part_price; Invoice myinvoice = new Invoice(); System.out.print("Enter Number:"); 22 // part_number = input.nextline(); 23 myinvoice.setnumber(input.nextline()); System.out.print("Enter Description:"); 26 // part_description = input.nextline(); 27 myinvoice.setdescription(input.nextline()); System.out.print("Enter Quantity:"); 30 // part_quantity = input.nextint(); 31 myinvoice.setquantity(input.nextint()); System.out.print("Enter Price:"); 34 // part_price = input.nextint(); 35 myinvoice.setprice(input.nextdouble()); System.out.println("The current item info:"); 38 myinvoice.showinvoice(); System.out.println("The current invoice amount:"); 41 System.out.println(myInvoice.getInvoiceAmount()); } } SteveHome Computing Workstation, Inc. Page 1
9 3.14 Create a class called Employee that includes three pieces of information as instance variables a first name (type String), a last name (type String) and a monthly salary (double). Your class should have a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, set it to 0.0. Write a test application named EmployeeTest that demonstrates class Employee's capabilities. Create two Employee objects and display each object's yearly salary. Then give each Employee a 10% raise and display each Employee's yearly salary again. E:\>java EmployeeTest Frist Employee Enter Frist Neme:Steve Enter Last Neme:Bob Enter Monthly Salary:0 Second Employee Enter Frist Neme:Steve Enter Last Neme:Joe Enter Monthly Salary:10 Third Employee Enter Frist Neme:Steve Enter Last Neme:Nick Enter Monthly Salary:19.9 This year is end. Our boss decided to give each employee's monthly salary +10%. Employee:Steve Bob Monthly Salary:0.0 The employee:steve Bob 's monthly salary NOW is 0.0 Employee:Steve Joe Monthly Salary:10.0 The employee:steve Joe 's monthly salary NOW is 11.0 Employee:Steve Nick Monthly Salary:19.9 The employee:steve Nick 's monthly salary NOW is 21.9 SteveHome Workstation HW List Page 4
10 E:\THUWorks\java 程 式 設 計 \Employee.java 2007 年 3 月 28 日 上 午 04:18 1 // Prog.Name:Employee 2 // StdNo.:s 邱 逸 夫 3 // input: none 4 // output: see code. 5 // Date: 03/28/07 6 public class Employee { 7 8 private String first_name; 9 private String last_name; 10 private double monthly_salary; public Employee () { 13 } public Employee (String fname, String lname, double msalary) { 16 first_name = fname; 17 last_name = lname; 18 if (msalary < 0) { 19 monthly_salary = 0; 20 } else { 21 monthly_salary = msalary; 22 } 23 } public void setfristname (String fname) { 26 first_name = fname; 27 } public void setlastname (String lname) { 30 last_name = lname; 31 } public void setmonthlysalary (double msalary) { 34 if (msalary < 0) { 35 monthly_salary = 0; 36 } else { 37 monthly_salary = msalary; 38 } 39 } public String getfristname () { 42 return first_name; 43 } 44 public String getlastname () { 45 return last_name; 46 } 47 public double getmonthlysalary (){ 48 return monthly_salary; 49 } public void showemployeeinfo() { 52 System.out.printf("Employee:%s %s\n", getfristname(), getlastname()); 53 System.out.printf("Monthly Salary:%.1f\n", getmonthlysalary()); 54 } 55 SteveHome Computing Workstation, Inc. Page 1
11 E:\THUWorks\java 程 式 設 計 \Employee.java 2007 年 3 月 28 日 上 午 04:18 56 } SteveHome Computing Workstation, Inc. Page 2
12 E:\THUWorks\java 程 式 設 計 \EmployeeTest.java 2007 年 3 月 28 日 上 午 04:18 1 import java.util.scanner; 2 3 public class EmployeeTest { 4 5 public static void main ( String args[] ){ 6 7 Scanner input = new Scanner( System.in ); 8 9 // Frist Employee 10 System.out.println("Frist Employee"); 11 Employee myfristemployee = new Employee(); 12 System.out.print("Enter Frist Neme:"); 13 myfristemployee.setfristname(input.nextline()); 14 System.out.print("Enter Last Neme:"); 15 myfristemployee.setlastname(input.nextline()); 16 System.out.print("Enter Monthly Salary:"); 17 myfristemployee.setmonthlysalary(input.nextdouble()); // Second Employee 20 System.out.println("Second Employee"); 21 input.nextline(); //Drop next line to fix input error. 22 Employee mysecondemployee = new Employee(); 23 System.out.print("Enter Frist Neme:"); 24 mysecondemployee.setfristname(input.nextline()); 25 System.out.print("Enter Last Neme:"); 26 mysecondemployee.setlastname(input.nextline()); 27 System.out.print("Enter Monthly Salary:"); 28 mysecondemployee.setmonthlysalary(input.nextdouble()); // Third Employee 31 System.out.println("Third Employee"); 32 input.nextline(); //Drop next line to fix input error. 33 Employee mythirdemployee = new Employee(); 34 System.out.print("Enter Frist Neme:"); 35 mythirdemployee.setfristname(input.nextline()); 36 System.out.print("Enter Last Neme:"); 37 mythirdemployee.setlastname(input.nextline()); 38 System.out.print("Enter Monthly Salary:"); 39 mythirdemployee.setmonthlysalary(input.nextdouble()); System.out.println(); 42 System.out.println("This year is end. Our boss decided to give each employee's monthly salary +10%.\n"); System.out.println(); 45 myfristemployee.showemployeeinfo(); //Show current Employee Info 46 myfristemployee.setmonthlysalary(myfristemployee.getmonthlysalary() * (11.0 /10.0)); //Add MonthlySalary to 110% 47 System.out.printf("The employee:%s %s 's monthly salary NOW is %.1f\n", myfristemployee. getfristname(), myfristemployee.getlastname(), myfristemployee.getmonthlysalary()); System.out.println(); 50 mysecondemployee.showemployeeinfo(); //Show current Employee Info 51 mysecondemployee.setmonthlysalary(mysecondemployee.getmonthlysalary() * ( 11.0/10.0)); //Add MonthlySalary to 110% 52 System.out.printf("The employee:%s %s 's monthly salary NOW is %.1f\n", mysecondemployee. SteveHome Computing Workstation, Inc. Page 1
13 E:\THUWorks\java 程 式 設 計 \EmployeeTest.java 2007 年 3 月 28 日 上 午 04:18 getfristname(), mysecondemployee.getlastname(), mysecondemployee.getmonthlysalary ()); System.out.println(); 55 mythirdemployee.showemployeeinfo(); //Show current Employee Info 56 mythirdemployee.setmonthlysalary(mythirdemployee.getmonthlysalary() * (11.0 /10.0)); //Add MonthlySalary to 110% 57 System.out.printf("The employee:%s %s 's monthly salary NOW is %.1f\n", mythirdemployee. getfristname(), mythirdemployee.getlastname(), mythirdemployee.getmonthlysalary()); } 60 } SteveHome Computing Workstation, Inc. Page 2
14 3.15 Create a class called Date that includes three pieces of information as instance variables a month (type int), a day (type int) and a year (type int). Your class should have a constructor that initializes the three instance variables and assumes that the values provided are correct. Provide a set and a get method for each instance variable. Provide a method displaydate that displays the month, day and year separated by forward slashes (/). Write a test application named DateTest that demonstrates class Date's capabilities. E:\>java DateTest DateTest for Object Date. Enter year:1 Enter month:1 Enter day:1 Incorrect year, the data will rest to 1990! You just enter the date:1/1/1990 E:\>java DateTest DateTest for Object Date. Enter year:2000 Enter month:2 Enter day:29 You just enter the date:2/29/2000 E:\>java DateTest DateTest for Object Date. Enter year:2001 Enter month:2 Enter day:29 Incorrect day(february check), the data will rest to 1! You just enter the date:2/1/2001 E:\>java DateTest DateTest for Object Date. Enter year:2006 Enter month:7 Enter day:31 You just enter the date:7/31/2006 E:\>java DateTest DateTest for Object Date. Enter year:2006 Enter month:7 Enter day:31 SteveHome Workstation HW List Page 5 You just enter the date:7/31/2006
15 E:\THUWorks\java 程 式 設 計 \Date.java 2007 年 3 月 28 日 上 午 04:18 1 // Prog.Name:Date 2 // StdNo.:s 邱 逸 夫 3 // input: none 4 // output: see code. 5 // Date: 03/28/07 6 public class Date { 7 private int month = 1; 8 private int day = 1; 9 private int year = 1990; //The Java's pre(oak) birthday. 10 private int replace_date = 0; // 0 = 28 days, 1 = 29 days for February use only. 11 private int replace_day = 1; // 0 = 30 days, 1 = 31 days public void setyear(int the_year) { 14 if ((1989<the_year) && (65535>the_year)) { 15 year = the_year; 16 } else { 17 System.out.println("Incorrect year, the data will rest to 1990!"); 18 } 19 // 不 能 被 4 整 除 的 不 是 閏 年, 能 被 100 整 除 而 不 能 被 400 整 除 的 年 份 不 是 閏 年, 能 被 3200 整 除 的 也 不 是 閏 年 20 if ((the_year%4!= 0) ((the_year%100 == 0) && (the_year%400!= 0)) ( the_year%3200 == 0)) { 21 replace_date = 0; 22 } else { 23 replace_date = 1; 24 } 25 } public void setmonth(int the_month) { 28 if ((0<the_month) && (13>the_month)) { 29 month = the_month; 30 } else { 31 System.out.println("Incorrect month, the data will rest to 1!"); 32 } 33 if (((the_month%2 == 1) && (the_month <= 7)) ((the_month%2 == 0) && ( the_month >= 8))) { // replace_day = 1; 35 } else { // replace_day = 0; 37 } 38 } public void setday(int the_day) { 41 if (replace_day == 1) { 42 if ((0<the_day) && (32>the_day) ) { 43 day = the_day; 44 } else { 45 System.out.println("Incorrect day(even check), the data will rest to 1!"); 46 } 47 } else if (getmonth() == 2) { //28 天, 是 否 閏 年? 48 if ((0<the_day) && (30>the_day) && (replace_date == 1)) { 49 day = the_day; 50 } else if ((0<the_day) && (29>the_day) && (replace_date == 0)) { 51 day = the_day; 52 } else { 53 System.out.println("Incorrect day(february check), the data will rest to 1!"); SteveHome Computing Workstation, Inc. Page 1
16 E:\THUWorks\java 程 式 設 計 \Date.java 2007 年 3 月 28 日 上 午 04:18 54 } 55 } else { 56 if ((0<the_day) && (31>the_day)) { 57 day = the_day; 58 } else { 59 System.out.println("Incorrect day(odd check), the data will rest to 1!"); 60 } 61 } 62 } public int getmonth(){ 65 return month; 66 } 67 public int getday(){ 68 return day; 69 } 70 public int getyear(){ 71 return year; 72 } public Date (int the_month, int the_day, int the_year){ 75 setyear(the_year); 76 setmonth(the_month); 77 setday(the_day); 78 } public String displaydate () { 81 //return year.tostring() + "/" + month.tostring()+ "/" + day.tostring(); 82 return month + "/" + day + "/" + year; 83 } 84 } SteveHome Computing Workstation, Inc. Page 2
17 E:\THUWorks\java 程 式 設 計 \DateTest.java 2007 年 3 月 28 日 上 午 04:17 1 // Prog.Name:DateTest 2 // StdNo.:s 邱 逸 夫 3 // input: year, month, day. All input value must be Type:int. 4 // output: see code. 5 // Date: 03/28/07 6 import java.util.scanner; // program uses Scanner 7 8 public class DateTest { 9 10 public static void main(string args[]) { int month; 13 int day; 14 int year; 15 byte trymore = 'y'; System.out.println("DateTest for Object Date."); Scanner input = new Scanner( System.in ); System.out.print("Enter year:"); 22 year = input.nextint(); 23 System.out.print("Enter month:"); 24 month = input.nextint(); 25 System.out.print("Enter day:"); 26 day = input.nextint(); Date mydate = new Date(month, day, year); System.out.println("You just enter the date:" + mydate.displaydate()); } } SteveHome Computing Workstation, Inc. Page 1
System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :
Benjamin Michael Java Homework 3 10/31/2012 1) Sales.java Code // Sales.java // Program calculates sales, based on an input of product // number and quantity sold import java.util.scanner; public class
java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner
java.util.scanner java.util.scanner is a class in the Java API used to create a Scanner object, an extremely versatile object that you can use to input alphanumeric characters from several input sources
OBJECT ORIENTED PROGRAMMING IN JAVA EXERCISES
OBJECT ORIENTED PROGRAMMING IN JAVA EXERCISES CHAPTER 1 1. Write Text Based Application using Object Oriented Approach to display your name. // filename: Name.java // Class containing display() method,
Chapter 2 Introduction to Java programming
Chapter 2 Introduction to Java programming 1 Keywords boolean if interface class true char else package volatile false byte final switch while throws float private case return native void protected break
Introduction to Java
Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high
Sample CSE8A midterm Multiple Choice (circle one)
Sample midterm Multiple Choice (circle one) (2 pts) Evaluate the following Boolean expressions and indicate whether short-circuiting happened during evaluation: Assume variables with the following names
Part I. Multiple Choice Questions (2 points each):
Part I. Multiple Choice Questions (2 points each): 1. Which of the following is NOT a key component of object oriented programming? (a) Inheritance (b) Encapsulation (c) Polymorphism (d) Parallelism ******
Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language
Translation Translating to Java Introduction to Computer Programming The job of a programmer is to translate a problem description into a computer language. You need to be able to convert a problem description
1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius
Programming Concepts Practice Test 1 1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius 2) Consider the following statement: System.out.println("1
CompSci 125 Lecture 08. Chapter 5: Conditional Statements Chapter 4: return Statement
CompSci 125 Lecture 08 Chapter 5: Conditional Statements Chapter 4: return Statement Homework Update HW3 Due 9/20 HW4 Due 9/27 Exam-1 10/2 Programming Assignment Update p1: Traffic Applet due Sept 21 (Submit
COSC 1020 3.0 Introduction to Computer Science I Section A, Summer 2005. Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19
Term Test #2 COSC 1020 3.0 Introduction to Computer Science I Section A, Summer 2005 Family Name: Given Name(s): Student Number: Question Out of Mark A Total 16 B-1 7 B-2 4 B-3 4 B-4 4 B Total 19 C-1 4
J a v a Quiz (Unit 3, Test 0 Practice)
Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points
First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science
First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca
CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013
Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)
CS170 Lab 11 Abstract Data Types & Objects
CS170 Lab 11 Abstract Data Types & Objects Introduction: Abstract Data Type (ADT) An abstract data type is commonly known as a class of objects An abstract data type in a program is used to represent (the
Topic 11 Scanner object, conditional execution
Topic 11 Scanner object, conditional execution "There are only two kinds of programming languages: those people always [complain] about and those nobody uses." Bjarne Stroustroup, creator of C++ Copyright
Classes and Objects. Agenda. Quiz 7/1/2008. The Background of the Object-Oriented Approach. Class. Object. Package and import
Classes and Objects 2 4 pm Tuesday 7/1/2008 @JD2211 1 Agenda The Background of the Object-Oriented Approach Class Object Package and import 2 Quiz Who was the oldest profession in the world? 1. Physician
Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75
Preet raj Core Java and Databases CS4PR Time Allotted: 3 Hours Final Exam: Total Possible Points 75 Q1. What is difference between overloading and overriding? 10 points a) In overloading, there is a relationship
Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.
1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays
Building Java Programs
Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: 3.3-3.4 self-check: #16-19 exercises: #11 videos: Ch. 3 #4 Interactive programs We have written programs that print
Line-based file processing
Line-based file processing reading: 6.3 self-check: #7-11 exercises: #1-4, 8-11 Hours question Given a file hours.txt with the following contents: 123 Kim 12.5 8.1 7.6 3.2 456 Brad 4.0 11.6 6.5 2.7 12
Introduction to Programming
Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems [email protected] Spring 2015 Week 2b: Review of Week 1, Variables 16 January 2015 Birkbeck
Chulalongkorn University International School of Engineering Department of Computer Engineering 2140105 Computer Programming Lab.
Chulalongkorn University Name International School of Engineering Student ID Department of Computer Engineering Station No. 2140105 Computer Programming Lab. Date Lab 2 Using Java API documents, command
CISC 181 Project 3 Designing Classes for Bank Accounts
CISC 181 Project 3 Designing Classes for Bank Accounts Code Due: On or before 12 Midnight, Monday, Dec 8; hardcopy due at beginning of lecture, Tues, Dec 9 What You Need to Know This project is based on
IRA EXAMPLES. This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account).
IRA EXAMPLES This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account). Definite Counting Loop Example IRA After x Years This first example illustrates
AP Computer Science Static Methods, Strings, User Input
AP Computer Science Static Methods, Strings, User Input Static Methods The Math class contains a special type of methods, called static methods. A static method DOES NOT operate on an object. This is because
Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.
Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java
JAVA ARRAY EXAMPLE PDF
JAVA ARRAY EXAMPLE PDF Created By: Umar Farooque Khan 1 Java array example for interview pdf Program No: 01 Print Java Array Example using for loop package ptutorial; public class PrintArray { public static
Introduction to Java. CS 3: Computer Programming in Java
Introduction to Java CS 3: Computer Programming in Java Objectives Begin with primitive data types Create a main class with helper methods Learn how to call built-in class methods and instance methods
Week 1: Review of Java Programming Basics
Week 1: Review of Java Programming Basics Sources: Chapter 2 in Supplementary Book (Murach s Java Programming) Appendix A in Textbook (Carrano) Slide 1 Outline Objectives A simple Java Program Data-types
File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)
File class in Java File Input and Output (Savitch, Chapter 10) TOPICS File Input Exception Handling File Output Programmers refer to input/output as "I/O". The File class represents files as objects. The
Building Java Programs
Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: 3.3-3.4 self-check: #16-19 exercises: #11 videos: Ch. 3 #4 Interactive programs We have written programs that print
CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O
CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O 1 Sending Output to a (Text) File import java.util.scanner; import java.io.*; public class TextFileOutputDemo1 public static void
Comp 248 Introduction to Programming
Comp 248 Introduction to Programming Chapter 2 - Console Input & Output Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University, Montreal, Canada These slides has been
It has a parameter list Account(String n, double b) in the creation of an instance of this class.
Lecture 10 Private Variables Let us start with some code for a class: String name; double balance; // end Account // end class Account The class we are building here will be a template for an account at
Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.
Scanner The Scanner class is intended to be used for input. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. For example, suppose the input
Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard
INPUT & OUTPUT I/O Example Using keyboard input for characters import java.util.scanner; class Echo{ public static void main (String[] args) { Scanner sc = new Scanner(System.in); // scanner for the keyboard
qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq
qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq Introduction to Programming using Java wertyuiopasdfghjklzxcvbnmqwertyui
Introduction to Computer Programming, Spring Term 2014 Practice Assignment 3 Discussion 15.3.2014-20.3.2014
German University in Cairo Media Engineering and Technology Prof. Dr. Slim Abdennadher Dr. Ahmed Gamal Introduction to Computer Programming, Spring Term 2014 Practice Assignment 3 Discussion 15.3.2014-20.3.2014
AP Computer Science File Input with Scanner
AP Computer Science File Input with Scanner Subset of the Supplement Lesson slides from: Building Java Programs, Chapter 6 by Stuart Reges and Marty Stepp (http://www.buildingjavaprograms.com/ ) Input/output
Lab 5: Bank Account. Defining objects & classes
Lab 5: Bank Account Defining objects & classes Review: Basic class structure public class ClassName Fields Constructors Methods Three major components of a class: Fields store data for the object to use
More on Objects and Classes
Software and Programming I More on Objects and Classes Roman Kontchakov Birkbeck, University of London Outline Object References Class Variables and Methods Packages Testing a Class Discovering Classes
MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION
MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION 1. Write a loop that computes (No need to write a complete program) 100 1 99 2 98 3 97... 4 3 98 2 99 1 100 Note: this is not the only solution; double sum
Building Java Programs
Building Java Programs Chapter 4 Lecture 4-1: Scanner; if/else reading: 3.3 3.4, 4.1 Interactive Programs with Scanner reading: 3.3-3.4 1 Interactive programs We have written programs that print console
Limitations of Data Encapsulation and Abstract Data Types
Limitations of Data Encapsulation and Abstract Data Types Paul L. Bergstein University of Massachusetts Dartmouth [email protected] Abstract One of the key benefits provided by object-oriented programming
MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java
Design Patterns in Java
Design Patterns in Java 2004 by CRC Press LLC 2 BASIC PATTERNS The patterns discussed in this section are some of the most common, basic and important design patterns one can find in the areas of object-oriented
In this Chapter you ll learn:
Now go, write it before them in a table, and note it in a book. Isaiah 30:8 To go beyond is as wrong as to fall short. Confucius Begin at the beginning, and go on till you come to the end: then stop. Lewis
CASCADING IF-ELSE. Cascading if-else Semantics. What the computer executes: What is the truth value 1? 3. Execute path 1 What is the truth value 2?
CASCADING IF-ELSE A cascading if- is a composite of if- statements where the false path of the outer statement is a nested if- statement. The nesting can continue to several levels. Cascading if- Syntax
Arrays in Java. Working with Arrays
Arrays in Java So far we have talked about variables as a storage location for a single value of a particular data type. We can also define a variable in such a way that it can store multiple values. Such
Basics of Java Programming Input and the Scanner class
Basics of Java Programming Input and the Scanner class CSC 1051 Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/
CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java
CS1020 Data Structures and Algorithms I Lecture Note #1 Introduction to Java Objectives Java Basic Java features C Java Translate C programs in CS1010 into Java programs 2 References Chapter 1 Section
Java is an Object-Oriented Language. As a language that has the Object Oriented feature, Java supports the following fundamental concepts:
JAVA OBJECTS JAVA OBJECTS AND CLASSES Java is an Object-Oriented Language. As a language that has the Object Oriented feature, Java supports the following fundamental concepts: Polymorphism Inheritance
You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:
Lecture 7 Picking Balls From an Urn The problem: An urn has n (n = 10) balls numbered from 0 to 9 A ball is selected at random, its' is number noted, it is set aside, and another ball is selected from
CSE 8B Midterm Fall 2015
Name Signature Tutor Student ID CSE 8B Midterm Fall 2015 Page 1 (XX points) Page 2 (XX points) Page 3 (XX points) Page 4 (XX points) Page 5 (XX points) Total (XX points) 1. What is the Big-O complexity
AP Computer Science Java Subset
APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall
Programming in Java. What is in This Chapter? Chapter 1
Chapter 1 Programming in Java What is in This Chapter? This first chapter introduces you to programming JAVA applications. It assumes that you are already familiar with programming and that you have taken
JAVA - OBJECT & CLASSES
JAVA - OBJECT & CLASSES http://www.tutorialspoint.com/java/java_object_classes.htm Copyright tutorialspoint.com Java is an Object-Oriented Language. As a language that has the Object Oriented feature,
Some Scanner Class Methods
Keyboard Input Scanner, Documentation, Style Java 5.0 has reasonable facilities for handling keyboard input. These facilities are provided by the Scanner class in the java.util package. A package is a
AP Computer Science Java Mr. Clausen Program 9A, 9B
AP Computer Science Java Mr. Clausen Program 9A, 9B PROGRAM 9A I m_sort_of_searching (20 points now, 60 points when all parts are finished) The purpose of this project is to set up a program that will
Token vs Line Based Processing
Token vs Line Based Processing Mixing token based processing and line based processing can be tricky particularly on the console Problems I saw in program 5: console.next()
CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals
CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasket { public static void main(string[]
Introduction to Object-Oriented Programming
Introduction to Object-Oriented Programming Programs and Methods Christopher Simpkins [email protected] CS 1331 (Georgia Tech) Programs and Methods 1 / 8 The Anatomy of a Java Program It is customary
Java CPD (I) Frans Coenen Department of Computer Science
Java CPD (I) Frans Coenen Department of Computer Science Content Session 1, 12:45-14:30 (First Java Programme, Inheritance, Arithmetic) Session 2, 14:45-16:45 (Input and Programme Constructs) Materials
Object-Oriented Programming in Java
CSCI/CMPE 3326 Object-Oriented Programming in Java Class, object, member field and method, final constant, format specifier, file I/O Dongchul Kim Department of Computer Science University of Texas Rio
Homework/Program #5 Solutions
Homework/Program #5 Solutions Problem #1 (20 points) Using the standard Java Scanner class. Look at http://natch3z.blogspot.com/2008/11/read-text-file-using-javautilscanner.html as an exampleof using the
IBATIS - DYNAMIC SQL
IBATIS - DYNAMIC SQL http://www.tutorialspoint.com/ibatis/ibatis_dynamic_sql.htm Copyright tutorialspoint.com Dynamic SQL is a very powerful feature of ibatis. Sometimes you have to change the WHERE clause
(Eng. Hayam Reda Seireg) Sheet Java
(Eng. Hayam Reda Seireg) Sheet Java 1. Write a program to compute the area and circumference of a rectangle 3 inche wide by 5 inches long. What changes must be made to the program so it works for a rectangle
Iteration CHAPTER 6. Topic Summary
CHAPTER 6 Iteration TOPIC OUTLINE 6.1 while Loops 6.2 for Loops 6.3 Nested Loops 6.4 Off-by-1 Errors 6.5 Random Numbers and Simulations 6.6 Loop Invariants (AB only) Topic Summary 6.1 while Loops Many
Using Files as Input/Output in Java 5.0 Applications
Using Files as Input/Output in Java 5.0 Applications The goal of this module is to present enough information about files to allow you to write applications in Java that fetch their input from a file instead
Software Development with UML and Java 2 SDJ I2, Spring 2010
Software Development with UML and Java 2 SDJ I2, Spring 2010 Agenda week 7, 2010 Pakages Looking back Looking forward Packages Interfaces Page 1 Spring 2010 Download, Install/Setup 1. Java SE SDK (http://java.sun.com/javase/downloads)
Using Two-Dimensional Arrays
Using Two-Dimensional Arrays Great news! What used to be the old one-floor Java Motel has just been renovated! The new, five-floor Java Hotel features a free continental breakfast and, at absolutely no
2009 Tutorial (DB4O and Visual Studio 2008 Express)
Jákup Wenningstedt Hansen Side 1 12-10-2009 2009 Tutorial (DB4O and Visual Studio 2008 Express)...1 Download the Database...1 Installation of the Database...2 Creating the project in VS...3 Pointing VS
Chapter 2. println Versus print. Formatting Output withprintf. System.out.println for console output. console output. Console Input and Output
Chapter 2 Console Input and Output System.out.println for console output System.out is an object that is part of the Java language println is a method invoked dby the System.out object that can be used
JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4
JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4 NOTE: SUN ONE Studio is almost identical with NetBeans. NetBeans is open source and can be downloaded from www.netbeans.org. I
Programming Languages CIS 443
Course Objectives Programming Languages CIS 443 0.1 Lexical analysis Syntax Semantics Functional programming Variable lifetime and scoping Parameter passing Object-oriented programming Continuations Exception
Yosemite National Park, California. CSE 114 Computer Science I Inheritance
Yosemite National Park, California CSE 114 Computer Science I Inheritance Containment A class contains another class if it instantiates an object of that class HAS-A also called aggregation PairOfDice
LAB4 Making Classes and Objects
LAB4 Making Classes and Objects Objective The main objective of this lab is class creation, how its constructer creation, object creation and instantiation of objects. We will use the definition pane to
Chapter 2 Elementary Programming
Chapter 2 Elementary Programming 2.1 Introduction You will learn elementary programming using Java primitive data types and related subjects, such as variables, constants, operators, expressions, and input
Java Basics: Data Types, Variables, and Loops
Java Basics: Data Types, Variables, and Loops If debugging is the process of removing software bugs, then programming must be the process of putting them in. - Edsger Dijkstra Plan for the Day Variables
LOOPS CHAPTER CHAPTER GOALS
jfe_ch04_7.fm Page 139 Friday, May 8, 2009 2:45 PM LOOPS CHAPTER 4 CHAPTER GOALS To learn about while, for, and do loops To become familiar with common loop algorithms To understand nested loops To implement
CS 121 Intro to Programming:Java - Lecture 11 Announcements
CS 121 Intro to Programming:Java - Lecture 11 Announcements Next Owl assignment up, due Friday (it s short!) Programming assignment due next Monday morning Preregistration advice: More computing? Take
Moving from CS 61A Scheme to CS 61B Java
Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you
Manual For Using the NetBeans IDE
1 Manual For Using the NetBeans IDE The content of this document is designed to help you to understand and to use the NetBeans IDE for your Java programming assignments. This is only an introductory presentation,
Chapter 3. Input and output. 3.1 The System class
Chapter 3 Input and output The programs we ve looked at so far just display messages, which doesn t involve a lot of real computation. This chapter will show you how to read input from the keyboard, use
Course Intro Instructor Intro Java Intro, Continued
Course Intro Instructor Intro Java Intro, Continued The syllabus Java etc. To submit your homework, do Team > Share Your repository name is csse220-200830-username Use your old SVN password. Note to assistants:
1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders
1.00 Lecture 1 Course Overview Introduction to Java Reading for next time: Big Java: 1.1-1.7 Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders
5.2 Q2 The control variable of a counter-controlled loop should be declared as: a.int. b.float. c.double. d.any of the above. ANS: a. int.
Java How to Program, 5/e Test Item File 1 of 5 Chapter 5 Section 5.2 5.2 Q1 Counter-controlled repetition requires a.a control variable and initial value. b.a control variable increment (or decrement).
Example of a Java program
Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);
Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013
Masters programmes in Computer Science and Information Systems Object-Oriented Design and Programming Sample module entry test xxth December 2013 This sample paper has more questions than the real paper
CS114: Introduction to Java
CS114: Introduction to Java Fall 2015, Mon/Wed, 5:30 PM - 6:45 PM Instructor: Pejman Ghorbanzade to Assignment 4 Release Date: Nov 04, 2015 at 5:30 PM Due Date: Nov 18, 2015 at 5:30 PM Question 1 An n
WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.
WA2099 Introduction to Java using RAD 8.0 Student Labs Web Age Solutions Inc. 1 Table of Contents Lab 1 - The HelloWorld Class...3 Lab 2 - Refining The HelloWorld Class...20 Lab 3 - The Arithmetic Class...25
12-6 Write a recursive definition of a valid Java identifier (see chapter 2).
CHAPTER 12 Recursion Recursion is a powerful programming technique that is often difficult for students to understand. The challenge is explaining recursion in a way that is already natural to the student.
JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.
http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral
Lecture 1 Introduction to Java
Programming Languages: Java Lecture 1 Introduction to Java Instructor: Omer Boyaci 1 2 Course Information History of Java Introduction First Program in Java: Printing a Line of Text Modifying Our First
Introduction to Java Lecture Notes. Ryan Dougherty [email protected]
1 Introduction to Java Lecture Notes Ryan Dougherty [email protected] Table of Contents 1 Versions....................................................................... 2 2 Introduction...................................................................
public void creditaccount(string accountnumber, float amount) { this.accounts.get(accountnumber).credit(amount); }
package bank; //... public class Bank { private Map accounts; public Bank() { this.accounts = new HashMap(); public void addaccount(bankaccount account) { this.accounts.put(account.getnumber(),
