Diploma in Software Engineering CT619: Week 3 Applet Assignment
VerifiedAdded on  2023/01/12
|8
|1003
|43
Homework Assignment
AI Summary
This assignment solution, submitted by a student for the CT619 Object-Oriented Programming Workshop, presents two Java applet implementations. The first part details the design and code for a dartboard applet, which draws concentric circles and radial lines based on user-defined parameters for the number of lines and the applet's dimensions. The code includes checks to ensure the number of lines falls within specified bounds. The second part of the assignment focuses on creating a flag applet, which displays the Irish flag and a tennis ball. The solution provides the code, design considerations, and a screenshot of the applets. References to external code sources are also included.

Diploma in Software Engineering
Student Name: Alan Burke
NUI Galway ID Number: 04417461
Course: CT619- Object Orientated Programming
Workshop No: Week 03
Assignments: Workshop 3- Questions 1-2
Date of Submission: 31/03/19
Student Name: Alan Burke
NUI Galway ID Number: 04417461
Course: CT619- Object Orientated Programming
Workshop No: Week 03
Assignments: Workshop 3- Questions 1-2
Date of Submission: 31/03/19
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

Table of Contents
Part 1.................................................................................................................................................4
Design................................................................................................................................................4
Design Requirements.........................................................................................................................4
Testing...............................................................................................................................................4
Code:.................................................................................................................................................5
Part 2.................................................................................................................................................6
Design................................................................................................................................................6
Code:.................................................................................................................................................7
Screenshot.........................................................................................................................................8
References.........................................................................................................................................8
Part 1.................................................................................................................................................4
Design................................................................................................................................................4
Design Requirements.........................................................................................................................4
Testing...............................................................................................................................................4
Code:.................................................................................................................................................5
Part 2.................................................................................................................................................6
Design................................................................................................................................................6
Code:.................................................................................................................................................7
Screenshot.........................................................................................................................................8
References.........................................................................................................................................8

Part 1
Design
1. Develop an applet that displays a dartboard pattern like the one shown here, with equally
spaced concentric circles and radial lines. The applet must check the available width and
height, so that the pattern is drawn as large as possible. There should always be three
equally spaced circles, but the number of lines must be specified by a parameter in the
Design
1. Develop an applet that displays a dartboard pattern like the one shown here, with equally
spaced concentric circles and radial lines. The applet must check the available width and
height, so that the pattern is drawn as large as possible. There should always be three
equally spaced circles, but the number of lines must be specified by a parameter in the
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

HTML file. The number of lines should be between 2 and 30, and should default to 20 if
outside of these limits.
Design Requirements
ï‚· Get the Height and Width parameters, check to see which is the smallest and this will be the
diameter
ï‚· Draw circle using this Diameter, repeat using 1/3 of this diameter, and using 2/3 of this
diameter.
ï‚· Get the number of lines, check to ensure these are within the defined parameters of 2 and
30 inclusive, if not set to 20
ï‚· Find the number of points on the circle (Lines *2)
ï‚· Derive the angle to step through for each point (360/the number of points)
ï‚· Loop to run for each number of points
ï‚· Get the line angle in radians = (angle* i) * Pi/180
ï‚· Get the X coordinate of the point (Radius * Cos (Radians))
ï‚· Get Y coordinate (Radius * Sin (Radians))
ï‚· Draw line ((X + Radius), (y+Radius) (x centre), (y centre))
Testing
outside of these limits.
Design Requirements
ï‚· Get the Height and Width parameters, check to see which is the smallest and this will be the
diameter
ï‚· Draw circle using this Diameter, repeat using 1/3 of this diameter, and using 2/3 of this
diameter.
ï‚· Get the number of lines, check to ensure these are within the defined parameters of 2 and
30 inclusive, if not set to 20
ï‚· Find the number of points on the circle (Lines *2)
ï‚· Derive the angle to step through for each point (360/the number of points)
ï‚· Loop to run for each number of points
ï‚· Get the line angle in radians = (angle* i) * Pi/180
ï‚· Get the X coordinate of the point (Radius * Cos (Radians))
ï‚· Get Y coordinate (Radius * Sin (Radians))
ï‚· Draw line ((X + Radius), (y+Radius) (x centre), (y centre))
Testing
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

Code:
Note: Used Code Samples from Deitel and Deitel SwitchTest.java
//Alan Burke-04417461//
//Week 3 Dartboard Applet//
import java.awt.Graphics;
import javax.swing.JApplet;
public class Dartboard extends JApplet {
int Diameter;
int NumberPoints;
int inputlines;
double angle;
public void init() {
final int input = Integer.parseInt(getParameter("Width"));
final int Lines = Integer.parseInt(getParameter("Lines"));
Diameter = input;
inputlines = Lines;
}
// draw shapes on applet's background
public void paint(Graphics g) {
super.paint(g); // call paint method inherited from JApplet
Note: Used Code Samples from Deitel and Deitel SwitchTest.java
//Alan Burke-04417461//
//Week 3 Dartboard Applet//
import java.awt.Graphics;
import javax.swing.JApplet;
public class Dartboard extends JApplet {
int Diameter;
int NumberPoints;
int inputlines;
double angle;
public void init() {
final int input = Integer.parseInt(getParameter("Width"));
final int Lines = Integer.parseInt(getParameter("Lines"));
Diameter = input;
inputlines = Lines;
}
// draw shapes on applet's background
public void paint(Graphics g) {
super.paint(g); // call paint method inherited from JApplet

g.drawOval(0, 0,
Diameter, Diameter);
g.drawOval(((Diameter / 2) / 3), ((Diameter / 2) / 3),
((Diameter / 3) * 2), ((Diameter / 3) * 2));
// done processing case
g.drawOval((((Diameter / 2) / 3) * 2), (((Diameter / 2) / 3) * 2),
(Diameter / 3), (Diameter / 3));
//check if the number of passed lines is within the bounds of the
requirements
if (inputlines < 2 || inputlines > 30) {
NumberPoints = 20;
} else {
NumberPoints = inputlines;
}
//find the angle that is to be used for the lines
angle = 360 / (double) NumberPoints;
int i; //for loop statement
int x; // X coordinate
int y; //y coordinate
for (i = 0; i < NumberPoints; i++) {
// find line angle in radians
double w = (angle * i) * Math.PI / 180;
x = (int) ((Diameter / 2) * Math.cos(w));
y = (int) ((Diameter / 2) * Math.sin(w));
g.drawLine(x + (Diameter / 2), y + (Diameter / 2), (Diameter /
2), (Diameter / 2));
}
}
}
//end program//
Part 2
Design
A happy tennis ball at the Ireland game this week.
Diameter, Diameter);
g.drawOval(((Diameter / 2) / 3), ((Diameter / 2) / 3),
((Diameter / 3) * 2), ((Diameter / 3) * 2));
// done processing case
g.drawOval((((Diameter / 2) / 3) * 2), (((Diameter / 2) / 3) * 2),
(Diameter / 3), (Diameter / 3));
//check if the number of passed lines is within the bounds of the
requirements
if (inputlines < 2 || inputlines > 30) {
NumberPoints = 20;
} else {
NumberPoints = inputlines;
}
//find the angle that is to be used for the lines
angle = 360 / (double) NumberPoints;
int i; //for loop statement
int x; // X coordinate
int y; //y coordinate
for (i = 0; i < NumberPoints; i++) {
// find line angle in radians
double w = (angle * i) * Math.PI / 180;
x = (int) ((Diameter / 2) * Math.cos(w));
y = (int) ((Diameter / 2) * Math.sin(w));
g.drawLine(x + (Diameter / 2), y + (Diameter / 2), (Diameter /
2), (Diameter / 2));
}
}
}
//end program//
Part 2
Design
A happy tennis ball at the Ireland game this week.
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

Code:
//Alan Burke-04417461//
//Flag and Ball//
import java.awt.*;
import java.awt.Event.*;
import javax.swing.*;
public class Flag extends JPanel {
public static void main(String[] args){
JFrame f = new JFrame("Flag");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Flag fl = new Flag();
fl.setBackground(Color.WHITE);
f.add(fl);
f.setSize(500, 270);
f.setVisible(true);
}
public void paintComponent(Graphics g){
super.paintComponent(g);
this.setBackground(Color.WHITE);
g.setColor(Color.GREEN);
g.fill3DRect(10, 10, 100, 50, true);
g.setColor(Color.WHITE);
g.fill3DRect(110, 10, 100, 50, true);
g.setColor(Color.ORANGE);
g.fill3DRect(210, 10, 100, 50, true);
g.setColor(Color.YELLOW);
g.fillOval(100,100,100,100);
g.setColor(Color.BLACK);
g.fillOval(120,125,20,20);
g.fillOval(160,125,20,20);
g.drawLine(150,165,150,150);
g.drawArc(110,106,80,90,-30,-120);
}
}
//Alan Burke-04417461//
//Flag and Ball//
import java.awt.*;
import java.awt.Event.*;
import javax.swing.*;
public class Flag extends JPanel {
public static void main(String[] args){
JFrame f = new JFrame("Flag");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Flag fl = new Flag();
fl.setBackground(Color.WHITE);
f.add(fl);
f.setSize(500, 270);
f.setVisible(true);
}
public void paintComponent(Graphics g){
super.paintComponent(g);
this.setBackground(Color.WHITE);
g.setColor(Color.GREEN);
g.fill3DRect(10, 10, 100, 50, true);
g.setColor(Color.WHITE);
g.fill3DRect(110, 10, 100, 50, true);
g.setColor(Color.ORANGE);
g.fill3DRect(210, 10, 100, 50, true);
g.setColor(Color.YELLOW);
g.fillOval(100,100,100,100);
g.setColor(Color.BLACK);
g.fillOval(120,125,20,20);
g.fillOval(160,125,20,20);
g.drawLine(150,165,150,150);
g.drawArc(110,106,80,90,-30,-120);
}
}
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

Screenshot
References
Part 1
Deitel, P and Deitel, H. (2011) Java How to Program, London: Pearson Education M.U.A.
Part 2
Code Samples:
https://www.javacodex.com/More-Examples/2/10 [accessed 27.3.19]
https://docs.oracle.com/javase/tutorial/uiswing/painting/closer.html [accessed 27.3.19]
https://way2java.com/java-general/java-set-background-color/ [accessed 27.3.19]
References
Part 1
Deitel, P and Deitel, H. (2011) Java How to Program, London: Pearson Education M.U.A.
Part 2
Code Samples:
https://www.javacodex.com/More-Examples/2/10 [accessed 27.3.19]
https://docs.oracle.com/javase/tutorial/uiswing/painting/closer.html [accessed 27.3.19]
https://way2java.com/java-general/java-set-background-color/ [accessed 27.3.19]
1 out of 8

Your All-in-One AI-Powered Toolkit for Academic Success.
 +13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
Copyright © 2020–2025 A2Z Services. All Rights Reserved. Developed and managed by ZUCOL.