Session 6
Source Code
import java.util.*;
public class Session6 {
public static void main(String[] args) {
System.out.println("Session 6");
// example1 method call
// example2 method call
}
// example1 method definition
public static void example1() {
// Create Counter object
// Increment counter
// Print counter variable
// Reset counter value
// Print counter value (again)
// click twice and print the value
//
}
// example2 method definition
public static void example2() {
}
}Ant.java
public class Ant {
// instance variable
// Constructor
// display method
// main method
public static void main(String[] args) {
System.out.println("Ant Class Demo");
// Example 1
// Example 2
// Example 3
}
}Flower.java
public class Flower {
// instance variable
// Constructor
// method
// main method
}Counter.java
// class header
// private instance variable(s)
// Constructor
// accessor method(s)
// mutator method(s)
Point.java
/**
* The Point class represents a point in 2D space with x and y coordinates.
* It provides methods to move the point and calculate distance.
*/
public class Point {
// Instance variables
/**
* No argument constructor
*/
/**
* Parameterized constructor that sets x and y
* @param x the x-coordinate
* @param y the y-coordinate
*/
// Getters and setters
/**
* Moves the point to new coordinates.
* @param newX new x-coordinate
* @param newY new y-coordinate
*/
/**
* Shifts the point by a given amount in x and y directions.
* @param dx change in x
* @param dy change in y
*/
/**
* Displays the coordinates of the point.
*/
}StringDemo.java
public class StringDemo {
public static void main(String[] args) {
System.out.println("String Demo");
}
}S6Problem1.java
import java.util.*;
public class S6Problem1 {
public static void main(String[] args) {
System.out.println("Problem 1");
Scanner in = new Scanner(System.in);
}
}S6Problem2.java
import java.util.*;
public class S6Problem2 {
public static void main(String[] args) {
System.out.println("Problem 2");
Scanner in = new Scanner(System.in);
}
}S6Problem3.java
import java.util.*;
public class S6Problem3 {
public static void main(String[] args) {
System.out.println("Problem 3");
Scanner in = new Scanner(System.in);
}
}S6Problem4.java
import java.util.*;
public class S6Problem4 {
public static void main(String[] args) {
System.out.println("Problem 4");
Scanner in = new Scanner(System.in);
}
}S6Problem5.java
import java.util.*;
public class S6Problem5 {
public static void main(String[] args) {
System.out.println("Problem 5");
Scanner in = new Scanner(System.in);
}
}S6Problem6.java
import java.util.*;
public class S6Problem6 {
public static void main(String[] args) {
System.out.println("Problem 6");
Scanner in = new Scanner(System.in);
}
}S6Problem7.java
import java.util.*;
public class S6Problem7 {
public static void main(String[] args) {
System.out.println("Problem 7");
Scanner in = new Scanner(System.in);
}
}S6Problem8.java
import java.util.*;
public class S6Problem8 {
public static void main(String[] args) {
System.out.println("Problem 8");
Scanner in = new Scanner(System.in);
}
}S6Problem9.java
import java.util.*;
public class S6Problem9 {
public static void main(String[] args) {
System.out.println("Problem 9");
Scanner in = new Scanner(System.in);
}
}S6Problem10.java
import java.util.*;
public class S6Problem10 {
public static void main(String[] args) {
System.out.println("Problem 10");
Scanner in = new Scanner(System.in);
}
}PetTracker.java
/**
* The Pet class represents a pet with a name, species, and age.
* Each Pet object stores information about ONE specific pet.
*/
public class PetTracker {
// instance variables (aka fields / attributes)
private String name;
private String species;
private int age; // in years
/**
* Constructor: creates a new Pet with a given name, species, and age.
*
* @param petName the pet's name
* @param petSpecies the type of animal (e.g. "dog", "cat", "lizard")
* @param petAge the pet's age in years
*/
public Pet(String petName, String petSpecies, int petAge) {
name = petName;
species = petSpecies;
age = petAge;
}
/**
* Returns the pet's name.
*/
public String getName() {
return name;
}
/**
* Returns the pet's species.
*/
public String getSpecies() {
return species;
}
/**
* Returns the pet's age.
*/
public int getAge() {
return age;
}
/**
* Increases the pet's age by 1 year.
* This simulates having a birthday.
*/
public void haveBirthday() {
age = age + 1;
System.out.println(name + " just had a birthday! Age is now " + age);
}
/**
* Prints a short summary of the pet.
* Example: "Pumpkin is a 3-year-old cat."
*/
public void printInfo() {
System.out.println(name + " is a " + age + "-year-old " + species + ".");
}
/**
* This class will be used to TEST the Pet class.
* You will add code in main() in Parts A–D.
*/
public static void main(String[] args) {
// You will write your code here for the lab
}
}Last updated
Was this helpful?