Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

uing java to write, and using the code which is gived to write Activity 2 Activity 1. Write a Java program that reads in three

uing java to write, and using the code which is gived to write Activity 2

image text in transcribed

image text in transcribed

Activity 1. Write a Java program that reads in three floating point numbers and prints the multiplication of th three inputs. The result should have two digits after the decimal point. For example: Please enter three numbers: 4 9 2.5 The multiplication is 90.00. Activity 2. Implement a class Robot that simulates a robot wandering on an infinite plane. The robot is loca at a point with integer coordinates and faces north, south, east, or west. Supply methods: public void turnLeft public void turnRight public void move() public Point getLocation public String getDirection() The turnLeft and turnRight methods change the direction but not the location. The move method m the robot by one unit in the direction it is facing. The getDirection method returns a string "N","S" "E", "W". For the new object, the initial location and facing should be specified. For the initial facing, O means north, I means east, 2 means south, and 3 means west. A tester class, RobotTester, has been provided as follows to help you how to implement the Robot cl: Therefore, implement the Robot class such that the following Robottester class can be executed with any changes. import java.awt. Point; /** A class to test the Robot class. public class Robot Tester /** Tests the methods of the Robot class. @param args not used */ public static void main(String[] args) // Create a new Robot object with the initial position of (5,5) and // initial direction to the East (1). Robot robot = new Robot (new Point(5, 5), 1); robot.move(); // 6, 5, 1 robot.turnRight(); // 6, 5, 2 robot.move(); // 6, 6, 2 robot.move(); // 6, 7, 2 robot.turnRight(); // 6, 7, 3 robot.move(); // 5, 7, 3 robot.move(); // 4, 7, 3 robot.turnLeft(); // 4, 7, 2 robot.move(); // 4, 8, 2 Point location = robot.getLocation(); System.out.println("Location: " + location.x + ", " + location.y); System.out.println("Expected: 4, 8"); System.out.println("Direction: " + robot.getDirection()); System.out.println("Expected: S"); Activity 3. A Person has a name (just a first name for simplicity) and friends. Store the names of the friends in a string, separated by spaces. Provide a class for Person and a constructor that constructs a person with a given name and no friends. Provide the following methods as well: befriend(Person p) unfriend(Person p) getFriendNames getFriendsCount()

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

Students also viewed these Databases questions