Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.ArrayList; class Main { public static void main(String[] args) { ArrayList toys = new ArrayList (); toys.add(new Toy(Lego Set, 29.99)); toys.add(new Toy(Monopoly Deal, 17.50));

import java.util.ArrayList;

class Main {

public static void main(String[] args) {

ArrayList toys = new ArrayList();

toys.add(new Toy("Lego Set", 29.99));

toys.add(new Toy("Monopoly Deal", 17.50));

toys.add(new Toy("Rubik's Cube", 10.00));

toys.add(new Toy("Nerf Gun", 39.99));

toys.add(new Toy("Barbie Doll", 12.99));

toys.add(new Toy("basketball", 19.99));

toys.add(new Toy("scooter", 59.99));

ToyBox toyBox = new ToyBox(4,3,toys);

System.out.println(" *** Toy Box Check ***");

System.out.println(toyBox);

Toy elCheapo = toyBox.cheapestToy();

System.out.println("Cheapest Toy: " + elCheapo);

System.out.println(" *** Game Show Board Check ***");

String[] clues = new String[30];

for(int i = 0; i < 30; i++)

clues[i] = "a";

GameShowBoard b = new GameShowBoard(5,6,clues);

b.chooseBonus();

System.out.println(b);

}

} ------------------------------------------------

class Clue {

private int dollarAmount;

private String clue;

private boolean isBonus;

public Clue(int d, String c)

{

dollarAmount = d;

clue = c;

isBonus = false;

}

public void setBonus()

{

isBonus = true;

}

//not shown on quiz

public boolean isBonus()

{

return isBonus;

}

public String toString()

{

return "[$" + dollarAmount + "]";

}

}

---------------------------------------------------------

class GameShowBoard {

private Clue[][] board;

public GameShowBoard(int rows, int cols, String[] clues)

{

board = new Clue[rows][cols];

int i = 0;

int dollars = 100;

for(int r = 0; r

{

for(int c=0; c

{

board[r][c] = new Clue[i];

dollar += 100;

}

}

}

public void chooseBonus()

{

/* PART B - Randomly chooses any one any

one of the Clues in board and sets its

isBonus state to true */

}

-----------------------------------------------

class Toy {

private String name;

private double cost;

public Toy(String n, double c)

{

name = n;

cost = c;

}

public double getCost()

{

return cost;

}

public String getName()

{

return name;

}

//not shown on quiz

public String toString()

{

String s = name + " $" + cost;

while (s.length() < 20)

s += " ";

return s;

}

}

-------------------------------------------------------

import java.util.ArrayList;

class ToyBox {

private Toy[][] box;

public ToyBox(int rows, int cols, ArrayList toys)

{

/*Part A - initializes box to have dimensions rows

by cols. Toys in the toys arraylist are copied into

the 2D array box in row major order. Empty

spaces in the box are assigned null.

Given: rows * cols >= toys.size() */

}

public Toy cheapestToy()

{

/*Part B - returns the cheapest Toy in box.

In case of a tie, return either Toy. You can assume

there is at least one Toy in the box and that there

is a Toy (not null) at position row 0, column 0 */

return null;

}

public String toString()

{

String build = "";

for(Toy[] row: box)

{

for(Toy t : row)

{

if(t != null)

build += t;

else

build += "Empty Space ";

}

build += " ";

}

return build;

}

}

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

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions

Question

What are the stages of project management? Write it in items.

Answered: 1 week ago

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago