Reading Compiler Errors & Java Interfaces, Study notes of Geometry

Geometry.java:1: error: class, interface, or enum expected public abstract Geometry. Cylinder.java:17: error: constructor Shape in class ...

Typology: Study notes

2022/2023

Uploaded on 03/01/2023

ekaksha
ekaksha 🇺🇸

4.4

(30)

268 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
9/23/2019
1
Reading Compiler Errors
&
Java Interfaces
CSCI 2300
Survey Results Summary
Labs could be designed to be more helpful
It is not always clear what is expected.
Some slowing down may be helpful
In general, more people think the class is moving too fast
Fewer people think the class is moving too slow
NOTE: Lectures alone may not be sufficient to learn the material. You
are expected to read the assigned reading. The effort required to do
the reading may differ depending on your prior experience.
pf3
pf4
pf5
pf8

Partial preview of the text

Download Reading Compiler Errors & Java Interfaces and more Study notes Geometry in PDF only on Docsity!

Reading Compiler Errors

Java Interfaces

CSCI 2300

Survey Results Summary

  • Labs could be designed to be more helpful
    • It is not always clear what is expected.
  • Some slowing down may be helpful
    • In general, more people think the class is moving too fast
    • Fewer people think the class is moving too slow

NOTE: Lectures alone may not be sufficient to learn the material. You

are expected to read the assigned reading. The effort required to do

the reading may differ depending on your prior experience.

Reading Compiler Errors

Compiler errors

  • What is a compiler error?
  • How do you fix compiler errors:
    • Start at the very first error
    • Read what the compiler is complaining about
Example (from your labs):
Driver.java:5: error: cannot find symbol
Circle first = new Circle2D(1, 2, 5);
^
symbol: class Circle
location: class Driver

A trickier example

Cylinder.java:39: error: abstract method

getArea() in Shape cannot be accessed directly

return super.getArea()*height;

  • Cylinder extends Shape
  • Shape is abstract
  • Shape has an abstract getArea() method

Java Interfaces

Review

  • Last time we discussed
    • Polymorphism
    • Abstract classes
  • How is abstract class different from a regular (non-abstract) class?

Suppose you are…

  • Designing a game of PacMan
    • PacMan roams through a Maze
    • Goal: eat the dots and avoid ghosts
    • Advance to next level when all dots are eaten

class Maze { public void place(IPlaceable p) { //select location on the Maze p.draw(location); } } Maze maze = new Maze(); PackMan packMan = new PackMan(); maze.place(pacMan);

PackMan is substitutable

for IPlaceable because

PacMan implements

IPlaceable

Interface versus Inheritance

Inheritance

  • A class can have only one parent

class

  • A class can be instantiated (if it

is not abstract)

  • A class inherits parent class's

methods and does not have to

override them

Interface

  • A class can implement multiple

interfaces

  • An interface cannot be

instantiated

  • A class implementing an

interface must implement all

interface methods

Lab 5

  • Pull your git repos, you will find lab5 directory
  • Complete code noted in TODO comments.
  • Run the driver, it should produce the output as in driver_output.txt

MovablePoint MovableCircle

<>

IMovable

+moveUp(int distance): void

+moveDown(int distance): void

+moveLeft(int distance): void

+moveRight(int distance): void