Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this lab you will have to generate a random number. Here is some sample code import java.util.*; Random u=new Random(); //Generate a number between

For this lab you will have to generate a random number. Here is some sample code

import java.util.*;

Random u=new Random();

//Generate a number between 0 and 10

int c=u.nextInt(10);

//Generate a number between 1 and 11. shift everything by 1

int c=u.nextInt(10)+1

//Generate a number between 2 and 11. shift everything by 2

int c=u.nextInt(10)+2

There is no Driver class for this assignment.

Create a class called Family that contains the following instance variables.

Income

children

Create an anonymous static block that generates a random number between 1 and 8. In the main method, call the no argument constructor if the random number that is generated is less than 4 and the one argument constructor if it is equal or greater than 4

Create an anonymous instance block that assigns the random number to the instance variable, children

In main create an object

If the no argument constructor is called, then inside the constructor, Multiply the random number by 1000 and assign it the income

If a one argument constructor is called, then ask the user for the income. Use the following syntax from section 3.5e to retrieve the income from the user

JOptionPane.showInputDialog(" some prompt ");

Convert the input which is in the form of a string into a Double object using the Double wrapper class and then convert it to the double primitive datatype.

Pass in the converted String which is now a double to the one argument constructor and assign it to the income instance variable.

Display the object information

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

Different formulas for mathematical core areas.

Answered: 1 week ago