CS141 HW Quiz 1, Java

0.0(0)
studied byStudied by 0 people
full-widthCall with Kai
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/12

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

13 Terms

1
New cards

How to create a class in java

Ex: Create a shape class

class Shape {

}

2
New cards

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 {

}

3
New cards

How to create a pure virtual member function in a class in Java
ex: a area class of type double

abstract double area();

4
New cards

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);
}

5
New cards

Create the main function/class in java

public class mainClass{
public static void main(String[] args){

6
New cards

Create an array of shape objects of set size 2

Shape[] shapeArray = new Shape[2];

7
New cards

Create an array of shape objects, fill the shape with two circles

Shape []shape Array = new Shape[]{new Circle(2), new Circle(5)};

8
New cards

How to convert double to string

Double.toString(postDoubleHere);H

9
New cards

How to print a line (remember, you can only print strings)

System.out.println(“what u need to print here”);

10
New cards

Print shapes area in a shape array

for(int i = 0; i<2; i++){
System.out.println(Double.toString(shapeArray[i].area());
}H

11
New cards

How to assign something null in Java

head = null;

12
New cards

How to convert string to int in java

int x = Integer.parseInt(string);

13
New cards

How to convert int to string in java

string y = Integer.toString(x);

Explore top flashcards

spanish
Updated 997d ago
flashcards Flashcards (32)
ap psych terms
Updated 894d ago
flashcards Flashcards (527)
Muscle anatomy
Updated 671d ago
flashcards Flashcards (26)
Enfoques - C1
Updated 748d ago
flashcards Flashcards (64)
Madrid Quiz 2
Updated 129d ago
flashcards Flashcards (112)
spanish
Updated 997d ago
flashcards Flashcards (32)
ap psych terms
Updated 894d ago
flashcards Flashcards (527)
Muscle anatomy
Updated 671d ago
flashcards Flashcards (26)
Enfoques - C1
Updated 748d ago
flashcards Flashcards (64)
Madrid Quiz 2
Updated 129d ago
flashcards Flashcards (112)