Title
- toc: true
- badges: true
- comments: true
- categories: [jupyter, Class Lessons]
- image: images/chart-preview.png
public class Cow
{
Cow myCow = new Cow();
Cow bessie = new Cow("hostein", "moo");
}
Methods
public static void main(String[] args){
}
// Basic Java Class
public class Snack { // class name always starts with capital letter
/*
* Instance variables
* Always declared right after class declaration
* Declared with TYPE and NAME
*/
private String name;
private int calories;
// constructor
public Snack(String n, int c){
name = n;
calories = c;
}
// methods
public String getName(){ // accessor
return name;
}
public void setName(String n){ // mutator
name = n;
}
// main method
public static void main(String[] args) {
Snack one = new Snack("Oreos", 100);
System.out.println(one.getName());
}
}
Snack.main(null);
public class cow
{
//on her fastpahes
}
//Hack 3
//Hack 4
public class Song
{
/** Verse - prints out a verse of the song
* @param number - a String like "one", "two", etc.
* @param rhyme - a String like "thumb", "shoe", etc.
*/
public void verse(String number, String rhyme)
{
System.out.println("This old man, he played " + number);
System.out.println("He played knick knack on my " + rhyme);
}
// The chorus method
public void chorus()
{
System.out.println("With a knick knack paddy whack, give a dog a bone.");
System.out.println("This old man came rolling home.");
}
public static void main(String args[])
{
Song mySong = new Song();
mySong.verse("one", "thumb");
mySong.chorus();
mySong.verse("two", "shoe");
mySong.chorus();
mySong.verse("three", "knee");
mySong.chorus();
}
}
Song.main(null);