create a new program containing: A class named Point, with two fields: x and y and a constructor to set the values (see https://docs.oracle.com/javase/tutorial/displayCode.html?code=https://docs.oracle.com/javase/tutorial/java/javaOO/examples/Point.java) Add a new field that will keep a name for the point. It is empty string by default. Create a new constructor that will set the name to a predefined value. Add a print method that will print the coordinates in the format: NAME(X,Y).  A class name Rectangle, with a point of origin, height and width, four constructors and two methods (see https://docs.oracle.com/javase/tutorial/displayCode.html?code=https://docs.oracle.com/javase/tutorial/java/javaOO/examples/Rectangle.java) Add a new field that will keep a name for the rectangle. Create a constructor that will set the name, origin point and dimensions. Add a print method that will print the coordinates in the format: NAME(x, y, w, h)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Code:

import java.util.*;

//Bicycle interface

interface Bicycle

{

abstract void changeCadence(int newValue); //will change value of candence to new value

abstract void changeGear (int newValue); //changes gear of car

abstract void speedUp(int increment); //increments speed of car by adding new Value to existing speed

abstract void applyBrakes(int decrement);

}

//ACMEBicycle class definition

class ACMEBicycle implements Bicycle

{

int cadence = 0;   

int speed = 0;   

int gear = 1;

//methods of interface

public void changeCadence(int newValue)

{

this.cadence=newValue;

}

public void changeGear (int newValue)

{

this.gear=newValue;

}

public void speedUp(int increment)

{

this.speed+=increment;

}

public void applyBrakes(int decrement)

{

this.speed-=decrement;

}

//display method

void display()

{

System.out.println("Cadence: "+this.cadence);

System.out.println("Gear: "+this.gear);

System.out.println("Speed: "+this.speed);

}

}

//KEYOBicycle class definition

class KEYOBicycle implements Bicycle

{

int cadence = 0; 

int speed = 0; 

int gear = 1;

//methods of interface

public void changeCadence(int newValue)

{

this.cadence=newValue;

}

public void changeGear (int newValue)

{

this.gear=newValue;

}

public void speedUp(int increment)

{

this.speed+=increment;

}

public void applyBrakes(int decrement)

{

this.speed-=decrement;

}

//display method

void display()

{

System.out.println("Cadence: "+this.cadence);

System.out.println("Gear: "+this.gear);

System.out.println("Speed: "+this.speed);

}

}

public class Main

{

 public static void main(String[] args) {

 System.out.println("Enter 1 for ACMEBicycle or 2 for KEYOBicycle");

 Scanner sc= new Scanner(System.in);

 //prompts user to choose either of the bicycles

 int a=sc.nextInt();

 //creating objects

 ACMEBicycle obj1= new ACMEBicycle();

 KEYOBicycle obj2= new KEYOBicycle();

 if (a==1)

 {

 obj1.changeCadence(5);

 obj1.changeGear(3);

obj1.speedUp(40);

 obj1.applyBrakes(20);

 obj1.display();

 }

else if (a==2)

 {

 obj2.changeCadence(5);

obj2.changeGear(3);

 obj2.speedUp(40);

obj2.applyBrakes(20);

obj2.display();

 }

 else

 {

 System.out.println("Wrong Choice!");

 }

 }

}

Using this links:

Classes and Objects https://docs.oracle.com/javase/tutorial/java/javaOO/index.html

  • Objects https://docs.oracle.com/javase/tutorial/java/javaOO/objects.html
  • Creating Objects https://docs.oracle.com/javase/tutorial/java/javaOO/objectcreation.html 
  • Using Objects https://docs.oracle.com/javase/tutorial/java/javaOO/usingobject.html  Instructions:
  • Continue the above code(program):

    Also:

  • create a new program containing:
    • A class named Point, with two fields: x and y and a constructor to set the values (see https://docs.oracle.com/javase/tutorial/displayCode.html?code=https://docs.oracle.com/javase/tutorial/java/javaOO/examples/Point.java)
      • Add a new field that will keep a name for the point. It is empty string by default. Create a new constructor that will set the name to a predefined value.
      • Add a print method that will print the coordinates in the format: NAME(X,Y). 
    • A class name Rectangle, with a point of origin, height and width, four constructors and two methods (see https://docs.oracle.com/javase/tutorial/displayCode.html?code=https://docs.oracle.com/javase/tutorial/java/javaOO/examples/Rectangle.java)
      • Add a new field that will keep a name for the rectangle.
      • Create a constructor that will set the name, origin point and dimensions.
      • Add a print method that will print the coordinates in the format: NAME(x, y, w, h)
  • Imagine a robot head (square) with a rectangle mouth and nose and point eyes. Create the image in a new main program (class), giving suggestive names for points and rectangles. 
  • Print the information for all the figures.
  • Check which eye has the biggest x coordinate and print the result. 
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY