Cmis 212 module 2 assignment


Published on

  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Cmis 212 module 2 assignment

  1. 1. The link to downloadCMIS 212 Module 2 AssignmentPart 1:1. "Java How to Program" textbook (JHtP) Ex3.52. Ex3.11.4. Ex3.13.Hints for Ex3.11:a). After you declare the second String instance variable, you need to modifyyour constructor to://Constructor:public GradeBook( String course, String instructor ){setCourse(course);setInstructor(instructor);} // end constructorb). Note that there is NO main( ) method in TheGradeBookTest.jva on Pages 89 - 90 DOES have main( ) method. On line 11(and 13 as well) of program on Page 90, you create anobject of GradeBook. Every time, you run a Java program, it looks for themain( ) method first, in other words, you must have a main() method in theprogram you want to run. As you create an object of the GradeBook programyou modified in Ex3.11 a-d, you use the newly changed GradeBook. If you tryto run a program without a main() method, you will get "main method notfound" error.c). Now, since you have TWO arguments in the GradeBook constructor, whenyou create a new object of GradeBook in the GradeBookTest program, youneed 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 surethe values you pass over match with the data type you have in the GradeBookconstructor.d). For Ex3.11, after you make changes instructed in a-d on p.104, to compilethe programs:javac GradeBookTest.javaTo run the program:java GradeBookTest
  2. 2. Hints for Ex3.13: // Note: this one does NOT have main() method// Later, you will create to instantiate Invoice objects// Invoice class: Invoice.javapublic class Invoice{private String partNumber;private String partDescription;private int quantity;private double pricePerItem;// four-argument constructorpublic Invoice( String part, String description, int count, double price ){;;if ( count > 0 ) // determine whether count is positive; // valid count assigned to quantityif ( 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 Ask yourself, whats the purpose of a Test program?//Q2: Why do we have and Why not combiningthem 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 invoice1System.out.println( "Original invoice information" );System.out.printf( "Part number: %sn", invoice1.getPartNumber() );
  3. 3. //I will let you finish the rest of the program to display more information ofinvoice1:Part 2:"Java How to Program" textbook (JHtP) Ch4:1. Ex4.13 In addition to answer the question of "What type of repetition wouldbe appropriate for calculating the sum of the first 100 positive integers?", alsowrite down your loop statement to calculate the sum of the first 100 positiveintegers, that is to get total which is sum of 1 + 2 + 3 + ... + 100.2. Ex4.153. Ex4.17Hints for Ex4.17:1. You will have two files:a) andb) The is very simple:public class GasTest{public static void main( String args[] ){Gas Gas();application.calculateMPG();} // end method main} // end class GasTest2. In file, obviously you will need a method called calculateMPG,which will ask the user to input miles driven and gallons used as many timesas 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( );int miles; // miles for one tankfulint gallons; // gallons for one tankfulint ; // total mailes for tripint ; // total gallons for tripdouble milesPerGallon; // miles per gallon for tankfuldouble totalMilesPerGallon; // miles per gallon for trip...
  4. 4. // exit if the input is -1; otherwise, proceed with the programwhile ( miles != -1 ){// prompt user for gallons and obtain the input from userSystem.out.print( "Enter gallons: " );();...// add gallons and miles for this tank to totals:...// calculate miles per gallon for the current tankif ( gallons != 0 ){ milesPerGallon = (double) miles / gallons;System.out.printf( "MPG this tankful: ....} // end if statement// calculate miles per gallon for the total tripif ( 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.44.x 13Part 4:Top of Form
  5. 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}