SlideShare une entreprise Scribd logo
1  sur  5
The link to download
CMIS 212 Module 2 Assignment
Part 1:
1. "Java How to Program" textbook (JHtP) Ex3.5
2. Ex3.11.
4. Ex3.13.
Hints for Ex3.11:
a). After you declare the second String instance variable, you need to modify
your constructor to:
//Constructor:
public GradeBook( String course, String instructor )
{
setCourse(course);
setInstructor(instructor);
} // end constructor

b). Note that there is NO main( ) method in GradeBook.java. The
GradeBookTest.jva on Pages 89 - 90 DOES have main( ) method. On line 11
(and 13 as well) of GradeBookTest.java program on Page 90, you create an
object of GradeBook. Every time, you run a Java program, it looks for the
main( ) method first, in other words, you must have a main() method in the
program you want to run. As you create an object of the GradeBook program
you modified in Ex3.11 a-d, you use the newly changed GradeBook. If you try
to run a program without a main() method, you will get "main method not
found" error.

c). Now, since you have TWO arguments in the GradeBook constructor, when
you create a new object of GradeBook in the GradeBookTest program, you
need to pass TWO values over, for example:
GradeBookGradeBook("BIBL 105", "Sam Smith" );
If you just pass one or 3 values over, you will get an error. Alos, make sure
the values you pass over match with the data type you have in the GradeBook
constructor.

d). For Ex3.11, after you make changes instructed in a-d on p.104, to compile
the programs:
javac GradeBook.java GradeBookTest.java

To run the program:
java GradeBookTest
Hints for Ex3.13: // Note: this one does NOT have main() method
// Later, you will create InvoiceTest.java to instantiate Invoice objects
// Invoice class: Invoice.java

