Question
CSCI 531 HW 1 Due WednesdayFeb. 1at 11:59 PM Central Time in Dropbox. 1. Imagine that you and a number of friends go to a
CSCI 531 HW 1
Due WednesdayFeb. 1at 11:59 PM Central Time in Dropbox.
1. Imagine that you and a number of friends go to a luxury restaurant and when you ask for the bill you want to split the amount and the tip (15 percent) between all. Write a Java program that asks the user for the total amount of the bill and the total number of friends and then calculates the amount of money that everyone has to pay. Your program should print the amount of the bill, the tip, the total cost, and the amount each person has to pay. It should also print how much of what each person pays is for the bill and for the tip.
2. Write a program LotteryPrinter that picks a combination in a lottery. In this lottery, a lottery ticket consists of 6 numbers (with none repeating) between 1 and 49. Construct an object of the Random class and invoke an appropriate method to generate each number. The numbers should be stored in an array and you must include some kind of logic to ensure that no two numbers are the same. Your program should print out a sentence such as Play this combinationitll make you rich! followed by a lottery combination.
3. Write a class Bug that models a bug moving in the x-y plane. The bug either moves north, east, south, or west. Initially, the bug moves to the north, but it can turn to the right or the left by 90 degrees at a time. In each move, its position changes by one unit in the current direction. Provide a constructor
public Bug(intinitX, intinitY) // places the bug at initial position
// initX, initY
and methods:
public void turnRight() // turn right by 90 degrees
public void turnLeft() // turn left by 90 degrees
public void move() // move in current direction by 1 unit
public intgetPositionX() // get X position
public intgetPositionY() // get Y position
public String getDirection() // returns the direction (e.g. east)
Also, you must override the method public String toString() so that it returns a string that displays the bugs position (x and y coordinates) as well as the direction that it is currently facing. Note: you dont need to draw the bug on the screen (we have not learned how to do this yet). You just need the bug object to keep track of its current position and direction.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started