Wiki
Quote
So, in this world, a square would be the same as a circle. Mmm have to think about grouping them in a different way.. Maybe lines, blocks and curves, as indicated by jon?
This post has been edited by andrewsw: 04 February 2013 - 10:23 AM




Posted 04 February 2013 - 10:20 AM
Quote
This post has been edited by andrewsw: 04 February 2013 - 10:23 AM
Posted 05 February 2013 - 01:10 AM
package areaprog;
import java.util.Scanner;
public class ShapesAreUs {
public static void main(String[] args) {
private Shape getShapeFromUser(double choice){
if (choice ==1){
System.out.println("what is the length of 1 side of the square?\n");
}
}
System.out.println("The area of your " + shape.getName() + " is: " + shape.getArea());
}
}
package areaprog;
public class Shape {
class shape {
public String getName() {return "Shape";}
public double getArea() {return 0;}
}
}
package areaprog;
class Square extends Shape{
private final double side; //only 1 property needed for this formula
public Square(double side) {this.side = side;} //constructor
public String getName() {return "Square";}
public double getArea() {return this.side * this.side;}
}
Posted 05 February 2013 - 01:47 AM
package areaprog;
import java.util.Scanner;
public class ShapesAreUs {
public static void main(String[] args) {
private Shape getShapeFromUser(double choice){
if (choice ==1){
System.out.println("what is the length of 1 side of the square?\n");
}
}
System.out.println("The area of your " + shape.getName() + " is: " + shape.getArea());
}
}
package areaprog;
public class Shape {
class shape {
public String getName() {return "Shape";}
public double getArea() {return 0;}
}
}
Posted 05 February 2013 - 05:27 AM
public class ShapesAreUs {
// ok, entry point for program
public static void main(String[] args) {
// start of new method, but we're not done with the old one yet
private Shape getShapeFromUser(double choice){
if (choice ==1){
System.out.println("what is the length of 1 side of the square?\n");
}
} // end getShapeFromUser, is would actually work
// now we're kind of lost
System.out.println("The area of your " + shape.getName() + " is: " + shape.getArea());
}
}
package areaprog;
import java.util.Scanner;
public class ShapesAreUs {
// we will try to kill as much static as possible
// we also want main rather lean
// let's make Mainprog an object
// you only need one reader in your program
private Scanner reader;
public ShapesAreUs() {
// init reader in constructor
this.reader = new Scanner(System.in);
}
// we show the menu more than once, so it's a method
private void showMenu() { /* your code here */ }
// we ask the user for a choice
// make sure the choice returned is valid
private int menuChoice() { /* your code here */ }
private Shape getShapeFromUser() {
int choice = menuChoice();
if (choice == 1){
System.out.println("What is a length of 1 side of the Square?\n");
double side = reader.nextDouble();
return new Square(side);
} else if (choice == 2) {
// ...
}
return null;
}
public void run() {
// with methods in place, the general logic of the program is simpilar to follow
Shape shape = getShapeFromUser();
// a null shape means they chose exit
if(shape!=null) {
System.out.println("The area of you " + shape.getName() + " is: " + shape.getArea());
}
}
public static void main (String [] args){
// avoid static land
// here we make an instance of ShapesAreUs and then call the method run
new ShapesAreUs().run();
}
}
This post has been edited by baavgai: 05 February 2013 - 05:27 AM
Posted 05 February 2013 - 07:45 AM
Quote
public static void main(String [] args){
//...do something
}
or
public class MyClass{
//...do something
}
public class MyClass
{
//...do something
}
public static void main(String [] args)
{
//...do something
}
Posted 05 February 2013 - 08:09 AM
public class MyClass
{
//...do something
}
Posted 05 February 2013 - 08:27 AM
Quote
This post has been edited by jon.kiparsky: 05 February 2013 - 08:29 AM
Posted 05 February 2013 - 08:28 AM
andrewsw, on 05 February 2013 - 08:09 AM, said:
public class MyClass
{
//...do something
}
Posted 05 February 2013 - 08:34 AM
jon.kiparsky, on 05 February 2013 - 08:27 AM, said:
Quote
Posted 05 February 2013 - 09:03 AM
Quote
Posted 05 February 2013 - 09:34 AM
jon.kiparsky, on 05 February 2013 - 10:27 AM, said:
Posted 05 February 2013 - 10:25 AM
Quote
Quote
Quote
Quote