public class Invoice
{
private String partNumber;
private String partDescription;
private int quantity;
private double pricePerItem;
// four-argument constructor
public Invoice( String part, String description, int count, double price )
{
;
;

if ( count > 0 ) // determine whether count is positive
; // valid count assigned to quantity

if ( price > 0.0 ) // I will let you finish the rest:
...
} // end four-argument Invoice constructor

// set part number:
public void setPartNumber( String part )
{
; //accept the passed part value and assign it to instance variable partNumber
} // end method setPartNumber
//You will finish the other set and get methods:
...
Hints for InvoiceTest.java:
//Q1: Ask yourself, what's the purpose of a Test program?
//Q2: Why do we have Invoice.java and InvoiceTest.java? Why not combining
them in one? Think from object-oriented programming point of view.
public class InvoiceTest
{
public static void main( String args[] )
{ //create an instance of Invoice passing 4 argument values here.
//Question1: Do you have 4 arguments in the Invoice constructor?
//Question2: What would happen if you just pass 3 values here?
Invoice Invoice( "1234", "Hammer", 2, 14.95 );

// display invoice1
System.out.println( "Original invoice information" );
System.out.printf( "Part number: %sn", invoice1.getPartNumber() );
//I will let you finish the rest of the program to display more information of
invoice1:



Part 2:

"Java How to Program" textbook (JHtP) Ch4:

1. Ex4.13 In addition to answer the question of "What type of repetition would
be appropriate for calculating the sum of the first 100 positive integers?", also
write down your loop statement to calculate the sum of the first 100 positive
integers, that is to get total which is sum of 1 + 2 + 3 + ... + 100.

2. Ex4.15

3. Ex4.17

Hints for Ex4.17:
1. You will have two files:
a) Gas.java and
b) GasTest.java. The Gas.Test.java is very simple:
public class GasTest
{
public static void main( String args[] )
{
Gas Gas();
application.calculateMPG();
} // end method main
} // end class GasTest
2. In Gas.java file, obviously you will need a method called calculateMPG,
which will ask the user to input miles driven and gallons used as many times
as the user wants until the user does not want to enter anymore (for example,
you can tell the user to enter -1 if they want to stop entering).
public void calculateMPG()
{
Scanner Scanner( System.in );

int miles; // miles for one tankful
int gallons; // gallons for one tankful
int ; // total mailes for trip
int ; // total gallons for trip
double milesPerGallon; // miles per gallon for tankful
double totalMilesPerGallon; // miles per gallon for trip

...
// exit if the input is -1; otherwise, proceed with the program
while ( miles != -1 )
{
// prompt user for gallons and obtain the input from user
System.out.print( "Enter gallons: " );
();
...
// add gallons and miles for this tank to totals:
...

// calculate miles per gallon for the current tank
if ( gallons != 0 )
{ milesPerGallon = (double) miles / gallons;
System.out.printf( "MPG this tankful: ....
} // end if statement

// calculate miles per gallon for the total trip
if ( totalGallons != 0 )
{

...
} // end if statement

// prompt user for new value for miles:
System.out.print( "Enter miles (-1 to quit): " );
//retrieve the value and save it into miles:
...

} // end while loop
} // end method calculateMPG
//Note that this is NOT a complete program, just a hint.




Part 3:

T.4

4.x 13

Part 4:Top of Form
1. SJP Tutorial 8.
2. SJP Ex8.12 (Mortgage Calculator Application)

Hint for Ex8.12:
To increment the year by 5 in the while loop:
while ( years <= 30 )
{
// calculate payment period:
...

// getmonthlyPayment:
...

// appendresultintooutputJTextArea:
...

years += 5; // incrementcounter

}

Contenu connexe

Tendances

What is new in sulu 2.0
What is new in sulu 2.0What is new in sulu 2.0
What is new in sulu 2.0danrot
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c languagetanmaymodi4
 
What is storage class
What is storage classWhat is storage class
What is storage classIsha Aggarwal
 
Storage Class Specifiers in C++
Storage Class Specifiers in C++Storage Class Specifiers in C++
Storage Class Specifiers in C++Reddhi Basu
 
Python Training in Bangalore | Python Introduction Session | Learnbay
Python Training in Bangalore |  Python Introduction Session | LearnbayPython Training in Bangalore |  Python Introduction Session | Learnbay
Python Training in Bangalore | Python Introduction Session | LearnbayLearnbayin
 
2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_unitskinan keshkeh
 
Functional Programming in Java - Code for Maintainability
Functional Programming in Java - Code for MaintainabilityFunctional Programming in Java - Code for Maintainability
Functional Programming in Java - Code for MaintainabilityMarcin Stepien
 
Loops in c language
Loops in c languageLoops in c language
Loops in c languagetanmaymodi4
 

Tendances (16)

C++ loop
C++ loop C++ loop
C++ loop
 
C++loop statements
C++loop statementsC++loop statements
C++loop statements
 
Storage class
Storage classStorage class
Storage class
 
Csharp generics
Csharp genericsCsharp generics
Csharp generics
 
What is new in sulu 2.0
What is new in sulu 2.0What is new in sulu 2.0
What is new in sulu 2.0
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
 
What is storage class
What is storage classWhat is storage class
What is storage class
 
Storage classes in C
Storage classes in CStorage classes in C
Storage classes in C
 
Storage Class Specifiers in C++
Storage Class Specifiers in C++Storage Class Specifiers in C++
Storage Class Specifiers in C++
 
Python Training in Bangalore | Python Introduction Session | Learnbay
Python Training in Bangalore |  Python Introduction Session | LearnbayPython Training in Bangalore |  Python Introduction Session | Learnbay
Python Training in Bangalore | Python Introduction Session | Learnbay
 
Loop control in c++
Loop control in c++Loop control in c++
Loop control in c++
 
2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units
 
Functional Programming in Java - Code for Maintainability
Functional Programming in Java - Code for MaintainabilityFunctional Programming in Java - Code for Maintainability
Functional Programming in Java - Code for Maintainability
 
Loop c++
Loop c++Loop c++
Loop c++
 
C# Method overloading
C# Method overloadingC# Method overloading
C# Method overloading
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 

En vedette

Silicon Valley best 20 qoutes
Silicon Valley best 20 qoutesSilicon Valley best 20 qoutes
Silicon Valley best 20 qoutesLenny Kweku
 
ECU ODS data integration using OWB and SSIS UNC Cause 2013
ECU ODS data integration using OWB and SSIS UNC Cause 2013ECU ODS data integration using OWB and SSIS UNC Cause 2013
ECU ODS data integration using OWB and SSIS UNC Cause 2013Keith Washer
 
Silicon Valley best 20 qoutes
Silicon Valley best 20 qoutes Silicon Valley best 20 qoutes
Silicon Valley best 20 qoutes Lenny Kweku
 
VWA Company Profile November 2012
VWA Company Profile November 2012VWA Company Profile November 2012
VWA Company Profile November 2012Aliwheel
 
"Бук 3х2": таємниця втраченої цифри. Розслідування bell¿ngcat
"Бук 3х2": таємниця втраченої цифри. Розслідування bell¿ngcat"Бук 3х2": таємниця втраченої цифри. Розслідування bell¿ngcat
"Бук 3х2": таємниця втраченої цифри. Розслідування bell¿ngcatОрест Читайло
 

En vedette (15)

Presentation1
Presentation1Presentation1
Presentation1
 
Manual cpmd
Manual cpmdManual cpmd
Manual cpmd
 
Survey
SurveySurvey
Survey
 
Computer midterm
Computer midtermComputer midterm
Computer midterm
 
10 slides .-
10 slides  .-10 slides  .-
10 slides .-
 
Direct Cannes 2013
Direct Cannes 2013Direct Cannes 2013
Direct Cannes 2013
 
Honduras janae
Honduras janaeHonduras janae
Honduras janae
 
My powerpoint
My powerpointMy powerpoint
My powerpoint
 
Silicon Valley best 20 qoutes
Silicon Valley best 20 qoutesSilicon Valley best 20 qoutes
Silicon Valley best 20 qoutes
 
HondurasMalia
HondurasMaliaHondurasMalia
HondurasMalia
 
ECU ODS data integration using OWB and SSIS UNC Cause 2013
ECU ODS data integration using OWB and SSIS UNC Cause 2013ECU ODS data integration using OWB and SSIS UNC Cause 2013
ECU ODS data integration using OWB and SSIS UNC Cause 2013
 
Silicon Valley best 20 qoutes
Silicon Valley best 20 qoutes Silicon Valley best 20 qoutes
Silicon Valley best 20 qoutes
 
Davis Portfolio
Davis PortfolioDavis Portfolio
Davis Portfolio
 
VWA Company Profile November 2012
VWA Company Profile November 2012VWA Company Profile November 2012
VWA Company Profile November 2012
 
"Бук 3х2": таємниця втраченої цифри. Розслідування bell¿ngcat
"Бук 3х2": таємниця втраченої цифри. Розслідування bell¿ngcat"Бук 3х2": таємниця втраченої цифри. Розслідування bell¿ngcat
"Бук 3х2": таємниця втраченої цифри. Розслідування bell¿ngcat
 

Similaire à Cmis 212 module 2 assignment

week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docxweek3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docxalanfhall8953
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)aeden_brines
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3Dillon Lee
 
This project calls for the modification of the DollarFormat clas.pdf
This project calls for the modification of the DollarFormat clas.pdfThis project calls for the modification of the DollarFormat clas.pdf
This project calls for the modification of the DollarFormat clas.pdfjibinsh
 
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
import java.util.Scanner;Henry Cutler ID 1234  7202.docximport java.util.Scanner;Henry Cutler ID 1234  7202.docx
import java.util.Scanner;Henry Cutler ID 1234 7202.docxwilcockiris
 
Using c++Im also using a the ide editor called CodeLiteThe hea.pdf
Using c++Im also using a the ide editor called CodeLiteThe hea.pdfUsing c++Im also using a the ide editor called CodeLiteThe hea.pdf
Using c++Im also using a the ide editor called CodeLiteThe hea.pdffashiongallery1
 
Lewis jssap3 e_labman02
Lewis jssap3 e_labman02Lewis jssap3 e_labman02
Lewis jssap3 e_labman02auswhit
 
Intro to programing with java-lecture 3
Intro to programing with java-lecture 3Intro to programing with java-lecture 3
Intro to programing with java-lecture 3Mohamed Essam
 
Cs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALCs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALPrabhu D
 
Procedure to create_the_calculator_application java
Procedure to create_the_calculator_application javaProcedure to create_the_calculator_application java
Procedure to create_the_calculator_application javagthe
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...Doug Jones
 
Powerpoint presentation final requirement in fnd prg
Powerpoint presentation final requirement in fnd prgPowerpoint presentation final requirement in fnd prg
Powerpoint presentation final requirement in fnd prgalyssa-castro2326
 
Goals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docxGoals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docxjosephineboon366
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C ProgrammingShuvongkor Barman
 
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docxransayo
 

Similaire à Cmis 212 module 2 assignment (20)

week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docxweek3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3
 
This project calls for the modification of the DollarFormat clas.pdf
This project calls for the modification of the DollarFormat clas.pdfThis project calls for the modification of the DollarFormat clas.pdf
This project calls for the modification of the DollarFormat clas.pdf
 
03b loops
03b   loops03b   loops
03b loops
 
CS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUALCS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUAL
 
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
import java.util.Scanner;Henry Cutler ID 1234  7202.docximport java.util.Scanner;Henry Cutler ID 1234  7202.docx
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
 
Using c++Im also using a the ide editor called CodeLiteThe hea.pdf
Using c++Im also using a the ide editor called CodeLiteThe hea.pdfUsing c++Im also using a the ide editor called CodeLiteThe hea.pdf
Using c++Im also using a the ide editor called CodeLiteThe hea.pdf
 
J Unit
J UnitJ Unit
J Unit
 
Lewis jssap3 e_labman02
Lewis jssap3 e_labman02Lewis jssap3 e_labman02
Lewis jssap3 e_labman02
 
Intro to programing with java-lecture 3
Intro to programing with java-lecture 3Intro to programing with java-lecture 3
Intro to programing with java-lecture 3
 
Cs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALCs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUAL
 
Procedure to create_the_calculator_application java
Procedure to create_the_calculator_application javaProcedure to create_the_calculator_application java
Procedure to create_the_calculator_application java
 
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
 
Powerpoint presentation final requirement in fnd prg
Powerpoint presentation final requirement in fnd prgPowerpoint presentation final requirement in fnd prg
Powerpoint presentation final requirement in fnd prg
 
Goals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docxGoals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docx
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
 
Simple Java Programs
Simple Java ProgramsSimple Java Programs
Simple Java Programs
 

Cmis 212 module 2 assignment

