Loading...

Messages

Proposals

Stuck in your homework and missing deadline? Get urgent help in $10/Page with 24 hours deadline

Get Urgent Writing Help In Your Essays, Assignments, Homeworks, Dissertation, Thesis Or Coursework & Achieve A+ Grades.

Privacy Guaranteed - 100% Plagiarism Free Writing - Free Turnitin Report - Professional And Experienced Writers - 24/7 Online Support

005 super why the tortoise and the hare

22/10/2021 Client: muhammad11 Deadline: 2 Day

Q1. Consider a two-by-three integer array t. (14 points)

a) Write a statement that declares and creates t.

int t [] [] = new int [2] [3];

b) How many rows does t have?

It has two rows;

c) How many columns does t have?

It has three columns;

d) How many elements does t have?

It has six elements;

e) Write access expressions for all the elements in row 1 of t.

t[1] [0], t[1][1],t[1][2];

f) Write access expressions for all the elements in column 2 of t.

t[0][2],t[1][2];

g) Write a single statement that sets the element of t in row 0 and column 1 to zero.

t[0][1]=0;

h) Write individual statements to initialize each element of t to zero.

t[0][0] = 0;

t[0][1] = 0;

t[0][2] = 0;

t[1][0] = 0;

t[1][1] = 0;

t[1][2] = 0;

i) Write a nested for statement that initializes each element of t to zero.

for ( int j =0; j

for(int k = 0; k

t[j][k] = 0;

j) Write a nested for statement that inputs the values for the elements of t from the

user.

Scanner keyboard = new Scanner (System.in);

for ( int r = 0; r

for(int c = 0; c < t[r].length; c++)

t[r][c] = keyboard.nextInt();

k) Write a series of statements that determines and displays the smallest value in t.

int small = t[0] [0];

for ( int x = 0; x < t.length; x++)

for( int y = 0; y < t[x].length; y++)

{

if (t[x][y] < small)

small = t[x][y];

}

System.out.println(“Smallest Value :” + small);

l) Write a single printf statement that displays the elements of the first row of t.

System.out.printf(t[0][0] + “” + t[0][1] + “” +t[0][2]);

m) Write a statement that totals the elements of the third column of t. Do not use

repetition.

InTotal = t[0][2] + t[1][2];

n) Write a series of statements that displays the contents of t in tabular format. List

the column indices as headings across the top, and list the row indices at the left

of each row

System.out.println(“ 0 1 2 “ ) ;.

for ( int i = 0; i < t.length; i++)

{

System.out.print(i + “”);

for (int j = 0; j < t[1].length; j++)

System.out.print(t[i][j] + “”);

System.out.println();

}

Q2. (Game of Craps) Write an application that runs 1,000,000 games of craps (Fig. 6.8 of your

textbook) and answer the following questions: (10 points)

a) How many games are won on the first roll, second roll, …, twentieth roll and after

the twentieth roll?

b) How many games are lost on the first roll, second roll, …, twentieth roll and after

the twentieth roll?

c) What are the chances of winning at craps? [Note: You should discover that craps

is one of the fairest casino games. What do you suppose this means?]

d) What is the average length of a game of craps?

e) Do the chances of winning improve with the length of the game?

001

import java.util.Random;

002

003

004

