What's new

Help Pa-unlock po, Bartleby.

Part 1

Java:
import java.util.Scanner;//to read user inputs

public class RunQuad {//start the class
 public static void main(String[] args) {//start main method
  Scanner input = new Scanner(System.in);//create Scanner object
  System.out.print("Press R for Rectangle or S for Square. ");
  char inputChoice = input.nextLine().charAt(0);//read character input
  if(inputChoice=='R') {//if choice is R
   Rectangle r = new Rectangle();//create object of Rectangle
   System.out.println("A Rectangle: ");
   r.showDescription();//call showDescription of Rectangle from its object r
  }
  else if(inputChoice=='S') {//if choice is S
   Square s = new Square();//create object of Square
   System.out.println("A Square: ");
   s.showDescription();//call showDescription of Square from its object s
  }
  else {
   System.out.println("Invalid input");
  }

 }
}
class Quadrilateral {//parent class
 public void showDescription() {
  System.out.println("- is quadrilateral");
 }
}

class Rectangle extends Quadrilateral {//rectangle inherits Quadrilateral
 public void showDescription() { 
  System.out.println("- has 4 right angles");
  super.showDescription();//call Quardrilatral's showDescription
 }
}

class Square extends Rectangle {//inherits Rectangle
 public void showDescription() { 
  System.out.println("- has 4 equal sides");
  super.showDescription();//call Rectangle's showDescription
 }
}

Part 2


Java:
import java.util.Scanner;//to read user inputs

public class RunQuad {//start the class
 public static void main(String[] args) {
  Scanner input = new Scanner(System.in);//create Scanner object
  System.out.print("Select from the following:\nR - Rectangle\nS - Square"
    + "\nP - Parallelogram\nH - Rhombus\nT - Trapezoid \n");
  char inputChoice = input.nextLine().charAt(0);//read character input
  if(inputChoice=='R') {//if choice is R
   Rectangle r = new Rectangle();//create object of Rectangle
   System.out.println("A Rectangle: ");
   r.showDescription();//call showDescription of Rectangle from its object r
  }
  else if(inputChoice=='S') {//if choice is S
   Square s = new Square();//create object of Square
   System.out.println("A Square: ");
   s.showDescription();//call showDescription of Square from its object s
  }
  else if(inputChoice=='P') {//if choice is P
   Parallelogram p = new Parallelogram();//create object of Paralleogram
   System.out.println("A Parallelogram: ");
   p.showDescription();//call showDescription of Parallelogram from its object p
  }
  else if(inputChoice=='H') {//if choice is H
   Rhombus h  = new Rhombus();//create object of Rhombus
   System.out.println("A Rhombus: ");
   h.showDescription();//call showDescription of rhombus from its object h
  }
  else if(inputChoice=='T') {//if choice is T
   Trapezoid t = new Trapezoid();//create object of Trapezoide
   System.out.println("A Trapezoid: ");
   t.showDescription();//call showDescription of Trapzoid from its object t
  }
  else {
   System.out.println("Invalid input");
  }

 }
}
class Quadrilateral {//parent class
 public void showDescription() {
  System.out.println("- is quadrilateral");
 }
}
class Parallelogram extends Quadrilateral{//inherits Quadrilateral
 public void showDescription() {
  System.out.println("- has 2 pairs of parallel sides");
  super.showDescription();//call Quardrilatral's showDescription
 }
}
class Trapezoid extends Quadrilateral{//inherits Quadrilateral
 public void showDescription() {
  System.out.println("- has 1 pair of parallel sides");
  super.showDescription();//call Quardrilatral's showDescription
 }
}
class Rectangle extends Parallelogram {//inherits Parallelgram
 public void showDescription() { 
  System.out.println("- has 4 right angles");
  super.showDescription();//call Parallelogram's showDescription
 }
}

class Square extends Rectangle {//inherits rctangle
 public void showDescription() { 
  System.out.println("- has 4 equal sides");
  super.showDescription();//call Rectangle's showDescription
 }
}
class Rhombus extends Parallelogram{
 public void showDescription() { 
  System.out.println("- has 4 congruent sides");
  super.showDescription();//call Parallelogram's showDescription
 }
}

Pamarked nalang po as solution ts.
 

Attachments

Last edited:
Part 1

