1/12
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
How to create a class in java
Ex: Create a shape class
class Shape {
…
}
How to create a class that you don’t want to be able to be made into an object in Java
Ex: Create a shape class
abstract class Shape {
…
}
How to create a pure virtual member function in a class in Java
ex: a area class of type double
abstract double area();
Create a Circle class that inherits from shape.
Create the data members radius and PI, radius is a double, pi is a double constant with a value of 3.14
Write a constructor to initialize radius
Create a member function area of type double that returns the area of a circle
class Circle extends Shape{
double radius;
static final double PI = 3.14;
Circle(double radius){
super();
this.radius = radius;
}
double area(){
return(this.radius*this.radius*Cthis.PI);
}
Create the main function/class in java
public class mainClass{
public static void main(String[] args){
Create an array of shape objects of set size 2
Shape[] shapeArray = new Shape[2];
Create an array of shape objects, fill the shape with two circles
Shape []shape Array = new Shape[]{new Circle(2), new Circle(5)};
How to convert double to string
Double.toString(postDoubleHere);H
How to print a line (remember, you can only print strings)
System.out.println(“what u need to print here”);
Print shapes area in a shape array
for(int i = 0; i<2; i++){
System.out.println(Double.toString(shapeArray[i].area());
}H
How to assign something null in Java
head = null;
How to convert string to int in java
int x = Integer.parseInt(string);
How to convert int to string in java
string y = Integer.toString(x);