public class GameOfCraps {

005

private Random randomNumbers=new Random();

006

private enum Status{Continue, Won, Lost};

007

int[] GamesWon;

008

int[] GamesLost;

009

int winTotal;

010

int loseTotal;

011

012

public void play(){

013

int totalOfDice=0;

014

int myPoints=0;

015

Status gameStatus;

016

int roll;

017

GamesWon=new int[22];

018

GamesLost=new int[22];

019

for(int x=1; x<=1000; x++){

020

totalOfDice=rollDice();

021

roll=1;

022

switch(totalOfDice){

023

case 7:

024

case 11:

025

gameStatus=Status.Won;

026

break;

027

case 2:

028

case 3:

029

case 12:

030

gameStatus=Status.Lost;

031

break;

032

default:

033

gameStatus=Status.Continue;

034

myPoints=totalOfDice;

035

break;

036

}

037

while(gameStatus==Status.Continue){

038

totalOfDice=rollDice();

039

roll++;

040

if(totalOfDice==myPoints)

041

gameStatus=Status.Won;

042

else if(totalOfDice==7)

043

gameStatus=Status.Lost;

044

}

045

if(roll>21)

046

roll=21;

047

if(gameStatus==Status.Won){

048

GamesWon[roll]++;

049

winTotal++;

050

}

051

else{

052

GamesLost[roll]++;

053

loseTotal++;

054

}

055

}

056

printStats();

057

}

058

public void printStats(){

059

int totalGames=winTotal+loseTotal;

060

int length=0;

061

int RollsToWin;

062

int RollsToLose;

063

064

for(int x=1; x<=21; x++){

065

if(x==21)

066

System.out.printf("\n%d games won and %d games lost on rolls after the 20th roll", GamesWon[21],GamesLost[21] );

067

else

068

if(x<=21)

069

System.out.printf("\n%d games won and %d games lost on roll %d", GamesWon[x], GamesLost[x], x);

070

071

RollsToWin=(1*GamesWon[1])+(2*GamesWon[2])+(3*GamesWon[3])+

072

(4*GamesWon[4])+(5*GamesWon[5])+(6*GamesWon[6])+(7*GamesWon[7])+

073

(8*GamesWon[8])+(9*GamesWon[9])+(10*GamesWon[10])+(11*GamesWon[11])+

074

(12*GamesWon[12])+(13*GamesWon[13])+(14*GamesWon[14])+(15*GamesWon[15])+

075

(16*GamesWon[16])+(17*GamesWon[17])+(18*GamesWon[18])+(19*GamesWon[19])+

076

(20*GamesWon[20])+(21*GamesWon[21]);

077

078

RollsToLose=(1*GamesLost[1])+(2*GamesLost[2])+(3*GamesLost[3])+

079

(4*GamesLost[4])+(5*GamesLost[5])+(6*GamesLost[6])+(7*GamesLost[7])+

080

(8*GamesLost[8])+(9*GamesLost[9])+(10*GamesLost[10])+(11*GamesLost[11])+

081

(12*GamesLost[12])+(13*GamesLost[13])+(14*GamesLost[14])+(15*GamesLost[15])+

082

(16*GamesLost[16])+(17*GamesLost[17])+(18*GamesLost[18])+(19*GamesLost[19])+

083

(20*GamesLost[20])+(21*GamesLost[21]);

084

085

length=(RollsToLose+loseTotal)+(RollsToWin+winTotal);

086

087

}

088

if((GamesWon[1]/GamesWon[1]+GamesLost[1])>(GamesWon[3]/GamesWon[3]+GamesLost[3])&&(GamesWon[3]/GamesWon[3]+GamesLost[3])>(GamesWon[5]/GamesWon[5]+GamesLost[5]))

089

System.out.printf("\nChances of winning decrease as rolls increase");

090

else

091

System.out.printf("\nChances of winning increase as rolls increase");

092

093

System.out.printf("\n%s %d / %d = %.2f%%\n", "The chances of winning are", winTotal, totalGames, (100.0*winTotal/totalGames));

094

System.out.printf("The average game length is %.2f rolls.\n", ((double)length/totalGames));

095

}

096

097

public int rollDice(){

098

int die1=1+randomNumbers.nextInt(6);

099

int die2=1+randomNumbers.nextInt(6);

100

int sum=die1+die2;

101

return sum;

102

}

103

public static void main(String args[]){

104

GameOfCraps game=new GameOfCraps();

105

game.play();

106

107

}

108

109

Q3. (Simulation: The Tortoise and the Hare)

import java.util.*;

public class tortouseAndHare

{public static void main(String []args)

{int finish=70,tort=1,hare=1,rtime=0;

System.out.println("ON YOUR MARK, GET SET\nBANG !!!!!\nAND THEY'RE OFF !!!!!\n");

do

{hare=movehare(hare);

tort=movetort(tort);

print(tort,hare);

rtime++;

}while(tort

if(tort>hare )

System.out.println("TORTOISE WINS!!! YAY!!!\n");

else if(tort

System.out.println("Hare wins. Yuch. \n");

else

System.out.println("Would you believe IT\'S A TIE!!\n");

System.out.println("time of race: "+rtime+" simulated seconds\n");

}

public static void print(int t,int h)

{int i;

if(h==t)

{for(i=0;i

System.out.print(" ");

System.out.println("OUCH!!!");

}

else if(h

{for(i=0;i

System.out.print(" ");

System.out.print("H");

for(i=0;i<(t-h);i++)

System.out.print(" ");

System.out.print("T");

}

else

{for(i=0;i

System.out.print(" ");

System.out.print("T");

for(i=0;i<(h-t);i++)

System.out.print(" ");

System.out.print("H");

}

System.out.println();

}

public static int movehare(int r )

{int num;

num=(int)(Math.random()*10);

if(num<2)

r-=2;

else if(num<5)

r++;

else if(num<6)

r-=12;

else if(num<8)

r+=9;

if(r< 1 )

r=1;

return r;

}

public static int movetort(int t)

{int num;

num=(int)(Math.random()*10);

if(num<5)

t+=3;

else if(num<7)

t-= 6;

else

t++;

if(t<1)

t=1;

return t;

}

}

7. Write an inheritance hierarchy for classes Quadrilateral, Trapezoid, Parallelogram,

Rectangle and Square. Use Quadrilateral as the superclass of the hierarchy. You are being

provided with a Point class, use it to represent the points in each shape. For e.g. the private

instance variables of Quadrilateral should be the x-y coordinate pairs for the four endpoints of

the Quadrilateral. Write a program that instantiates objects of your classes and outputs each

object’s area (except Quadrilateral). (10 points)

The Quadrilateral class

import java.awt.*;

public abstract class Quadrilateral

{

public Point topleft = new Point(0,0);

public Point topright = new Point(0,0);

public Point bottomleft = new Point(0,0);

public Point bottomright = new Point(0,0);

public abstract int calculateArea();

}//end of class Quadrilateral

The Rectangle class

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

import java.awt.*;

public class MyRect extends Quadrilateral

{

public MyRect()

{

super();

}//end of constructor

public MyRect(int x, int y, int width, int height)

{

//super();

topleft = new Point(x,y);

topright = new Point(x+width,y);

bottomleft = new Point(x, y+height);

bottomright = new Point(x+width, y+height);

}//end of constructor

public int calculateArea()

{

/*

* The area of a Rectangle is calculated as follows:

* (length * breadth)

*/

int area = (bottomright.x - topleft.x) * (bottomright.y - topleft.y);

return area;

}//end of method calculateArea()

}//end of class MyRect

The Square class

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

import java.awt.*;

public class Square extends Quadrilateral

{

public Square()

{

super();

}//end of constructor

public Square(int x, int y, int side)

{

super();

topleft = new Point(x,y);

topright = new Point(x+side,y);

bottomleft = new Point(x, y+side);

bottomright = new Point(x+side, y+side);

}//end of constructor

public int calculateArea()

{

/*

* The area of a Parallelogram is calculated as follows:

* (side*side)

*/

int area = (bottomright.x - topleft.x) * (bottomright.y - topleft.y);

return area;

}//end of method calculateArea()

}//end of class Square

The Paralleogram class

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

import java.awt.*;

public class Parallelogram extends Quadrilateral

{

public Parallelogram()

{

super();

}//end of constructor

public Parallelogram(int x, int y, int width, int height)

{

super();

topleft = new Point(x,y);

topright = new Point(x+width,y);

bottomleft = new Point(x, y+height);

bottomright = new Point(x+width, y+height);

}//end of constructor

public int calculateArea()

{

/*

* The area of a Parallelogram is calculated as follows:

* (base * height)

*/

int area = (bottomright.x - topleft.x) * (bottomright.y - topleft.y);

return area;

}//end of method calculateArea()

}//end of class Parallelogram

The ShapeGenerator class

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

public class ShapeGenerator

{

public static void main(String args[])

{

Quadrilateral shapes[] = {

new MyRect(0,0,10,20),

new Parallelogram(0,0,10,20),

new Square(0,0,10)

};

int area=0;

for(int i=0;i

{

area = shapes[i].calculateArea();

System.out.println("Area of " + shapes[i].getClass() + " : " + area);

}//end of for loop

}//end of method main()

}//end of class ShapeGenerator

Homework is Completed By:

Writer Writer Name Amount Client Comments & Rating
Instant Homework Helper

ONLINE

Instant Homework Helper

$36

She helped me in last minute in a very reasonable price. She is a lifesaver, I got A+ grade in my homework, I will surely hire her again for my next assignments, Thumbs Up!

Order & Get This Solution Within 3 Hours in $25/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 3 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

Order & Get This Solution Within 6 Hours in $20/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 6 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

Order & Get This Solution Within 12 Hours in $15/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 12 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

6 writers have sent their proposals to do this homework:

High Quality Assignments
Supreme Essay Writer
A+GRADE HELPER
Top Academic Guru
Top Grade Tutor
Top Academic Tutor
Writer Writer Name Offer Chat
High Quality Assignments

ONLINE

High Quality Assignments

After reading your project details, I feel myself as the best option for you to fulfill this project with 100 percent perfection.

$49 Chat With Writer
Supreme Essay Writer

ONLINE

Supreme Essay Writer

This project is my strength and I can fulfill your requirements properly within your given deadline. I always give plagiarism-free work to my clients at very competitive prices.

$15 Chat With Writer
A+GRADE HELPER

ONLINE

A+GRADE HELPER

I find your project quite stimulating and related to my profession. I can surely contribute you with your project.

$15 Chat With Writer
Top Academic Guru

ONLINE

Top Academic Guru

I find your project quite stimulating and related to my profession. I can surely contribute you with your project.

$20 Chat With Writer
Top Grade Tutor

ONLINE

Top Grade Tutor

Being a Ph.D. in the Business field, I have been doing academic writing for the past 7 years and have a good command over writing research papers, essay, dissertations and all kinds of academic writing and proofreading.

$15 Chat With Writer
Top Academic Tutor

ONLINE

Top Academic Tutor

I will provide you with the well organized and well research papers from different primary and secondary sources will write the content that will support your points.

$29 Chat With Writer

Let our expert academic writers to help you in achieving a+ grades in your homework, assignment, quiz or exam.

Similar Homework Questions

Quotes from othello about desdemona cheating - Learning disability assessment tool - Kyr 35gw x1c manual - Adela (encantar) la música de tito "el bambino". a me (interesar) la música de otros países. - Prompting is a more passive listening style than advising - Increased loneliness due to technology - Violence - Hotel assassination gta 5 sticky bomb - Forensic toxicology worksheet answers - Sales and education executive estee lauder - Lab computer science - Administration and Supervision in Criminal Justice - Chapter 5 - How are standard costs developed - You may need to modify the data set you created for the Week 1 Discussion. You will need to have two quantitative variables that - Unplugged the myth of computers in the classroom pdf - I need 300 words(1 page double spaced ) on Watch a movie. - Assignment 9/16 - Paul and donna decker are married taxpayers - What does tearfund do - Risk Challenges for below case studies - HR - Annotated Bibliography 1 - Why is eggshell a good material for edta to chelate - The dead files evil descends murrieta california - Progressive can crusher prepworks - Andrew cherlin public and private families - Feedback mechanism in animals - Module c craft of writing prescribed texts - Unlike the classical economists keynes asserted that - Discussion 07.1- Student t-Test - Frédéric chopin full name - LITERATURE - Rights and responsibilities of journalists chapter 2 - Compare and contrast the three sociological perspectives - Specific gravity formula pharmacy - The spectacular now pdf - Gyprock wall sheet sizes - Stephen hawking free will - Negative state relief hypothesis - A raisin in the sun facts - Ambulance service act 1986 - Shift in utilization from inpatient hospitalization to ambulatory care services - An increase in sensible heat causes - Managerial Accounting_Discussion4 - Profit margin for an investment center measures - HRM 652 EVALUATING RESULTS AND BENEFITS - Sheffield & district junior league - Is psychology a hard science - Chocoline hong kong - Ethical guidelines for statistical practice - Lure of the temptress walkthrough - Case synopsis----quick finish in 4 hours - Multi voting process - Donna beegle ted talk - Personality development assignment - What organelle does kartagener affect - Agar jelly diffusion experiment method - Glenlyn medical centre appointments - Katy perry brighter than the moon - Roman numerals printable pdf - What are the five major supply chain drivers - Sociology of Everyday Life - Tls ssl server supports rc4 cipher algorithms cve 2013 2566 - Air force defence guard - Analyzing a poem worksheet i wandered lonely as a cloud - 150 words - Iodination of acetone equation - Cumber claudy primary school - Java program for round robin cpu scheduling algorithm - Picnic spots in dandenong ranges - Il 31 bambus bamboo - Business statistics by ken black 9th edition - Nessus activation code offline - What makes a good salt bridge - Interactive media authoring definition - Baba deep singh ji - U pick cherries melbourne - How to set snagit as default print screen - 33 of 34 567 - What is an example of a physical contaminant servsafe - What is prime reality in spirituality - Budget forecast advantages and disadvantages - Borrowing a subsidized federal student loan means quizlet - Reading lolitha in teheran pdf - Three phase reactive power - 0737179697 MAMA SHANANI ABORTION CLINIC IN QWAQWA WELKOM HARRISMITH BETHLEHEM - Pinkies swap meets 2021 - Resume and cover letter - Independent educational psychologist hampshire - Todd anderson character analysis - Character element of drama - Wk 3 - Principles of marketing class activities - The red badge of courage and camouflaging the chimera - Evidence that pangaea once existed - Apply a ½ point black, text 1 outline to the chart area - Data table 1 microscope components - ENGLISH Assignment Instructions: Frankenstein Application Essay The Frankenstein Application Essay - Critically evaluate essay structure - English composition - Four steps of art criticism