《面向对象程序设计(双语)》课程实验教学大纲 一、课程基本信息 课程代码:16073504 课程名称:面向对象程序设计(双语) 英文名称:Object-Oriented Programming 实验总学时:22 适用专业:计算机科学技术专业 课程类别:专业课 先修课程:程序设计 二、实验教学的总体目的和要求 1、对学生的要求 ()具有C语言程序设计基础: (②)实验课程不仅需要课上投入,课后需要有一定的练习时间: (③)能够根据规范撰写实验报告: 2、对教师的要求 (①)合理设计实验项目: (2)根据实验内容有效控制学生的实验过程: (③)在实验指导过程中,根据学生个性问题提供指导,并且总结共性问题,集中 指导: 3、对实验条件的要求 (1)具有一定性能的电脑和通畅的网络环境: (②)安装JDK和Eclipse
《面向对象程序设计(双语)》课程实验教学大纲 一、课程基本信息 课程代码:16073504 课程名称:面向对象程序设计(双语) 英文名称: Object-Oriented Programming 实验总学时:22 适用专业:计算机科学技术专业 课程类别:专业课 先修课程:程序设计 二、实验教学的总体目的和要求 1、对学生的要求 (1) 具有 C 语言程序设计基础; (2) 实验课程不仅需要课上投入,课后需要有一定的练习时间; (3) 能够根据规范撰写实验报告; 2、对教师的要求 (1) 合理设计实验项目; (2) 根据实验内容有效控制学生的实验过程; (3) 在实验指导过程中,根据学生个性问题提供指导,并且总结共性问题,集中 指导; 3、对实验条件的要求 (1) 具有一定性能的电脑和通畅的网络环境; (2) 安装 JDK 和 Eclipse
三、实验教学内容 实验项目一 实验名称:Introduction 实验内容: 1.Printing Strings Write aJava program thatprints the message,"Roses are red".Your program will be a class definition containinga main method-see the Linco/mexamp in Listing 1.1 ofthe text f youneed guidance.Rememberthe The name of the class must match the name of the file (but without the,java extension) The main method must be inside the class definition(between the first{and the last). The statement that printsthe message must be inside main. .When it works that entire poem Roses are red violets are blue Sugar is sweet And so are you」 2.Documentation File Co Java program that counts English.Frenchand Spanish Save this file to your directory and compile and run it to see what it does.Then modify it as follows: (1)Use /style comments to add a comment header at the top of the file that includes the name of the program,your name,and a brief description of what the program does,neatly formatted (2)Add a comment before each printin that indicates what language the next line is in. Experiment with leaving a blank line before each of these comment lines (in the program itself.not the output).Is the program easier to read with or without these blank lines? (3)Remove one of the slashes from one of your comment lines and recompile the program,so one of the comments starts with a single/.What ero do you get?Put the slash back in. (4)Try putting a comment within acommen so that a/appears after the line.Does this cause problems? (5)Consult the documentation guidelines in Appendix F of the text.Have you violated any of them?List two things that you could imagine yourself or someone else doing in commenting this program that these. 3.Identifiers File Simplejava contains a simple Java program that prints a message.The identifier tha represents the name of this program is Simple but we could have chosen a different identifier subject to certain rules and conventions.An identifier may contain any combination of letters, digits.the underscore character.and the dollar sign.but cannot begin with a digit.Furthermore.by epresent class names (which includes pogram ames)begin with a ta yo wn'tt Sror if yor name den't rt with
三、实验教学内容 实验项目一 实验名称:Introduction 实验内容: 1. Printing Strings Write a Java program that prints the message, “Roses are red”. Your program will be a class definition containing a main method—see the Lincoln example in Listing 1.1 of the text if you need guidance. Remember the following: The name of the class must match the name of the file (but without the .java extension). The main method must be inside the class definition (between the first { and the last}). The statement that prints the message must be inside main. Compile and run your program. When it works correctly, modify it so that it prints the entire poem: Roses are red Violets are blue Sugar is sweet And so are you! 2. Documentation File Count.java contains a Java program that counts from 1 to 5 in English, French, and Spanish. Save this file to your directory and compile and run it to see what it does. Then modify it as follows: (1) Use // style comments to add a comment header at the top of the file that includes the name of the program, your name,and a brief description of what the program does, neatly formatted. Include a delimiter line (e.g., all stars) at the beginning and end of the header. (2) Add a comment before each println that indicates what language the next line is in. Experiment with leaving a blank line before each of these comment lines (in the program itself, not the output). Is the program easier to read with or without these blank lines? (3) Remove one of the slashes from one of your comment lines and recompile the program, so one of the comments starts with a single /. What error do you get? Put the slash back in. (4) Try putting a comment within a comment, so that a // appears after the initial // on a comment line. Does this cause problems? (5) Consult the documentation guidelines in Appendix F of the text. Have you violated any of them? List two things that you could imagine yourself or someone else doing in commenting this program that these guidelines discourage. 3. Identifiers File Simple.java contains a simple Java program that prints a message. The identifier that represents the name of this program is Simple, but we could have chosen a different identifier subject to certain rules and conventions. An identifier may contain any combination of letters, digits, the underscore character, and the dollar sign, but cannot begin with a digit. Furthermore, by convention, identifiers that represent class names (which includes program names) begin with a capital letter. This means that you won’t get an error if your program name doesn’t start with a
capital letter (as long as what it starts with is legal for an identifier).but it's better style if you do seem arhit rary now but have lots of in your programsyou see the benefit.Of cour,the program name should always be reasonably des riptive of the program. Indicate whether each name below is a legal identifier.and if so.whether it is a good choice to name this program.If the answer to either question is no,explain why.Then save Simple java to your directory and check your answers by modifying it to try each note that you will have to change thefle name each time to match the program name or you will always get an error (1)simple (Why do you even have to change the name of the file in this case?) (2)SimpleProgram (3)1Simple 8 (6)$12345 (7)Simple! 4.Syntax errors yntaxrors in you gives eror messages and does no t som of th se messa es are what they mean.Unfortunately,at this stage in the game many of the messages will not be meaningful except to let you know where the first error occurred.Your only choice is to carefully study your program to find the error.In the following you will introduce a few typical to a simple program and examTis is (1)Type the follo the traditional first program a computer scientist writes in a new language. Compile and run the program to see what it does.Then make the changes below.answering the questions as you go (2)Class name different from file name.Delete one (el)from the name of the class (so the first non com ent line is public class Helo).save the program,and compile it.What was the error message? (3)Misspelling inside string.Correct the mistake above,then delete one l from the Hello in the message to be printed(inside the quotation marks).Save the program and recompile it There is no error message -why not?Now run the program.What has changed? (4)No ending mark ina string literal.Correct the spelling in the string then delete the ending 9u ation mark enclos ng the ring Hello, Wo Save the program and recompile it.What error message(s)do you get? (5)No beginning quotation mark in a string literal.Put the ending quotation mark back,then take out the beginning one.Save and recompile.How many errors this time?Lots,even though there is really only one emor.When you get lots of errors always concentrate on finding the fixing tha e will fix the rest.After we s tudy variables the error messages that came up this time will make more sense (6)No semicolon after a statement.Fix the last error (put the quotation mark back).Now remove the semicolon at the end of the line that prints the message.Save the program and recompile it.What error mess age(s)do you get?
capital letter (as long as what it starts with is legal for an identifier), but it’s better style if you do. This may seem arbitrary now, but later when you have lots of identifiers in your programs you’ll see the benefit. Of course, the program name should always be reasonably descriptive of the program. Indicate whether each name below is a legal identifier, and if so, whether it is a good choice to name this program. If the answer to either question is no, explain why. Then save Simple.java to your directory and check your answers by modifying it to try each—note that you will have to change the file name each time to match the program name or you will always get an error. (1) simple (Why do you even have to change the name of the file in this case?) (2) SimpleProgram (3) 1 Simple (4) _Simple_ (5) *Simple* (6) $123_45 (7) Simple! 4. Syntax errors When you make syntax errors in your program the compiler gives error messages and does not create the bytecode file. It saves time and frustration to learn what some of these messages are and what they mean. Unfortunately, at this stage in the game many of the messages will not be meaningful except to let you know where the first error occurred. Your only choice is to carefully study your program to find the error. In the following you will introduce a few typical errors into a simple program and examine the error messages. (1) Type the following program into a file called Hello.java. (This is the traditional first program a computer scientist writes in a new language.) Compile and run the program to see what it does. Then make the changes below, answering the questions as you go. (2) Class name different from file name. Delete one l (el) from the name of the class (so the first non-comment line is public class Helo), save the program, and recompile it. What was the error message? (3) Misspelling inside string. Correct the mistake above, then delete one l from the Hello in the message to be printed(inside the quotation marks). Save the program and recompile it. There is no error message—why not? Now run the program. What has changed? (4) No ending quotation mark in a string literal. Correct the spelling in the string, then delete the ending quotation mark enclosing the string Hello, World!. Save the program and recompile it. What error message(s) do you get? (5) No beginning quotation mark in a string literal. Put the ending quotation mark back, then take out the beginning one. Save and recompile. How many errors this time? Lots, even though there is really only one error. When you get lots of errors always concentrate on finding the first one listed!! Often fixing that one will fix the rest. After we study variables the error messages that came up this time will make more sense. (6) No semicolon after a statement. Fix the last error (put the quotation mark back). Now remove the semicolon at the end of the line that prints the message. Save the program and recompile it. What error message(s) do you get?
实验性质:验证性 实验学时:2 实验目的与要求 ()掌握输出字符串 (②)熟悉注释方式以及合法的标识符定义: (3)能够识别基本的语法错误; 实验条件: ()CPUi5及以上,内存4G及以上: ②网络顺畅: (3)安装jdk、eclipse或Myeclipse 研究与思考: (①)标识符大小写敏感问题 (2)如何调试错误? 融入点:通过立法监督强调编码的规范性 实验项目二 实验名称:Data and Expressions 实验内容: 1.String literals The goal in this exercise is to develop a program that will print out a list of student names together with other information for each.The b charcter (an ape squence)is helpful in getting the (1)Save Names.java to your directory.Compile and run it to see how it works (2)Modify the program so that your name and hometown and the name and hometown of at least two classmates sitting near you in lab also are printed.Save.compile and run the program Make sure the columns line up. ()Modify the program to add a third com with the intended major of each person( Sally's major is Computer Science and Alexander's major is Math).Be sure to add a label a the top of the third column and be sure everything is lined up(use tab characters!). 2.String Concatenation Write a Java program that prints a table with a list of at least 5 students together with their grades earned(lab pints,bonus points,and the total)inthe format below ///////八NN Student Points■
实验性质:验证性 实验学时:2 实验目的与要求: (1) 掌握输出字符串; (2) 熟悉注释方式以及合法的标识符定义; (3) 能够识别基本的语法错误; 实验条件: (1) CPU i5 及以上,内存 4G 及以上; (2) 网络顺畅; (3) 安装 jdk、eclipse 或 Myeclipse 研究与思考: (1) 标识符大小写敏感问题 (2) 如何调试错误? 融入点:通过立法监督强调编码的规范性 实验项目二 实验名称:Data and Expressions 实验内容: 1. String literals The goal in this exercise is to develop a program that will print out a list of student names together with other information for each. The tab character (an escape sequence) is helpful in getting the list to line up nicely. A program with only two names is in the file Names.java. (1) Save Names.java to your directory. Compile and run it to see how it works. (2) Modify the program so that your name and hometown and the name and hometown of at least two classmates sitting near you in lab also are printed. Save, compile and run the program. Make sure the columns line up. (3) Modify the program to add a third column with the intended major of each person (assume Sally's major is Computer Science and Alexander's major is Math). Be sure to add a label at the top of the third column and be sure everything is lined up (use tab characters!). 2. String Concatenation Write a Java program that prints a table with a list of at least 5 students together with their grades earned (lab points, bonus points, and the total) in the format below. ///////////////////\\\\\\\\\\\\\\\\\\\ == Student Points ==
NN\N//1/1/////1/ Name Lab Bonus Total Joe 43 7 50 william 50 8 58 Mary Sue 39 10 49 The requirements for the programare as follows (1)Print the rder on the top asl rated (using the ss and backsash characters) (2)0s e tab characters to get your columns aligned and you must use the+operator both for addition and string concatenation. (3)Make up your own student names and points-the ones shown are just for illustration purposes.You need 5 names. 3.Escape sequences (1)Observing the Behavior of+To see the behavior of+in different settings do the following a.Study the program below,which is in file PlusTest.java. b.Save PlusTest iava to your directory. c.Compile and run the program.For each of the last three output statements (the ones dealing )write down what was printed.Now for each explain why the computer printed wha If both operands are numbers+is treated as ordinary addition.(NOTE:in the expression a+b the a and b are called the operands If at least one operand is a string the other operand is converted to a string and is the concatenation operator. sinside parentheses are evaluated first.If there are no parentheses the expression is evaluated ef torigh d.The statement about when the computer was invented is too scrunched up.How should that be fixed? (2)Writing Your Own Program with Now write a complete Java program that prints out the following Your program must use only one statement that invokes the println method.It must use the operator both to do arithmetic and string concatenation. 4.Variables Prelab Excercises 5.Arithmetic Expressions The program is supposed to compute the lab grade for a student.To do this it gets as input the number of points the student earned on the prelab assignment and the maximum number of points the student could have earned;the number of points earned on the lab itself and the maximum number of points:the number of points earned on the postlab assignment and the maximum number of points.The lab grade is co das described above:the in-elass and out-of-class grades (in percent)are computed separately then a weighted average of these is computed.The program currently assumes the out-of-class work counts 40%and the in-class counts60%Do the following: (1)First carefully hand trace the program assuming the input stream contains the values 17,20
\\\\\\\\\\\\\\\\\\\/////////////////// Name Lab Bonus Total ---- --- ----- ----- Joe 43 7 50 William 50 8 58 Mary Sue 39 10 49 The requirements for the program are as follows: (1) Print the border on the top as illustrated (using the slash and backslash characters). (2) Use tab characters to get your columns aligned and you must use the + operator both for addition and string concatenation. (3) Make up your own student names and points—the ones shown are just for illustration purposes. You need 5 names. 3. Escape sequences (1) Observing the Behavior of + To see the behavior of + in different settings do the following: a. Study the program below, which is in file PlusTest.java. b. Save PlusTest.java to your directory. c. Compile and run the program. For each of the last three output statements (the ones dealing with 8 plus 5) write down what was printed. Now for each explain why the computer printed what it did given that the following rules are used for +. Write out complete explanations. If both operands are numbers + is treated as ordinary addition. (NOTE: in the expression a + b the a and b are called the operands.) If at least one operand is a string the other operand is converted to a string and + is the concatenation operator. If an expression contains more than one operation expressions inside parentheses are evaluated first. If there are no parentheses the expression is evaluated left to right. d. The statement about when the computer was invented is too scrunched up. How should that be fixed? (2) Writing Your Own Program With + Now write a complete Java program that prints out the following sentence: Ten robins plus 13 canaries is 23 birds. Your program must use only one statement that invokes the println method. It must use the + operator both to do arithmetic and string concatenation. 4. Variables Prelab Excercises 5. Arithmetic Expressions The program LabGrade.java is supposed to compute the lab grade for a student. To do this it gets as input the number of points the student earned on the prelab assignment and the maximum number of points the student could have earned; the number of points earned on the lab itself and the maximum number of points; the number of points earned on the postlab assignment and the maximum number of points. The lab grade is computed as described above: the in-class and out-of-class grades (in percent) are computed separately then a weighted average of these is computed. The program currently assumes the out-of-class work counts 40% and the in-class counts 60%. Do the following: (1) First carefully hand trace the program assuming the input stream contains the values 17, 20