{"id":3689,"date":"2022-04-22T21:30:39","date_gmt":"2022-04-22T21:30:39","guid":{"rendered":"https:\/\/highclasswriters.com\/blog\/?p=3689"},"modified":"2022-04-22T21:30:41","modified_gmt":"2022-04-22T21:30:41","slug":"monetary-coin","status":"publish","type":"post","link":"https:\/\/highclasswriters.com\/blog\/monetary-coin\/","title":{"rendered":"monetary coin"},"content":{"rendered":"\n<p><strong>9.1: MonetaryCoin<\/strong><br>Design and implement a&nbsp;class&nbsp;called&nbsp;MonetaryCoin&nbsp; that is derived from the&nbsp;Coin&nbsp;&nbsp;class&nbsp;.&nbsp;Store&nbsp;an&nbsp;integer&nbsp;in the&nbsp;MonetaryCoin&nbsp; that represents its&nbsp;value&nbsp;and add a&nbsp;method&nbsp;that returns its&nbsp;value. Add a&nbsp;toString&nbsp;&nbsp;method&nbsp;that appends a space followed by the coin&#8217;s&nbsp;value&nbsp;to the&nbsp;Coin&#8217;s&nbsp;&nbsp;String&nbsp;representation.<\/p>\n\n\n\n<p><strong>Driver<\/strong>. Instead of creating a main driver&nbsp;class, include a&nbsp;main method&nbsp;in the&nbsp;MonetaryCoin&nbsp;&nbsp;class&nbsp;itself to exercise the&nbsp;class&#8217;s&nbsp;behavior. Your&nbsp;method&nbsp;should create an&nbsp;array&nbsp;of 7&nbsp;MonetaryCoin&nbsp;&nbsp;objects&nbsp;with&nbsp;values&nbsp;1,5,10,25,50,100,100 and then&nbsp;iterate&nbsp;through the&nbsp;array, flipping in each coin. The&nbsp;method&nbsp;should then&nbsp;iterate&nbsp;through the&nbsp;array&nbsp;again, invoking the&nbsp;getValue&nbsp;&nbsp;method&nbsp;and adding up the resulting&nbsp;values. The&nbsp;String&nbsp;representation of each coin should then be printed on a line by itself, followed by, on a line by itself, the&nbsp;sum&nbsp;of the&nbsp;values&nbsp;that was computed (preceded by the label &#8220;Total&nbsp;Value: &#8220;.<\/p>\n\n\n\n<p><strong>THIS IS FOR MYPROGRAMMINGLAP<\/strong><\/p>\n\n\n\n<p><strong>\/\/********************************************************************<\/strong><\/p>\n\n\n\n<p><strong>\/\/&nbsp; Coin.java&nbsp; &nbsp; &nbsp; &nbsp;Author: Lewis\/Loftus<\/strong><\/p>\n\n\n\n<p><strong>\/\/<\/strong><\/p>\n\n\n\n<p><strong>\/\/&nbsp; Represents a coin with two sides that can be flipped.<\/strong><\/p>\n\n\n\n<p><strong>\/\/********************************************************************<\/strong><\/p>\n\n\n\n<p><strong>public class Coin<\/strong><\/p>\n\n\n\n<p><strong>{<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; private final int HEADS = 0;<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; private final int TAILS = 1;<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; private int face;<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; \/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; \/\/&nbsp; Sets up the coin by flipping it initially.<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; \/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; public Coin()<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; {<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; &nbsp; &nbsp; flip();<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; }<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; \/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; \/\/&nbsp; Flips the coin by randomly choosing a face value.<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; \/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; public void flip()<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; {<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; &nbsp; &nbsp; face = (int) (Math.random() * 2);<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; }<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; \/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; \/\/&nbsp; Returns true if the current face of the coin is heads.<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; \/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; public boolean isHeads()<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; {<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; &nbsp; &nbsp; return (face == HEADS);<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; }<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; \/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; \/\/&nbsp; Returns the current face of the coin as a string.<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; \/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; public String toString()<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; {<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; &nbsp; &nbsp; String faceName;<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; &nbsp; &nbsp; if (face == HEADS)<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faceName = &#8220;Heads&#8221;;<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; &nbsp; &nbsp; else<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faceName = &#8220;Tails&#8221;;<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; &nbsp; &nbsp; return faceName;<\/strong><\/p>\n\n\n\n<p><strong>&nbsp; &nbsp; }<\/strong><\/p>\n\n\n\n<p><strong>}<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>9.1: MonetaryCoinDesign and implement a&nbsp;class&nbsp;called&nbsp;MonetaryCoin&nbsp; that is derived from the&nbsp;Coin&nbsp;&nbsp;class&nbsp;.&nbsp;Store&nbsp;an&nbsp;integer&nbsp;in the&nbsp;MonetaryCoin&nbsp; that represents its&nbsp;value&nbsp;and add a&nbsp;method&nbsp;that returns its&nbsp;value. Add a&nbsp;toString&nbsp;&nbsp;method&nbsp;that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3689","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>monetary coin - Highclasswriters<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/highclasswriters.com\/blog\/monetary-coin\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"monetary coin - Highclasswriters\" \/>\n<meta property=\"og:description\" content=\"9.1: MonetaryCoinDesign and implement a&nbsp;class&nbsp;called&nbsp;MonetaryCoin&nbsp; that is derived from the&nbsp;Coin&nbsp;&nbsp;class&nbsp;.&nbsp;Store&nbsp;an&nbsp;integer&nbsp;in the&nbsp;MonetaryCoin&nbsp; that represents its&nbsp;value&nbsp;and add a&nbsp;method&nbsp;that returns its&nbsp;value. Add a&nbsp;toString&nbsp;&nbsp;method&nbsp;that [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/highclasswriters.com\/blog\/monetary-coin\/\" \/>\n<meta property=\"og:site_name\" content=\"Highclasswriters\" \/>\n<meta property=\"article:published_time\" content=\"2022-04-22T21:30:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-22T21:30:41+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/highclasswriters.com\/blog\/monetary-coin\/\",\"url\":\"https:\/\/highclasswriters.com\/blog\/monetary-coin\/\",\"name\":\"monetary coin - Highclasswriters\",\"isPartOf\":{\"@id\":\"https:\/\/highclasswriters.com\/blog\/#website\"},\"datePublished\":\"2022-04-22T21:30:39+00:00\",\"dateModified\":\"2022-04-22T21:30:41+00:00\",\"author\":{\"@id\":\"https:\/\/highclasswriters.com\/blog\/#\/schema\/person\/06412d8249aafcb0c75ea9958c98aaae\"},\"breadcrumb\":{\"@id\":\"https:\/\/highclasswriters.com\/blog\/monetary-coin\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/highclasswriters.com\/blog\/monetary-coin\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/highclasswriters.com\/blog\/monetary-coin\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/highclasswriters.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"monetary coin\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/highclasswriters.com\/blog\/#website\",\"url\":\"https:\/\/highclasswriters.com\/blog\/\",\"name\":\"Highclasswriters\",\"description\":\"Essay Writing Service\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/highclasswriters.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/highclasswriters.com\/blog\/#\/schema\/person\/06412d8249aafcb0c75ea9958c98aaae\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/highclasswriters.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/99ccb26aea1053c4c33c76cde1eee45f1ec58485d03e72c412d111c386e42174?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/99ccb26aea1053c4c33c76cde1eee45f1ec58485d03e72c412d111c386e42174?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"https:\/\/highclasswriters.com\/blog\"],\"url\":\"https:\/\/highclasswriters.com\/blog\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"monetary coin - Highclasswriters","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/highclasswriters.com\/blog\/monetary-coin\/","og_locale":"en_US","og_type":"article","og_title":"monetary coin - Highclasswriters","og_description":"9.1: MonetaryCoinDesign and implement a&nbsp;class&nbsp;called&nbsp;MonetaryCoin&nbsp; that is derived from the&nbsp;Coin&nbsp;&nbsp;class&nbsp;.&nbsp;Store&nbsp;an&nbsp;integer&nbsp;in the&nbsp;MonetaryCoin&nbsp; that represents its&nbsp;value&nbsp;and add a&nbsp;method&nbsp;that returns its&nbsp;value. Add a&nbsp;toString&nbsp;&nbsp;method&nbsp;that [&hellip;]","og_url":"https:\/\/highclasswriters.com\/blog\/monetary-coin\/","og_site_name":"Highclasswriters","article_published_time":"2022-04-22T21:30:39+00:00","article_modified_time":"2022-04-22T21:30:41+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/highclasswriters.com\/blog\/monetary-coin\/","url":"https:\/\/highclasswriters.com\/blog\/monetary-coin\/","name":"monetary coin - Highclasswriters","isPartOf":{"@id":"https:\/\/highclasswriters.com\/blog\/#website"},"datePublished":"2022-04-22T21:30:39+00:00","dateModified":"2022-04-22T21:30:41+00:00","author":{"@id":"https:\/\/highclasswriters.com\/blog\/#\/schema\/person\/06412d8249aafcb0c75ea9958c98aaae"},"breadcrumb":{"@id":"https:\/\/highclasswriters.com\/blog\/monetary-coin\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/highclasswriters.com\/blog\/monetary-coin\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/highclasswriters.com\/blog\/monetary-coin\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/highclasswriters.com\/blog\/"},{"@type":"ListItem","position":2,"name":"monetary coin"}]},{"@type":"WebSite","@id":"https:\/\/highclasswriters.com\/blog\/#website","url":"https:\/\/highclasswriters.com\/blog\/","name":"Highclasswriters","description":"Essay Writing Service","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/highclasswriters.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/highclasswriters.com\/blog\/#\/schema\/person\/06412d8249aafcb0c75ea9958c98aaae","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/highclasswriters.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/99ccb26aea1053c4c33c76cde1eee45f1ec58485d03e72c412d111c386e42174?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/99ccb26aea1053c4c33c76cde1eee45f1ec58485d03e72c412d111c386e42174?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/highclasswriters.com\/blog"],"url":"https:\/\/highclasswriters.com\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/highclasswriters.com\/blog\/wp-json\/wp\/v2\/posts\/3689","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/highclasswriters.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/highclasswriters.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/highclasswriters.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/highclasswriters.com\/blog\/wp-json\/wp\/v2\/comments?post=3689"}],"version-history":[{"count":1,"href":"https:\/\/highclasswriters.com\/blog\/wp-json\/wp\/v2\/posts\/3689\/revisions"}],"predecessor-version":[{"id":3690,"href":"https:\/\/highclasswriters.com\/blog\/wp-json\/wp\/v2\/posts\/3689\/revisions\/3690"}],"wp:attachment":[{"href":"https:\/\/highclasswriters.com\/blog\/wp-json\/wp\/v2\/media?parent=3689"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/highclasswriters.com\/blog\/wp-json\/wp\/v2\/categories?post=3689"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/highclasswriters.com\/blog\/wp-json\/wp\/v2\/tags?post=3689"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}