  • 1. The link to download CMIS 212 Module 2 Assignment Part 1: 1. "Java How to Program" textbook (JHtP) Ex3.5 2. Ex3.11. 4. Ex3.13. Hints for Ex3.11: a). After you declare the second String instance variable, you need to modify your constructor to: //Constructor: public GradeBook( String course, String instructor ) { setCourse(course); setInstructor(instructor); } // end constructor b). Note that there is NO main( ) method in GradeBook.java. The GradeBookTest.jva on Pages 89 - 90 DOES have main( ) method. On line 11 (and 13 as well) of GradeBookTest.java program on Page 90, you create an object of GradeBook. Every time, you run a Java program, it looks for the main( ) method first, in other words, you must have a main() method in the program you want to run. As you create an object of the GradeBook program you modified in Ex3.11 a-d, you use the newly changed GradeBook. If you try to run a program without a main() method, you will get "main method not found" error. c). Now, since you have TWO arguments in the GradeBook constructor, when you create a new object of GradeBook in the GradeBookTest program, you need to pass TWO values over, for example: GradeBookGradeBook("BIBL 105", "Sam Smith" ); If you just pass one or 3 values over, you will get an error. Alos, make sure the values you pass over match with the data type you have in the GradeBook constructor. d). For Ex3.11, after you make changes instructed in a-d on p.104, to compile the programs: javac GradeBook.java GradeBookTest.java To run the program: java GradeBookTest
  • 2. Hints for Ex3.13: // Note: this one does NOT have main() method // Later, you will create InvoiceTest.java to instantiate Invoice objects // Invoice class: Invoice.java public class Invoice { private String partNumber; private String partDescription; private int quantity; private double pricePerItem; // four-argument constructor public Invoice( String part, String description, int count, double price ) { ; ; if ( count > 0 ) // determine whether count is positive ; // valid count assigned to quantity if ( price > 0.0 ) // I will let you finish the rest: ... } // end four-argument Invoice constructor // set part number: public void setPartNumber( String part ) { ; //accept the passed part value and assign it to instance variable partNumber } // end method setPartNumber //You will finish the other set and get methods: ... Hints for InvoiceTest.java: //Q1: Ask yourself, what's the purpose of a Test program? //Q2: Why do we have Invoice.java and InvoiceTest.java? Why not combining them in one? Think from object-oriented programming point of view. public class InvoiceTest { public static void main( String args[] ) { //create an instance of Invoice passing 4 argument values here. //Question1: Do you have 4 arguments in the Invoice constructor? //Question2: What would happen if you just pass 3 values here? Invoice Invoice( "1234", "Hammer", 2, 14.95 ); // display invoice1 System.out.println( "Original invoice information" ); System.out.printf( "Part number: %sn", invoice1.getPartNumber() );
  • 3. //I will let you finish the rest of the program to display more information of invoice1: Part 2: "Java How to Program" textbook (JHtP) Ch4: 1. Ex4.13 In addition to answer the question of "What type of repetition would be appropriate for calculating the sum of the first 100 positive integers?", also write down your loop statement to calculate the sum of the first 100 positive integers, that is to get total which is sum of 1 + 2 + 3 + ... + 100. 2. Ex4.15 3. Ex4.17 Hints for Ex4.17: 1. You will have two files: a) Gas.java and b) GasTest.java. The Gas.Test.java is very simple: public class GasTest { public static void main( String args[] ) { Gas Gas(); application.calculateMPG(); } // end method main } // end class GasTest 2. In Gas.java file, obviously you will need a method called calculateMPG, which will ask the user to input miles driven and gallons used as many times as the user wants until the user does not want to enter anymore (for example, you can tell the user to enter -1 if they want to stop entering). public void calculateMPG() { Scanner Scanner( System.in ); int miles; // miles for one tankful int gallons; // gallons for one tankful int ; // total mailes for trip int ; // total gallons for trip double milesPerGallon; // miles per gallon for tankful double totalMilesPerGallon; // miles per gallon for trip ...
  • 4. // exit if the input is -1; otherwise, proceed with the program while ( miles != -1 ) { // prompt user for gallons and obtain the input from user System.out.print( "Enter gallons: " ); (); ... // add gallons and miles for this tank to totals: ... // calculate miles per gallon for the current tank if ( gallons != 0 ) { milesPerGallon = (double) miles / gallons; System.out.printf( "MPG this tankful: .... } // end if statement // calculate miles per gallon for the total trip if ( totalGallons != 0 ) { ... } // end if statement // prompt user for new value for miles: System.out.print( "Enter miles (-1 to quit): " ); //retrieve the value and save it into miles: ... } // end while loop } // end method calculateMPG //Note that this is NOT a complete program, just a hint. Part 3: T.4 4.x 13 Part 4:Top of Form
  • 5. 1. SJP Tutorial 8. 2. SJP Ex8.12 (Mortgage Calculator Application) Hint for Ex8.12: To increment the year by 5 in the while loop: while ( years <= 30 ) { // calculate payment period: ... // getmonthlyPayment: ... // appendresultintooutputJTextArea: ... years += 5; // incrementcounter }