2 Replies - 1470 Views - Last Post: 03 September 2010 - 04:37 PM Rate Topic: -----

#1 Braber01   User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 332
  • Joined: 29-November 08

Do I need setWhatever() methods?

Posted 03 September 2010 - 04:16 PM

Specifications
Create a class named Circle to store the data about this circle. This class should contain these constructors and methods:
public Circle(double radius)
public double getCircumference()
public String getFormattedCircumference()
public double getArea()
public String getFormattedArea()
private String formatNumber(double x)
public static int getObjectCount()


The formulas for calculating circumference and area are:
circumference = 2 * pi * radius
area = pi * radius2


For the value of pi, use the PI constant of the java.lang.Math class.
Create a class named CircleApp that gets the user input, creates a Circle object, and displays the circumference and area.
Create a class named Validator like the one shown in chapter 6 and use its static methods to validate the data in this application.

here is my project so far
import java.util.Scanner;
import java.text.NumberFormat;

/**
 * @author Braber01
 * DATE: September 3, 2010
 * DESC: Get Area and Circumference of a Circle using OOP Methods
 * and using good class Design
 */
public class Circle {
	static int numObjects=0;
	private double circumfrence;
	private double area;
	/**
	 * @param args The command Line Arguments
	 */
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		System.out.println("Welcome to Ben's Circle Tester");
		System.out.println();
		System.out.println("Enter Raidus: ");
		double radius = in.nextDouble();
		new Circle(radius);	
	}
	public Circle(double radius){
		//Circle.numObjects++;
		
	}
	public double getCircumference(){
		return circumfrence;		
	}
	public String getFormattedCircumference(){
		return "";
	}
	public double getArea(){
		return (double) 0;
	}
	public String getFormattedArea(){
		return "";
	}
	@SuppressWarnings("unused")
	private String formatNumber(double x){
		return "";
	}
	public static int getObjectCount(){
		return 0;
	}
	@SuppressWarnings("unused")
	private class Validator{
		
	}
}


Any help would be greatly appracated Thanks Braber01

Is This A Good Question/Topic? 0
  • +

Replies To: Do I need setWhatever() methods?

#2 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12800
  • View blog
  • Posts: 45,992
  • Joined: 27-December 08

Re: Do I need setWhatever() methods?

Posted 03 September 2010 - 04:33 PM

If you limit access to your variables and you want users to be able to modify them, you must provide setter methods. Setter methods also have the benefit of allowing you to validate the values passed as params before assigning them to your attributes.

Does this answer your question? Also, please post your question in the body of your thread, not the title where it gets truncated.
Was This Post Helpful? 0
  • +
  • -

#3 Braber01   User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 332
  • Joined: 29-November 08

Re: Do I need setWhatever() methods?

Posted 03 September 2010 - 04:37 PM

Well there's only one variable that the user needs to modify so I think it does.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1