CS 1713 Practice Problems #1


Problem 1: Tracking student information

The incomplete class StudentInfo is used to keep track of a student's records. It contains the name, hours taken, and grade points earned by the student. The class calculates the GPA of the student and determines if the student is a senior. Other member functions are not shown.

public class StudentInfo 
{
// fields
private String myName;
private int myCreditHours;
private double myGradePoints;

// constructor
public StudentInfo(String name, int creditHours, double gradePoints)
{
// code here

}

//accessors
public String getName()
{
// code here
}

public int getCreditHours()
{
// code here
}

public double getGradePoints()
{
// code here
}

public double computeGPA()
{
// code here
}

public boolean isSenior()
{
// code here
}

public String toString( )
{
// code here
}
// modifiers here ...
}


Problem 2: Computing ticket cost

The following incomplete class TicketCalculator is used (among other things) to calculate the cost of speeding tickets given by the officers of Speedtrap, Tx. It contains the speed of the driver and the posted speed where the ticket was given.

public class TicketCalculator { 
// class constants
// 1-10 miles per hour over
public static final double LOWCOST = 10.00;
// 11-20 miles per hour over
public static final double MIDCOST = 15.00;
// 21 or over
public static final double MAXCOST = 20.00;

// fields
private int mySpeed;
private int myPostedSpeed;

// constructor
public TicketCalculator(int speed, int postedSpeed)
{
// code here
}

// accessors
public double computeTicketCost()
{
// code here
}

// other accessors here
// modifiers here
}


Problem 3: Analyzing body weight

The following incomplete class is used to determine if a person is obese. It records the gender, weight and height of a person. The class calculates the body mass index and "other" statistics for a person requiring this information.

public class ObesityStats 
{
// class constants
public static final double MALELIMIT = 27.8;
public static final double FEMALELIMIT = 27.3;

// fields
private char myGender;
private double myWeight; // in kilograms
private double myHeight; // in meters

// constructor
public ObesityStats( char gender, double weight, double height)
{
// code here
}

// accessors here
public double getMassIndex()
{
// code here
}

public void weightResults()
{
// code here
}
// modifiers here
}


Problem 4: Analyzing production based on rainfall

The following incomplete class ProductionIndicator is used to predict the seasonal wheat harvest for acreage based on the average rainfall. Under ideal conditions of 21 inches of rain a single acre will produce 8.4 bushels of wheat. For every inch of rain above or below 21, production is decreased 5%.

public class ProductionIndicator 
{
// class constants
public static final double IDEAL = 21;
public static final double BUSHELSPERACRE = 8.4;
public static final double RATEDECREASE = 0.05;

// fields
private double myRainFall;
private double myNumAcres;

// constructor
public ProductionIndicator(double rainFall, double numAcres)
{
// code here
}

// accessors
public double getRainFall()
{
// code here
}

public double getNumAcres
{
// code here
}

public double bushelsProduced ()
{
// code here
}
// modifiers here
}


Objective: Solidify ability to write simple classes
Last revision: August 19, 2002 at 4:00 pm