Demo entry 3913075

Data Base Test

   

Submitted by Class Entry on Mar 06, 2016 at 23:20
Language: Java. Code size: 3.1 kB.

package com.hfad.databasetest;

import java.util.GregorianCalendar;

/**
 * Created by Stephen on 3/2/2016.
 *
 * Class Entry represents one entry of a rock climbing trip.
 * Each method has its own get/set method to access the fields.
 *
 * The method gradeToString() is helpful for converting the styles-less grade of the climb into a string
 * representing either the bouldering grade or the top rope grade.
 *
 * The method swapParams is a helper method for use in sorting. Allows ArrayLists to be sorted more easily by allowing
 * entries of the same type simply swap data. Accepts another Entry as input.
 */
public class Entry {

    /**
     * Each entry consists of three things.
     * Grade-Day-RopeClimbing
     */
    private int myGrade; //grade of the climb
    private boolean ropeClimbing; //boolean to represent top roping or bouldering
    private Day myDay;

    /**
     * Constructor for class Entry. This is the expected format for creation of a new entry.
     * @param inputGrade an int that represents the grade of the climb, 0-12 supported so far.
     * @param inputRopeBoolean boolean to represent topRoping vs Belaying. if inputRopeBoolean is true then they are rope climbing.
     */
    public Entry(int inputGrade, boolean inputRopeBoolean, int year, int month, int day){
        myGrade = inputGrade;
        ropeClimbing = inputRopeBoolean;
        myDay = new Day(year, month, day);

    }

    public Entry(){
        myGrade = 0;
        myDay = null;
        ropeClimbing = false;
    }

    public String gradeToString(){
        //conversion for yosemite decimal grades
        String[] ydsGrade = {"5.9", "5.10a", "5.10b", "5.10c", "5.10d", "5.11a", "5.11b", "5.11c", "5.11d", "5.12a", "5.12b", "5.12c", "5.12d"};
        String output = "";
        if(ropeClimbing){
            output+= ydsGrade[myGrade];
        }
        else{
            output += "V";
            output += myGrade;
        }
        return output;
    }

    public void swapParams(Entry e){
        Entry tempEntry = new Entry(myGrade, ropeClimbing, myDay.year, myDay.month, myDay.day);

        setMyDate(e);
        setGrade(e.getRawGrade());
        setRopeClimbing(e.isRopeClimbing());

        e.setMyDate(tempEntry);
        e.setGrade(tempEntry.getRawGrade());
        e.setRopeClimbing(tempEntry.isRopeClimbing());
    }

    public boolean isRopeClimbing() {return ropeClimbing;}

    public int getRawGrade(){ return myGrade; }

    public void setGrade(int grade) {
        this.myGrade = grade;
    }

    public void setRopeClimbing(boolean ropeClimbing) {
        this.ropeClimbing = ropeClimbing;
    }

    public void setMyDate(Entry e) {
        myDay = e.getDay();
    }

    public Day getDay(){ return myDay; }

    public void setDay(Day inputDay){
        myDay = inputDay;
    }
    public String entryToString(){
        String output = "";
        output = myDay.toString() + " " + myGrade + " " + ropeClimbing;
        return output;
    }
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).