Java:
import java.util.Scanner;//to read user inputs

public class RunQuad {//start the class
 public static void main(String[] args) {//start main method
  Scanner input = new Scanner(System.in);//create Scanner object
  System.out.print("Press R for Rectangle or S for Square. ");
  char inputChoice = input.nextLine().charAt(0);//read character input
  if(inputChoice=='R') {//if choice is R
   Rectangle r = new Rectangle();//create object of Rectangle
   System.out.println("A Rectangle: ");
   r.showDescription();//call showDescription of Rectangle from its object r
  }
  else if(inputChoice=='S') {//if choice is S
   Square s = new Square();//create object of Square
   System.out.println("A Square: ");
   s.showDescription();//call showDescription of Square from its object s
  }
  else {
   System.out.println("Invalid input");
  }

 }
}
class Quadrilateral {//parent class
 public void showDescription() {
  System.out.println("- is quadrilateral");
 }
}

class Rectangle extends Quadrilateral {//rectangle inherits Quadrilateral
 public void showDescription() {
  System.out.println("- has 4 right angles");
  super.showDescription();//call Quardrilatral's showDescription
 }
}

class Square extends Rectangle {//inherits Rectangle
 public void showDescription() {
  System.out.println("- has 4 equal sides");
  super.showDescription();//call Rectangle's showDescription
 }
}

Part 2


Java:
import java.util.Scanner;//to read user inputs

public class RunQuad {//start the class
 public static void main(String[] args) {
  Scanner input = new Scanner(System.in);//create Scanner object
  System.out.print("Select from the following:\nR - Rectangle\nS - Square"
    + "\nP - Parallelogram\nH - Rhombus\nT - Trapezoid \n");
  char inputChoice = input.nextLine().charAt(0);//read character input
  if(inputChoice=='R') {//if choice is R
   Rectangle r = new Rectangle();//create object of Rectangle
   System.out.println("A Rectangle: ");
   r.showDescription();//call showDescription of Rectangle from its object r
  }
  else if(inputChoice=='S') {//if choice is S
   Square s = new Square();//create object of Square
   System.out.println("A Square: ");
   s.showDescription();//call showDescription of Square from its object s
  }
  else if(inputChoice=='P') {//if choice is P
   Parallelogram p = new Parallelogram();//create object of Paralleogram
   System.out.println("A Parallelogram: ");
   p.showDescription();//call showDescription of Parallelogram from its object p
  }
  else if(inputChoice=='H') {//if choice is H
   Rhombus h  = new Rhombus();//create object of Rhombus
   System.out.println("A Rhombus: ");
   h.showDescription();//call showDescription of rhombus from its object h
  }
  else if(inputChoice=='T') {//if choice is T
   Trapezoid t = new Trapezoid();//create object of Trapezoide
   System.out.println("A Trapezoid: ");
   t.showDescription();//call showDescription of Trapzoid from its object t
  }
  else {
   System.out.println("Invalid input");
  }

 }
}
class Quadrilateral {//parent class
 public void showDescription() {
  System.out.println("- is quadrilateral");
 }
}
class Parallelogram extends Quadrilateral{//inherits Quadrilateral
 public void showDescription() {
  System.out.println("- has 2 pairs of parallel sides");
  super.showDescription();//call Quardrilatral's showDescription
 }
}
class Trapezoid extends Quadrilateral{//inherits Quadrilateral
 public void showDescription() {
  System.out.println("- has 1 pair of parallel sides");
  super.showDescription();//call Quardrilatral's showDescription
 }
}
class Rectangle extends Parallelogram {//inherits Parallelgram
 public void showDescription() {
  System.out.println("- has 4 right angles");
  super.showDescription();//call Parallelogram's showDescription
 }
}

class Square extends Rectangle {//inherits rctangle
 public void showDescription() {
  System.out.println("- has 4 equal sides");
  super.showDescription();//call Rectangle's showDescription
 }
}
class Rhombus extends Parallelogram{
 public void showDescription() {
  System.out.println("- has 4 congruent sides");
  super.showDescription();//call Parallelogram's showDescription
 }
}

Pamarked nalang po as solution ts.
Maraming salamat po!!

Last na question ko po is, san po makikita yung solution button po? I can't seem to see it here po eh :/
 

Similar threads

Back
Top