Implement a class Robot that simulates a robot wandering on an infinite plane
Q: Write a Java class called Hotel that represents a hotel. The class will contain the following…
A: In java ArrayList can be resize as an array and it is present under util package. Example of…
Q: Write a class to model a television set. A TV has a constructor that takes the brand as a String. It…
A: PROGRAM EXPLANATION: - The TV class implements the Comparable interface public class TV implements…
Q: Consider the following class: public class Cat extends Animal implements RunsFast{ public Mammal…
A: The problem is based on the basics of Object Oriented Programming concept known as Inheritance.
Q: Please implement the Book search(Object e). This method returns the object being search if not found…
A: Here we need to iterate over the ArrayList we have and when we have a matching Book we are going to…
Q: MAKE A JAVA PROGRAM Write a class that corrects a sentence. Your class must capitalize the letter…
A:
Q: Modify the ClockPane class to drawthe clock with more details on the hours and minutes, as shown in…
A: Program: //Import required pacakgesimport javafx.application.Application;import…
Q: Help me out with this java problem. Given partial codes of the Colored interface and Point…
A: ANSWER:-
Q: Write a Java program, using object- oriented programming concepts, that allows the user: 1- Enter…
A: Note: Answering the first three subparts as per the guidelines. Input : Input marks of 10 students.…
Q: write easy java program. Make a class Employee with a name and salary. Make a class Manager…
A: Code is in step 2 and output in step 3 Programming instructions: Create a class Employee. In the…
Q: Consider a class PersonAddress that represents an entry in an address book. Its attributes are The…
A: ANSWER:-
Q: Write a class to model a television set. A TV has a constructor that takes the brand as a String. It…
A: PROGRAM: TV.java //Defining the class and implementing the comparable class class TV implements…
Q: e, one fly and three frogs are placed randomly on a board with the size 7x7.In each iteration, they…
A: code : 43 answers Three classes are implemented, 1 for frog ,1 for fly and one to run the…
Q: Provide a class for authoring a simple letter. In the constructor, supply the names of the sender…
A: The required program is as follows, File name: “Letter.java” //First the Letter class public class…
Q: write program in java Design an abstract class GeometricObject. GeometricObject must ensure that…
A: The RectangleYourRegNo class is shown below. public static class RectangleYourRegNo extends…
Q: Define a class Pet with two attributes, name (a string), and legs (an int). In Pet, define a show…
A: The approach and the python program are given below:Approach:Creating a class Pet.Now, defining the…
Q: Implement a class Moth that models a moth flying along a straight line. The moth has a position,…
A: public class Moth{ private double position; public Moth(double initialPosition) {…
Q: 1. Class Human: a. Fields: age (int), weight (double), height (double) b. Methods: getAge,…
A: Answer: Below is the solution to the problem in Java:
Q: Given the following class. (JAVA) public class FamilyMember { public String drink( ) {return…
A: logic:- define a constructor taking age as parameter. set this.age=age create a method in baby…
Q: Provide a class for authoring a simple letter. In the constructor, supply the names of the sender…
A: The Java code for the above problem is (Comments are mentioned for reference):- import java.util.*;…
Q: 1/ Implement a class Employee. An employee has a name (a string) and a salary (a double). Provide a…
A: Note: This is a multiple-question-based problem. The only first question is solved. Kindly send the…
Q: public class Book implements Comparable { protected int pages; public Book () { pages - 1500; public…
A: Here I have created a class Book that implements the Comparable interface. Inside the class, I have…
Q: 4. Complete the following class to implement all the methods in the class: public class Person {…
A: public class Person { String name; int birthYear; public Person() { name="unknown";…
Q: Consider the following code in Java 8: public interface Runnable { void run() ; } public final class…
A: Here we have an interface named Runnable with one abstract method named run, hence we can say that…
Q: Implement a class Quadrilateral that represents a quadrilateral shape, based on the coordinates of…
A: 1. As we know All shapes are special form of Trapezoid so a. if all sides are equal and…
Q: Write a class CircularArrayQueue such that all the following methods are implemented: 1. enqueue 2.…
A: Queue follows the principle in which elements that are inserted first is the one which is removed…
Q: consider the class class MyPoint: definit (self): self._x_coordinate=0 self. y coordinate = 0 def…
A: Below I have provided Python Programming. Also, I have attached the screenshot of the code and…
Q: Write a java program as in the next class diagram, such as: • SimpleCalc2() method only calls find…
A: The code is Java is as follows. Kindly refer the comments for understanding: import java.io.*;import…
Q: Public classTestMain { public static void main(String [ ] args) { Car myCar1,…
A: Solution: Given,
Q: Consider a class PersonAddress that represents an entry in an address book. Its attributes are • The…
A: Programming is a way to instruct the computer devices to operate. Every computer needs a set of…
Q: Write a Rectangle class to represent rectangles, with two data fields (width, height) and four…
A: Given: Write a Rectangle class to represent rectangles, with two data fields (width, height) and…
Q: Complete the TrafficLightComponent class to draw a traffic light such as this one. The rectangle…
A: Program: File name: “TrafficLightComponent.java” //Import necessary packages import java.awt.Color;…
Q: 3. Write a java program as in the next class diagram, such as: SimpleCalc2() method only calls find…
A: Question in Two forms first in simple way which is understand first in step 2 complete program in…
Q: 4. Complete the following class to implement all the methods in the class: public class Person {…
A: JAVA CODE- public class Person { String name; int birthYear; //constructor public…
Q: Write a java program to complete the following parts: Part-1: Create a class Car and perform the…
A: Solution: Java Program: import java.util.*; /** * Part-1 * Create a class Car */ public class…
Q: In Java 1. Suppose you have a class Circle that represents circles which all have centers at the…
A: A total ordering for a set is a set which satisfies all the four conditions, the first three…
Q: Write a java program to print the area and perimeter of a rectangle having sides of 6 and 3 units by…
A: Java Code: class Rectangle{ //class Rectangle private int length; //data members to…
Q: Define the method getElementbyId also give an example.
A: The Hypertext Markup Language, also abbreviated as HTML is basically the standard markup language…
Q: 3. Write a java program as in the next class diagram, such as: SimpleCalc2 SimpleCalc2() method only…
A: ALGORITHM:- 1. Create class SimpleCalc2(). 2. Define all the member functions inside it. 3. Test the…
Q: Consider the following classes: public abstract class PointXY private int x, y; public PointXY(int…
A: abstract methods are the methods which has only method declaration but no implementation Abstract…
Q: Complete the following class to implement all the methods in the class
A: I have given an answer in step 2.
Q: Explain the following Java Abstraction code in details and draw the UML notations diagram.
A: Abstraction: It is simply a process of hiding details Like how we made color in Shape class as…
Q: In Java Programming: Example, 8-8, defined the class Person to store the name of a person. The…
A: Program: Programs are used for problem-solving according to the instructions given by the…
Q: Define a method printAll() for class PetData that prints output as follows with inputs "Fluffy", 5,…
A: When we run the given program code, we get the below-given output of code: This program is taking…
Q: Write one java code program with a class whose instances represent a single playing card from a deck…
A: Required: Write one java code program with a class whose instances represent a single playing card…
Q: 1/ Write a BankAccountTester class whose main method constructs a bank account, deposits $1,000,…
A: 1. BankAccountTester.java public class BankAccountTester { public static void main(String…
Q: Write a java program Create an Abstract class Student that contains a method take exam, implement…
A: Create an Abstract class Student that contains a method take exam, implement the method in the child…
Q: 4.2.3: Method definition: Volume of a pyramid. Define a method pyramidVolume with double…
A: The answer is given in the below step
Q: Consider the following classes: public abstract class PointXY private int x, y; public PointXY(int…
A: Given The following statements of given answer is below.
JAva
Implement a class Robot that simulates a robot wandering on an infinite plane. The robot is located
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 moves
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, 0
means north, 1 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 class.
Therefore, implement the Robot class such that the following RobotTester class can be executed without
any changes.
import java.awt.Point;
/**
A class to test the Robot class.
*/
public class RobotTester
{
/**
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
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");
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
- public class Animal { public static int population; private int age; } public Animal (int age) { this.age = age; population++; } + msg); public void say (String msg) { System.out.print("Saying: " System.out.print(" for "); System.out.print(getHuman Years()); System.out.println(" years."); } public int getHuman Years() { return age; } public class Mammal extends Animal { private String species; public Mammal(String species, int age) { super (age); this. species species; } } } = public int getHuman Years() { if (species.equals("dog")) 1 else return super.getHumanYears() * 7; return super.getHumanYears(); €Fix this program import java.util.Scanner; public class main { public static void WeShipItBad(String[] args) { int OVERNIGHT_CHARGE = 5; int TWO_DAY_CHARGE = 2; int ECONOMY_CHARGE = 1; Scanner console = new Scanner(System.in); // Scanner object to pass around. // Get item description. String itemDescription = getItemDescription(console); if (itemDescription.equals("")) { System.out.println("Invalid description."); } shipWeight = getShipWeight(scnr); if (shipWeight <= 0.0) { System.out.println(); System.out.println("Invalid weight."); } char shipMethod = getShipMethod(council); shipMethod = Character.toUpperCase(shipMethod); double shipCost = calculateShip(shipWeight, shipMethod); displayResults(itemDescription, shipCost, shipMethod, shipWeight); } public static void getItemDescription(Scanner console) { System.out.println("Enter item description:"); String description =…50 public void setColor(String color) { } 51 52 이 ㅎ @0verride public boolean equals(Object o) { if ( o instanceof ColoredPoint ) { ColoredPoint p = (ColoredPoint)o; 53 54 55 return x == p.x && y == p.y && color p.color; 56 57 else 58 return false; 59 60 // if we override equals() we have to override hashCode() @0verride public int hashCode() { return Objects.hash(x, y, color); } 61 62 of E 65 66 /* tostring method Input: 67 68 69 None 70 Ουtρut : 71 String: (x,y,color) (No spaces) */ @0verride public String toString() { SYOUR CODE HERE> 72 73 of e 74 75 76 public static void main(String[] args) { ColoredPointp = new ColoredPoint( x: 2, y: 3, color: "red"); System.out.println("p = " + p); /* create point q using getlocation() */ Point q = p.getLocation(); /* q and p will have the same co-ordinates, but q has no color */ System.out.println("q="+q); System.out.println("p equal to q? " + p.equals(q)); ColoredPoint g2 = new ColoredPoint(q, color: "red"); System.out.println("q2="+g2);…
- public class TwoColors 10 { public static void main(String[] args) { Scanner in = new Scanner(System.in); 11 12 13 14 System.out.print("Enter your first favorite color: "); 15 16 // Step 2: Read in the next line of input and assign • it to a String variable color1 17 // 18 19 // Step 3: Trim spaces from both end and convert the // // 20 input to all lowercase and assign it back 21 22 to the same variable 23 24 System.out.print("Enter your second favorite color: "); 25 26 // Step 4: Read in the next line of input and assign 27 // it to a String variable color2 28 29 30 // Step 5: Trim spaces from both end and convert the // // 31 input to all lowercase and assign it back 32 33 to the same variable 34 35 // Step 6: Display a message according to the following: // 36 first color 37 second color message light blue 38 red That's wonderful! light blue 39 red That's even better! That's also great! 40 otherwise 41 42Methods in Java Write a program that accepts three strings: first name, last name, age, and nationality. Create an object of the class Person and assign the inputs to their respective attributes. In the class, create a method greeting() that prints the attributes. Inputs 1. Input Cody Chum 20 Filipino Sample Output Enter first name: Cody Enter last name: Chum Enter age: 20 Enter nationality: Filipino Hello, I am Cody Chum, 20 years old and a Filipino!public class worksheet3_1 { public static void main(String[] arg) { ShadowingExample example = new ShadowingExample(); example.x = 99; example.sampleMethod(); }}class ShadowingExample { int x; public void sampleMethod() { int x = 0; System.out.println("the value of local variable x = " + ………………………………………………); System.out.println("the value of instance variable x = " + …………………………………………); }} what should be written in the second print statement so that the output is: the value of instance variable x = 99 what should be written in the first print statement so that the output is: the value of local variable x = 0 options are: samplemethod.x this.x shadowingexample.x x Answer 1 Question 1
- public class Polygon { private double sideLength; private int sides; private String shape; public double getArea () { int n sides; double a sideLength; return ((a * a * n) / (4 * Math.tan((180 / n) 3.14159 / 180))); public void setPolygon (double sl, int sd, String sh) { sides-sd; sideLength-sl; shape=sh; public Polygon (double sl, int sd, String sh) ( sides-sd; sideLengthsl; shape=sh; public String getShape () { return (shape); } public int getSides () { return (sides); } public double getLength () { return (sideLength); } Write a static method named find that takes as a parameter an array of type Polygon named list. The method should print the shapes of each polygon that has an area greater than 500 and return their count. The method prototype is public static int find (Polygon [] list); Note: assume the array is already declared, populated with data in the main method and ready to be used.public class Geometry{public static void main(String[] args){//asks for user's choice Scanner in = new Scanner(System.in);displayMenu();selectOption(choice);System.out.println("Enter your choice (1-3): ");int choice1 = in.nextInt();System.out.println("Thanks for using the Geometry Calculator - Goodbye!");//Prints if input is a number that is not one of the choiceswhile(choice1 < 1 || choice1 > 3 ){System.out.println("Invalid choice. Please enter 1 - 3: ");choice1 = in.nextInt();}}/**Displays the menu*/public static void displayMenu(){System.out.println("Welcome to the Geometry Calculator Application");System.out.println("1. Calculate the Area of a Circle");System.out.println("2. Calculate the Area of a Rectangle");System.out.println("3. Calculate the Area of a Triangle");}/** This method calculates the area of the circle@return the area of the circle*/public static double circle()// calculates the area of the circle{Scanner in = new Scanner(System.in);System.out.println("What is…Problem: Bugs are simple creatures that only know how to walk towards other bugs. Bugs maintain information about their (x, y) position; by which it can tell if they are standing next to other bugs. Watch the following video: bug movement. Create a java project that simulate bugs movement. You need to write a class “Bug" that models a bug moving along a straight line and it can turn to change its direction counterclockwise (i.e. 90 degree to the left; north → west → south → east → north). In each move, its position changes by one unit in the current direction. Details of the "Bug" class is described below. Your simulator should read information of an unknown number of “Bug" objects from an input file called “Bugs.txt". Each line represents a bug and the initial position and facing direction of this particular bug. Keeping the first bug position as a reference the simulator should move the second bug next to the first bug forming a cluster and its final position and direction should be…
- 1/ Implement a class Employee. An employee has a name (a string) and a salary (a double). Provide a constructor with two arguments public Employee(String employeeName, double currentSalary) and methods public String getName() public double getSalary() public void raiseSalary(double byPercent) These methods return the name and salary, and raise the employee's salary by a certain percentage. Sample usage: Employee harry = new Employee("Hacker, Harry", 50000); harry.raiseSalary(10); // Harry gets a 10 percent raise Supply an EmployeeTester class that tests all methods. 2/Implement a class Car with the following properties. A car has a certain fuel efficiency (measured in miles/gallon or liters/km—pick one) and a certain amount of fuel in the gas tank. The efficiency is specified in the constructor, and the initial fuel level is 0. Supply a method drive that simulates driving the car for a certain distance, reducing the amount of gasoline in the fuel tank. Also supply methods…class overload { int x; double y; void add(int a , int b) { x = a + b; } void add(double c , double d) { y = c + d; } overload() { this.x 0; %3D this.y = 0; } %3D } class Overload_methods { public static void main(String args[]) { overload obj int a = 2; double b - 3.2; obj.add(a, a); obj.add(b, b); System.out.println(obj.x + } = new overload(); + obj.y); } #3Run the codeJava: ShowStudent.java: class ShowStudent { public static void main (String args[]) { Student pupil = new Student(); pupil.setIdNumber(234); pupil.setPoints(47); pupil.setHours(15); pupil.showIdNumber(); pupil.showPoints(); pupil.showHours(); System.out.println("The grade point average is " + pupil.getGradePoint()); } } ShowStudent2.java: class ShowStudent2 { public static void main (String args[]) { Student pupil = new Student(); pupil.showIdNumber(); pupil.showPoints(); pupil.showHours(); System.out.println("The grade point average is " + pupil.getGradePoint()); } } Student.java: class Student { // the private data members private int idNumber; private int hours; private int points; // Constructor added in part c Student() { } // end of constructor added in part c // the public get and set methods public void…