Just started learning java and i'm having a little trouble with my compiling im supposed to give a screen shots of my outputs if it works but vista is blocking it (asks for permission and then just hangs)

ive included the questions just in case its being bleh but it should work... i hope =3

Q1 construct a class for a triangle

use lengths of sides as data members
include constructors for no inputs, one input and three inputs
include methods to calculate perimeter, area (herons formula)
include methods that test for an equilateral or isosceles triangle
include a method to test for a right angle (Pythagoras theorem)

put the main method in a separate test driver class

public class Triangle {

    //Triangle with 3 said a, b, and c
    private int sideA;
    private int sideB;
    private int sideC;

    // Constructor that takes 3 lengths as input
    public Triangle (   int newSideA,
                int newSideB,
                int newSideC) {
        sideA = newSideA;
        sideB = newSideB;
        sideC = newSideC;

    }

    // Constructor equilateral triangle
    public Triangle(    int newLength) {
        sideA = newLength;
        sideB = newLength;
        sideC = newLength;
    }

    //Constructor with default value;
    public Triangle() {
        sideA = 3;
        sideB = 4;
        sideC = 5;
    }

    //Methods that return side A
    public int GetSideA() {
        return sideA;           
    }

    //Methods that return side B
    public int GetSideB() {
        return sideB;           
    }

    //Methods that return side C
    public int GetSideC() {
        return sideC;           
    }

    //Method that return perimeter
    public int GetPerimeter() {
        return sideA + sideB + sideC;
    {

    //Method that set the length of sides
    public void SetLengths(int a; int b; int c) {
        if (a>0) {
            sideA = a;
        }
        if (b>0) {
            sideB = b;
        }
        if (c>0) {
            sideC = c;
        }
    }
}

Q2 Construct a class for photograph

use year it was taken, faces, events, placesin the photoas data members
can you think of any other usefull data members?

include a constructor for one input (year) and all inputs
include methods to get and set faces, events and places
include a method to print a full description of photo

include the main method in class

import java.util.ArrayList;

public class PhotoItem
{
    public String Title;
    public String Author;
    public ArrayList<String> People = new ArrayList<String>();
    public ArrayList<String> Details = new ArrayList<String>();
    public int YearTaken;

    // Constructor (all)
    public LibraryItem (String Title,String Author,
                        ArrayList<String> People, ArrayList<String> Details,
                        int YearTaken)
    {
        this.Title = Title;
        this.Photographer = Photographer;
        this.People = People;
        this.Details = Details;
        this.YearTaken = YearTaken;
    }

    // Constructor (Year)
    public LibraryItem (int YearTaken)
    {
        this.Title = "Untitled";
        this.Author = "Unknown";
        this.YearTaken = YearTaken;
    }

    public void AddPerson(String Person)
    {
        this.People.add(Person);
    }

    //Remove the Person or atleast try to
    public void RemovePerson(String Person)
    {
        this.People.remove(Person);
    }

    //Get the ArrayList
    public ArrayList<String> GetPeople()
    {
        return this.People;
    }

    //Add a Detail
    public void AddDetail(String Detail)
    {
        this.Details.add(Detail);
    }

    //Remove the Detail or atleast try to
    public void RemoveDetail(String Detail)
    {
        this.Details.remove(Detail);
    }

    //Get the ArrayList
    public ArrayList<String> GetDetails()
    {
        return this.Details;
    }

    //Show all the data
    public void showData()
    {
        /*
            public String Title;
            public String Author;
            public ArrayList<String> People = new ArrayList<String>();
            public ArrayList<String> Details = new ArrayList<String>();
            public int YearTaken;
         */

        System.out.println("Name: " + Title);
        System.out.println("Taken by: " + Author);
        System.out.println("Taken on: " + YearTaken);
        if(!People.isEmpty())
        {
            System.out.println("People in the photo");
            for (String Person : People)
            {
                System.out.println(Person);
            }
        }
        if(!Details.isEmpty())
        {
            System.out.println("Details about the photo");
            for (String Detail : Details)
            {
                System.out.println(Detail);
            }
        }
    }

    public static void main(String[] args)
    {
        LibraryItem LI = new LibraryItem(2010);
        LI.Title = "Woot";
        LI.Author = "yoko";
        LI.showData();
    }
}

Q3 take a class from the bluej shapes projects and convert it so that it works standalone without bluej context you may need to take more then one class

you will need to code a main method
you may need to code inputs to constructors using joptionpane class methods

public class Circle
{
    private int diameter;
    private int xPosition;
    private int yPosition;
    private String color;
    private boolean isVisible;
    public Circle()
    {
        diameter = 30;
        xPosition = 20;
        yPosition = 60;
        color = "blue";
        isVisible = false;
    }
/Make visible
/
    public void makeVisible()
    {
        isVisible = true;
        draw();
    }
    /Make invisible
        /
    public void makeInvisible()
    {
        erase();
        isVisible = false;
    }
/Move circle up.
/
    public void moveUp()
    {
        moveVertical(-20);
    }
    /Move circle down.
    /
    public void moveDown()
    {
        moveVertical(20);
    }
    public void moveRight()
    {
        moveHorizontal(20);
    }
/Move circle left.
/
    public void moveLeft()
    {
        moveHorizontal(-20);
    }
/Move circle horizontally 
/
    public void moveHorizontal(int distance)
    {
        erase();
        xPosition += distance;
        draw();
    }
/Move vertically
/
    public void moveVertical(int distance)
    {
        erase();
        yPosition += distance;
        draw();
    }
/move horizontally slow
/
    public void slowMoveHorizontal(int distance)
    {
        int delta;

        if(distance < 0) 
        {
            delta = -1;
            distance = -distance;
        }
        else 
        {
            delta = 1;
        }

        for(int i = 0; i < distance; i++)
        {
            xPosition += delta;
            draw();
        }
    }
/move vertically slow
/
    public void slowMoveVertical(int distance)
    {
        int delta;

        if(distance < 0) 
        {
            delta = -1;
            distance = -distance;
        }
        else 
        {
            delta = 1;
        }

        for(int i = 0; i < distance; i++)
        {
            yPosition += delta;
            draw();
        }
    }
/Change size 
/
    public void changeSize(int newDiameter)
    {
        erase();
        diameter = newDiameter;
        draw();
    }
/Change color
/
    public void changeColor(String newColor)
    {
        color = newColor;
        draw();
    }
    private void draw()
    {
        if(isVisible) {
            Canvas canvas = Canvas.getCanvas();
            canvas.draw(this, color, new Ellipse2D.Double(xPosition, yPosition, 
                                                          diameter, diameter));
            canvas.wait(10);
        }
    }

/deletes circle
/
    private void erase()
    {
        if(isVisible) {
            Canvas canvas = Canvas.getCanvas();
            canvas.erase(this);
        }
    }
}

Recommended Answers

All 2 Replies

Please use the correct code taga for you code. See the icon above text field to right.

What are your questions or problems?
If there are errors, please copy and paste here the full text of the error messages.

So the problem is not with your code, but that you can't get a screen shot in Vista?

Sorry, can't help you there. Have you tried a Windows forum?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.