Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Code-NEED ALL DONE TOGETHER- Everything you need is below with question and Base Code. Need done ASAP 0) Make a directory called comp1406t3. Download

Java Code-NEED ALL DONE TOGETHER- Everything you need is below with question and Base Code. Need done ASAP image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
0) Make a directory called comp1406t3. Download all the tutorial 3 fles to this directly. 1) Modify the Money class that is provided. This is a simple class that stores money as dollars and cents. For example, $12.73 will be stored as 12 dollars and 73 cents. The cents value stored should never be greater than 99, so 3 dollars and 164 cents should actually be stored as 4 dollars and 64 cents. The class has only one method tostringO. which retuns a String representation of the money object hod. tostringO. which retuns a String representation of the money object. Your first task is to create four constructors for the class as follows public MoneyOI...) // create an object with zero dollars and cents. public Money (int c)i...) // create an object with c cents // (adjusting dollars and cents so that 03 centss-99) public Money (int d, int c)(...) / create an object with d dollars and c cents // (adjusting dollars and cents so that Oc centac-99) pubic Money (intIl coins)t.. #loonies, #quarters, ldines, #nickels, 'pennies) litoonies, 1S2, $1, $0.25, $0.10, $0.05, $0.01) // // create an object with total money passed in array // (adjusting internal dollar and cents so that 0 100) Be sure to test your methods. Pay special attention to the remove method. As with the constructors, the intention is that your internal representation of the money wil satisty the condition o cs cents c 99 t ll imes Adjust your More Reading 2) An enum (enumeration) type is a special Java class to hold constants. By convention, constants in Java are always in FULL CAPS Essentially, objects of the enum class are each of the possible constants Seethe Month java enum type provided. We can use this Month enum when need to use months Java provides some pre-built methods in every enum class. These include toStringO will return a string representation of the constant values0 will return an array containing all possible constants (in the order that they appear in the enum definition valueOf(String) will return the enum object corresponding to the input string (if possible). Run the UseMonthEnumType program to see how these methods used Add a static method to the UseMonthEnumType program. The method should look like public static int days (Month month) The method will have a "switch " statement that will determine the number of days in the provided (input) month will then retun this number. Don't worry about leap years (fLe, FEBRUARY wil always have 28 days). More Reading 3) In this problem, you will use Javadoc in the Find class. You'll notice that the comments might look slightly different than normal Java comments. The commenting used is in the Javadoc format. What is Javadoc? From wiki, we see Javad is a documentation generator om Oracle Corporation or generating API documentation in HTML om at fr n Java source code. The HTML format is used to add the convenience of being able to hyperlink related documents together An API is the application programming interface. This is the interface between the writers of the code (classes) and the users of the code. In order to generate the html code for the APL we will use the javadoc program from the command line (using cmd or terminal), In the directory where you compile and rnu your code for this tutorial, type Windows Users javadoe -d comp1406t3%docs eomp1406e3\Find.java -author -version OS X or Linux Users javadoc id cop1406t3/docs comp: 4063Find.dava Hauthor rversion This will create a new directory called docs in your comp1406t3 directory. Inside this new directory, is the html code for the API for the Find class. In the windows file viewer, click on the index.html ile. This will open the file in a web browser. Click on the Find class (left pane) and see the API for the Find class What happened? -d comp1406t3ndocs specifies where to put the htmil files comp1406t3 Find javo specified which file to generate javadocs for (use "java for alljava files) author-version specity to list the author and version (if speoified in the java files). How do you write javadoc comments? In your code, you can add a special comment block just before a class attribute, method or constructor declaration. This block of comments will be used in the generated APt to describe whatever it is that the comment blocks comes before. There are some special tags that the Javadoc tool will read and use in this comment block. Here some simple rules The comment block must start with / (two stars instead of 1) and end with . For methods, each input argument should have an associated Oparam tag describing that input (We can add pre-conditions on the argument here ) . For non-void methods, the @return tag is used to describe the output (and any post-conditions) . You can use basic HTML tags to help format the text. For example, main will format main in code format. Use "p> to start a new paragraph (with a blank line). . The @author tag will list the author of the class or method Now, go back and add javadoc commenting to your Money class. More Reading tation/index-137868 html https//www.codeproject.com/Articles 658382/Basic-Javados quide UseMonthEnumType.java) Money javaxTostMoney java x UseM ApthEnum Typejava x javaMonth javax ject SDK is not defined package comp1406t3; public class UseMonthEnumTypef public static void main(String[1 args)f // a Month object Month current Month. JANUARY // all enum objects have a pre-defined toString() method System.out.printIn("the current month is"current.toString)): // the values() method returns an array of all constants (objects) /1 in the order that they appear in the enum declaration/definition for (Month m: Month.values()) System.out.print1n(m.toString()) /I the yalueof(String) method returns the enum object corresponding to the // input string (if it exists) current Month. valueof("OCTOBER); System.out.print In("the new current month is "current.toString(); // try uncommenting this code to see what happens when you compile //current Month.valueOf("September"); //System.out.println("the new current month is "+current.toString(O); 140613)Money java Money java TestMoney java Project SDK is not defined 1 package comp 40613 A class to modet currency (noney) as dollars and cents a/ a 4 hey.jav public class / attributes / private int dollars -1 private int cents -1 es 1e 12 14 public Money) 15 // create an object with zero dotlars and cents. 17 public Money (int c) // create an object with c cents r (adjusting dollars and cents so that 0oacentsc-99) public Money(int d, iat ct Il create an object with d doltars and c cents // (adjusting dottars and cents so that Roscents99) 26 public Money(int!l coins) / input array has 6 elesents and corresponds to // (#toones, iloonies, tquarters, adises, anickels, apennies) 152, 2, $0.25, se.1, se.es, se.0) 32 // create an object with total noney passed in array // (adjusting internal dotlars and cents so that eieacents99) * Returns a String representation of the value of the current object. 39 greturn The value of the current object is returned as the scode-Strings/ code$o.cc e where D is the number of dollars and cc is the cents of the value. Uses the ccodes format()e method from the scode-Stringe/ codes class to ensure that the cents are displayed properly (2 spaces - with leading zeros if needed) public string tostringl) (return+String-format("voa", dollars) String.format( 02, cents): y Month.java) 1 Find java- Month.java x Lail Money.java ,x roject SDK is not defined TestMoney.java :c Usel package comp1406t3; * An enumeration of constants to represent months in the Gregorian calendar * eauthor jason hinek * @version 1.0 public enum Month JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER; Find java) Project SDK is not defined package comp1406t3: /Tutorial 3- Winter 2019 * This is the skeleton provided for Assignment 1. * sp> * In the provided Find. java file, complete the locateSequence method. s For a given target sequence (non-empty array of integers), the method * searches the input array (of integers) to find an occurrence of the * target sequence if it is present. If the sequence is present, the * method returns the array index position of where it starts in the array * If the sequence is not present, the method returns -1. Bauthor Jason Hinek * eversion 1.0 public class Find4 /ss Finds the last occurrence of the sequence in the array or indicates that * the sequence is not present. . * Gparam sequence is an array of one or more integers. It is the target sequence we are looking for. * Sparan array is an array integers. * ereturn the starting position of the last occurrence of the target sequence in the array if it exists. Returns-1 othenwise. public static int locateSequence(intl sequence, intll array) [ return -3: ) 3) TestMoney java Find java Month java Money java xTestMoney java x Project SDK is not defined package comp1486t3 /s basic tester for Money class 5 public class TestMoneyf public static void main(Stringl) args) Money money String actual, expected; 10 Money() test 12 13 14" 15 16 17 18 System.out.print(" money new Money); actual = money. toString(); expected "$0.00". Systen.out.print("expected ifl actual.equals(expected) expectedactual output + ac System.out.print n(" pass"); elset 2 Sys en.out.printint- faitl-):. I 21 System.out.print ("Money(int, int) test:" money new Money(e,e); actual = money. toString(); expected "$0.00"; System.out.print ("expected expectedactual output if( actual.equals(expected) 23 24 25 actual System.out.print In(" pass) 29 elset System.out.print In(" fail"): System.out.print("Money(int, int) test: money - new Money(12,7); actual- money.toString): expected$12.07 System.out.print("expected \"" +expectedactual output ""actual f( actual.equals(expected) ){ 34 ) System.out.print In(" pass") elsef 40 System.out.print ln(" fail") System.out.print("Honey(int, int) test money new Money(3,4823): actual money.toString) expected =-$43.23"; System.out.print( expected + expected iff actual.equals(expected) 48 actual output +actual ") 0) Make a directory called comp1406t3. Download all the tutorial 3 fles to this directly. 1) Modify the Money class that is provided. This is a simple class that stores money as dollars and cents. For example, $12.73 will be stored as 12 dollars and 73 cents. The cents value stored should never be greater than 99, so 3 dollars and 164 cents should actually be stored as 4 dollars and 64 cents. The class has only one method tostringO. which retuns a String representation of the money object hod. tostringO. which retuns a String representation of the money object. Your first task is to create four constructors for the class as follows public MoneyOI...) // create an object with zero dollars and cents. public Money (int c)i...) // create an object with c cents // (adjusting dollars and cents so that 03 centss-99) public Money (int d, int c)(...) / create an object with d dollars and c cents // (adjusting dollars and cents so that Oc centac-99) pubic Money (intIl coins)t.. #loonies, #quarters, ldines, #nickels, 'pennies) litoonies, 1S2, $1, $0.25, $0.10, $0.05, $0.01) // // create an object with total money passed in array // (adjusting internal dollar and cents so that 0 100) Be sure to test your methods. Pay special attention to the remove method. As with the constructors, the intention is that your internal representation of the money wil satisty the condition o cs cents c 99 t ll imes Adjust your More Reading 2) An enum (enumeration) type is a special Java class to hold constants. By convention, constants in Java are always in FULL CAPS Essentially, objects of the enum class are each of the possible constants Seethe Month java enum type provided. We can use this Month enum when need to use months Java provides some pre-built methods in every enum class. These include toStringO will return a string representation of the constant values0 will return an array containing all possible constants (in the order that they appear in the enum definition valueOf(String) will return the enum object corresponding to the input string (if possible). Run the UseMonthEnumType program to see how these methods used Add a static method to the UseMonthEnumType program. The method should look like public static int days (Month month) The method will have a "switch " statement that will determine the number of days in the provided (input) month will then retun this number. Don't worry about leap years (fLe, FEBRUARY wil always have 28 days). More Reading 3) In this problem, you will use Javadoc in the Find class. You'll notice that the comments might look slightly different than normal Java comments. The commenting used is in the Javadoc format. What is Javadoc? From wiki, we see Javad is a documentation generator om Oracle Corporation or generating API documentation in HTML om at fr n Java source code. The HTML format is used to add the convenience of being able to hyperlink related documents together An API is the application programming interface. This is the interface between the writers of the code (classes) and the users of the code. In order to generate the html code for the APL we will use the javadoc program from the command line (using cmd or terminal), In the directory where you compile and rnu your code for this tutorial, type Windows Users javadoe -d comp1406t3%docs eomp1406e3\Find.java -author -version OS X or Linux Users javadoc id cop1406t3/docs comp: 4063Find.dava Hauthor rversion This will create a new directory called docs in your comp1406t3 directory. Inside this new directory, is the html code for the API for the Find class. In the windows file viewer, click on the index.html ile. This will open the file in a web browser. Click on the Find class (left pane) and see the API for the Find class What happened? -d comp1406t3ndocs specifies where to put the htmil files comp1406t3 Find javo specified which file to generate javadocs for (use "java for alljava files) author-version specity to list the author and version (if speoified in the java files). How do you write javadoc comments? In your code, you can add a special comment block just before a class attribute, method or constructor declaration. This block of comments will be used in the generated APt to describe whatever it is that the comment blocks comes before. There are some special tags that the Javadoc tool will read and use in this comment block. Here some simple rules The comment block must start with / (two stars instead of 1) and end with . For methods, each input argument should have an associated Oparam tag describing that input (We can add pre-conditions on the argument here ) . For non-void methods, the @return tag is used to describe the output (and any post-conditions) . You can use basic HTML tags to help format the text. For example, main will format main in code format. Use "p> to start a new paragraph (with a blank line). . The @author tag will list the author of the class or method Now, go back and add javadoc commenting to your Money class. More Reading tation/index-137868 html https//www.codeproject.com/Articles 658382/Basic-Javados quide UseMonthEnumType.java) Money javaxTostMoney java x UseM ApthEnum Typejava x javaMonth javax ject SDK is not defined package comp1406t3; public class UseMonthEnumTypef public static void main(String[1 args)f // a Month object Month current Month. JANUARY // all enum objects have a pre-defined toString() method System.out.printIn("the current month is"current.toString)): // the values() method returns an array of all constants (objects) /1 in the order that they appear in the enum declaration/definition for (Month m: Month.values()) System.out.print1n(m.toString()) /I the yalueof(String) method returns the enum object corresponding to the // input string (if it exists) current Month. valueof("OCTOBER); System.out.print In("the new current month is "current.toString(); // try uncommenting this code to see what happens when you compile //current Month.valueOf("September"); //System.out.println("the new current month is "+current.toString(O); 140613)Money java Money java TestMoney java Project SDK is not defined 1 package comp 40613 A class to modet currency (noney) as dollars and cents a/ a 4 hey.jav public class / attributes / private int dollars -1 private int cents -1 es 1e 12 14 public Money) 15 // create an object with zero dotlars and cents. 17 public Money (int c) // create an object with c cents r (adjusting dollars and cents so that 0oacentsc-99) public Money(int d, iat ct Il create an object with d doltars and c cents // (adjusting dottars and cents so that Roscents99) 26 public Money(int!l coins) / input array has 6 elesents and corresponds to // (#toones, iloonies, tquarters, adises, anickels, apennies) 152, 2, $0.25, se.1, se.es, se.0) 32 // create an object with total noney passed in array // (adjusting internal dotlars and cents so that eieacents99) * Returns a String representation of the value of the current object. 39 greturn The value of the current object is returned as the scode-Strings/ code$o.cc e where D is the number of dollars and cc is the cents of the value. Uses the ccodes format()e method from the scode-Stringe/ codes class to ensure that the cents are displayed properly (2 spaces - with leading zeros if needed) public string tostringl) (return+String-format("voa", dollars) String.format( 02, cents): y Month.java) 1 Find java- Month.java x Lail Money.java ,x roject SDK is not defined TestMoney.java :c Usel package comp1406t3; * An enumeration of constants to represent months in the Gregorian calendar * eauthor jason hinek * @version 1.0 public enum Month JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER; Find java) Project SDK is not defined package comp1406t3: /Tutorial 3- Winter 2019 * This is the skeleton provided for Assignment 1. * sp> * In the provided Find. java file, complete the locateSequence method. s For a given target sequence (non-empty array of integers), the method * searches the input array (of integers) to find an occurrence of the * target sequence if it is present. If the sequence is present, the * method returns the array index position of where it starts in the array * If the sequence is not present, the method returns -1. Bauthor Jason Hinek * eversion 1.0 public class Find4 /ss Finds the last occurrence of the sequence in the array or indicates that * the sequence is not present. . * Gparam sequence is an array of one or more integers. It is the target sequence we are looking for. * Sparan array is an array integers. * ereturn the starting position of the last occurrence of the target sequence in the array if it exists. Returns-1 othenwise. public static int locateSequence(intl sequence, intll array) [ return -3: ) 3) TestMoney java Find java Month java Money java xTestMoney java x Project SDK is not defined package comp1486t3 /s basic tester for Money class 5 public class TestMoneyf public static void main(Stringl) args) Money money String actual, expected; 10 Money() test 12 13 14" 15 16 17 18 System.out.print(" money new Money); actual = money. toString(); expected "$0.00". Systen.out.print("expected ifl actual.equals(expected) expectedactual output + ac System.out.print n(" pass"); elset 2 Sys en.out.printint- faitl-):. I 21 System.out.print ("Money(int, int) test:" money new Money(e,e); actual = money. toString(); expected "$0.00"; System.out.print ("expected expectedactual output if( actual.equals(expected) 23 24 25 actual System.out.print In(" pass) 29 elset System.out.print In(" fail"): System.out.print("Money(int, int) test: money - new Money(12,7); actual- money.toString): expected$12.07 System.out.print("expected \"" +expectedactual output ""actual f( actual.equals(expected) ){ 34 ) System.out.print In(" pass") elsef 40 System.out.print ln(" fail") System.out.print("Honey(int, int) test money new Money(3,4823): actual money.toString) expected =-$43.23"; System.out.print( expected + expected iff actual.equals(expected) 48 actual output +actual ")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions