SlideShare a Scribd company logo
1 of 7
Download to read offline
I need help on this 5 and 6.
here is the code so far:
import javax.swing.*;
import java.awt.*;
import java.util.*;
/**
* !!! Put in description of your program here !!!
*
* @author !!! your name here !!!
*
*/
public class AngryBirds extends JPanel
{
/**
* Here are some variables you are likely to find useful. I have created
* this variables outside of any method, so that they are available to all
* the methods.
*
* (Typically instance variables like this should be labeled as "public" or
* "private" but I have omitted this designation since you are not familiar
* with the meanings of these terms yet.)
*
* Show care not to create local variables with the same names as these
* ones!
*/
double timeInterval;
double velocity;
double angle;
/**
* paint
*
* Draws the Angry Birds simulation on the graphics window
*
* @param g the Graphics object for the window
*/
public void paint(Graphics g)
{
super.paint(g); // do not edit
// Set background color
Color skyBlueDay = new Color(135, 206, 250);
setBackground(skyBlueDay);
// Draw horizon (ground)
g.setColor(new Color(34, 139, 34)); // Green color for the ground
g.fillRect(0, getHeight() - 50, getWidth(), 50);
// Draw structure (e.g., a wooden block)
g.setColor(new Color(139, 69, 19)); // Brown color for the structure
g.fillRect(200, getHeight() - 100, 80, 80);
// Draw pigs in the structure (green round pigs with happy faces)
g.setColor(Color.GREEN);
// Pig 1
g.fillOval(215, getHeight() - 85, 20, 20); // Head
g.setColor(Color.BLACK); // Pig's features
g.fillArc(220, getHeight() - 80, 6, 6, 180, 180); // Happy mouth
g.fillOval(222, getHeight() - 85, 2, 2); // Left eye
g.fillOval(226, getHeight() - 85, 2, 2); // Right eye
// Pig 2
g.setColor(Color.GREEN);
g.fillOval(235, getHeight() - 85, 20, 20); // Head
g.setColor(Color.BLACK); // Pig's features
g.fillArc(240, getHeight() - 80, 6, 6, 180, 180); // Happy mouth
g.fillOval(242, getHeight() - 85, 2, 2); // Left eye
g.fillOval(246, getHeight() - 85, 2, 2); // Right eye
// Pig 3
g.setColor(Color.GREEN);
g.fillOval(255, getHeight() - 85, 20, 20); // Head
g.setColor(Color.BLACK); // Pig's features
g.fillArc(260, getHeight() - 80, 6, 6, 180, 180); // Happy mouth
g.fillOval(262, getHeight() - 85, 2, 2); // Left eye
g.fillOval(266, getHeight() - 85, 2, 2); // Right eye
// Draw slingshot
g.setColor(new Color(139, 69, 19)); // Brown color for slingshot base
g.fillRect(50, getHeight() - 20, 20, 100); // Slingshot base
// Angry bird (Red bird)
g.setColor(new Color(255, 0, 0)); // Red color for the bird
g.fillOval(30, getHeight() - 50, 40, 40); // Body
g.setColor(Color.BLACK); // Bird's features
g.fillArc(40, getHeight() - 45, 10, 10, 0, -180); // Happy mouth
g.fillOval(35, getHeight() - 50, 8, 8); // Left eye
g.fillOval(45, getHeight() - 50, 8, 8); // Right eye
//put your code here
}//paint
/**
* init
*
* prompts user for information about the simulation
*/
public void init()
{
// prompt user for information
String time = ""; //used to store user input
do
{
time = JOptionPane.showInputDialog("Enter the time interval (>0).");
try
{
timeInterval = Double.parseDouble(time);
}
catch (NumberFormatException e)
{
// Handle invalid input (non-numeric)
timeInterval = -1; // Set to a negative value to trigger the loop
}
} while (timeInterval <= 0);
String velocityStr = "";
boolean validVelocityInput = false;
while (!validVelocityInput)
{
velocityStr = JOptionPane.showInputDialog("Enter the velocity (m/s) (>0).");
if (velocityStr != null && !velocityStr.isEmpty())
{
try
{
velocity = Double.parseDouble(velocityStr);
if (velocity > 0)
{
validVelocityInput = true;
}
else
{
JOptionPane.showMessageDialog(null, "Velocity must be greater than 0.");
}
}
catch (NumberFormatException e)
{
JOptionPane.showMessageDialog(null, "Invalid input. Please enter a numeric
value.");
}
}
else
{
JOptionPane.showMessageDialog(null, "Input cannot be empty. Please enter a value.");
}
}
String angleStr = "";
boolean validAngleInput = false;
while (!validAngleInput)
{
angleStr = JOptionPane.showInputDialog("Enter the angle (radians) (0 <= angle <=
?/2).");
if (angleStr != null && !angleStr.isEmpty())
{
try
{
angle = Double.parseDouble(angleStr);
if (angle >= 0 && angle <= Math.PI / 2)
{
validAngleInput = true;
}
else
{
JOptionPane.showMessageDialog(null, "Angle must be between 0 and ?/2.");
}
}
catch (NumberFormatException e)
{
JOptionPane.showMessageDialog(null, "Invalid input. Please enter a numeric
value.");
}
}
else
{
JOptionPane.showMessageDialog(null, "Input cannot be empty. Please enter a value.");
}
}
}
/**
* This constructor method creates the window for you.
* Do not modify it.
*/
public AngryBirds()
{
super();
}
/**
* main
* This method starts the application. It creates a new AngryBirds object.
* Do not modify this except that you may increase the window size
* up to a maximum of 1000x1000.
*/
public static void main(String[] args)
{
//Create the window
JFrame frame = new JFrame();
frame.setSize(500,500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Gather input from the user
AngryBirds ab = new AngryBirds();
frame.add(ab);
ab.init();
//Display the window
frame.setVisible(true);
frame.repaint();
}
}//class AngryBirds
[30%] Your paint method should use a loop to draw the position of the angry bird at each time
increment while the bird is in the air (y position >=0 ). Your code should honor the user's inputs
in this regard. You may assume no wind resistance. Important: This is not an animation; you'll be
drawing a fixed image. For example, the image at right statically depicts the motion of a circle
moving through an arc. [10%] Your loop should stop drawing the bird once it hits the ground or
the structure. It is okay if it draws the bird at a position that is outside of the window boundary
because it is too high or too far to the right.
ogistics and Hints - The starter code is just a .java file. To use it, you will need to create a new
BlueJ project then create a class named AngryBirds in the project. Finally, replace BlueJ's
default code for the AngryBirds class with the starter code. - Your graphics should be
recognizable but need not be particularly well drawn. They do not need to match the quality of
the actual Angry Birds game. - Since you will need to draw the angry bird in multiple locations,
you will probably want to create a method that can draws the bird at a specified x,y location. -
Below is pseudocode for drawing the arc of the bird's path. This code assumes Cartesian
coordinates (i.e., the y-axis goes up as normal). When painting the bird on the screen, you'll have
to convert the y-value to graphics coordinates (y-axis inverted). 0 Assign x and y-position to the
starting coordinate of the angry bird (the slingshot). o Assign time =0. o Main Loop: While bird
is in the air (y-position is above the ground): - Calculate x-position at the current time:
velocitycos(angle)time - Calculate y-position at the current time: velocity sin( angle) time 0.59.8
time 2 - Update the time by adding the timeInterval to it. - Draw the bird. Don't forget to invert
the y-axis. - If the bird has hit the structure (something you shall have to determine based on
your structure's position and design) then exit the loop. - The sin and cos functions are available
in the Math class. Note that these functions expect angles in radians (not degrees). - Your bird
position calculations should be using doubles, but you will need to convert these to ints to use as
coordinates for drawing. Use a type cast to do this conversion. - Put all your dialog windows in
the init() constructor and all your drawing in the paint() method.

More Related Content

Similar to I need help on this 5 and 6. here is the code so far import jav.pdf

Computer graphics
Computer graphicsComputer graphics
Computer graphicssnelkoli
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Troy Miles
 
Please help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdfPlease help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdfJUSTSTYLISH3B2MOHALI
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchainedEduard Tomàs
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptVisual Engineering
 
05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboardsDenis Ristic
 
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfWorking with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfudit652068
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developersStoyan Stefanov
 
MIS 4310-01 Final Take Home Exam (100 points) DUE Thursd.docx
MIS 4310-01 Final Take Home Exam (100 points) DUE  Thursd.docxMIS 4310-01 Final Take Home Exam (100 points) DUE  Thursd.docx
MIS 4310-01 Final Take Home Exam (100 points) DUE Thursd.docxraju957290
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Ismar Silveira
 
operating system linux,ubuntu,Mac Geometri.pdf
operating system linux,ubuntu,Mac Geometri.pdfoperating system linux,ubuntu,Mac Geometri.pdf
operating system linux,ubuntu,Mac Geometri.pdfaquadreammail
 
Creating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfCreating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfShaiAlmog1
 
I wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdfI wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdffeelinggifts
 

Similar to I need help on this 5 and 6. here is the code so far import jav.pdf (20)

Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1
 
Please help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdfPlease help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdf
 
Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6
 
Casa
CasaCasa
Casa
 
Clock For My
Clock For MyClock For My
Clock For My
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchained
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
 
05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards
 
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfWorking with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
MIS 4310-01 Final Take Home Exam (100 points) DUE Thursd.docx
MIS 4310-01 Final Take Home Exam (100 points) DUE  Thursd.docxMIS 4310-01 Final Take Home Exam (100 points) DUE  Thursd.docx
MIS 4310-01 Final Take Home Exam (100 points) DUE Thursd.docx
 
ES6 - Level up your JavaScript Skills
ES6 - Level up your JavaScript SkillsES6 - Level up your JavaScript Skills
ES6 - Level up your JavaScript Skills
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
 
Open Cv Tutorial Ii
Open Cv Tutorial IiOpen Cv Tutorial Ii
Open Cv Tutorial Ii
 
Open Cv Tutorial Ii
Open Cv Tutorial IiOpen Cv Tutorial Ii
Open Cv Tutorial Ii
 
operating system linux,ubuntu,Mac Geometri.pdf
operating system linux,ubuntu,Mac Geometri.pdfoperating system linux,ubuntu,Mac Geometri.pdf
operating system linux,ubuntu,Mac Geometri.pdf
 
Creating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfCreating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdf
 
Virtual inheritance
Virtual inheritanceVirtual inheritance
Virtual inheritance
 
I wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdfI wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdf
 

More from mail931892

I need help writing test Codepackage org.example;import j.pdf
I need help writing test Codepackage org.example;import j.pdfI need help writing test Codepackage org.example;import j.pdf
I need help writing test Codepackage org.example;import j.pdfmail931892
 
I need a substantive comment on this postThe formal structure of .pdf
I need a substantive comment on this postThe formal structure of .pdfI need a substantive comment on this postThe formal structure of .pdf
I need a substantive comment on this postThe formal structure of .pdfmail931892
 
I need help debugging some code. I am trying to read a text file and.pdf
I need help debugging some code. I am trying to read a text file and.pdfI need help debugging some code. I am trying to read a text file and.pdf
I need help debugging some code. I am trying to read a text file and.pdfmail931892
 
I have these files in picture I wrote most the codes but I stuck wit.pdf
I have these files in picture I wrote most the codes but I stuck wit.pdfI have these files in picture I wrote most the codes but I stuck wit.pdf
I have these files in picture I wrote most the codes but I stuck wit.pdfmail931892
 
I am trying to create a dynamic web project in Eclipse IDE that impl.pdf
I am trying to create a dynamic web project in Eclipse IDE that impl.pdfI am trying to create a dynamic web project in Eclipse IDE that impl.pdf
I am trying to create a dynamic web project in Eclipse IDE that impl.pdfmail931892
 
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfHow do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfmail931892
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfmail931892
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfmail931892
 
how can i build this as problem 2 of my code #include iostream.pdf
how can i build this as problem 2 of my code #include iostream.pdfhow can i build this as problem 2 of my code #include iostream.pdf
how can i build this as problem 2 of my code #include iostream.pdfmail931892
 
Hi All!I have a question regrading creating a subgraph or rather v.pdf
Hi All!I have a question regrading creating a subgraph or rather v.pdfHi All!I have a question regrading creating a subgraph or rather v.pdf
Hi All!I have a question regrading creating a subgraph or rather v.pdfmail931892
 
HeadWallRam Inc. has expanded its reach globally and needs to re-lay.pdf
HeadWallRam Inc. has expanded its reach globally and needs to re-lay.pdfHeadWallRam Inc. has expanded its reach globally and needs to re-lay.pdf
HeadWallRam Inc. has expanded its reach globally and needs to re-lay.pdfmail931892
 
Help I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfHelp I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfmail931892
 
For this part you will need to analyze the provided logfile part2.lo.pdf
For this part you will need to analyze the provided logfile part2.lo.pdfFor this part you will need to analyze the provided logfile part2.lo.pdf
For this part you will need to analyze the provided logfile part2.lo.pdfmail931892
 
Ginny (45) is unmarried. Who of the following may be Ginnys quali.pdf
Ginny (45) is unmarried. Who of the following may be Ginnys quali.pdfGinny (45) is unmarried. Who of the following may be Ginnys quali.pdf
Ginny (45) is unmarried. Who of the following may be Ginnys quali.pdfmail931892
 

More from mail931892 (14)

I need help writing test Codepackage org.example;import j.pdf
I need help writing test Codepackage org.example;import j.pdfI need help writing test Codepackage org.example;import j.pdf
I need help writing test Codepackage org.example;import j.pdf
 
I need a substantive comment on this postThe formal structure of .pdf
I need a substantive comment on this postThe formal structure of .pdfI need a substantive comment on this postThe formal structure of .pdf
I need a substantive comment on this postThe formal structure of .pdf
 
I need help debugging some code. I am trying to read a text file and.pdf
I need help debugging some code. I am trying to read a text file and.pdfI need help debugging some code. I am trying to read a text file and.pdf
I need help debugging some code. I am trying to read a text file and.pdf
 
I have these files in picture I wrote most the codes but I stuck wit.pdf
I have these files in picture I wrote most the codes but I stuck wit.pdfI have these files in picture I wrote most the codes but I stuck wit.pdf
I have these files in picture I wrote most the codes but I stuck wit.pdf
 
I am trying to create a dynamic web project in Eclipse IDE that impl.pdf
I am trying to create a dynamic web project in Eclipse IDE that impl.pdfI am trying to create a dynamic web project in Eclipse IDE that impl.pdf
I am trying to create a dynamic web project in Eclipse IDE that impl.pdf
 
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfHow do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
 
how can i build this as problem 2 of my code #include iostream.pdf
how can i build this as problem 2 of my code #include iostream.pdfhow can i build this as problem 2 of my code #include iostream.pdf
how can i build this as problem 2 of my code #include iostream.pdf
 
Hi All!I have a question regrading creating a subgraph or rather v.pdf
Hi All!I have a question regrading creating a subgraph or rather v.pdfHi All!I have a question regrading creating a subgraph or rather v.pdf
Hi All!I have a question regrading creating a subgraph or rather v.pdf
 
HeadWallRam Inc. has expanded its reach globally and needs to re-lay.pdf
HeadWallRam Inc. has expanded its reach globally and needs to re-lay.pdfHeadWallRam Inc. has expanded its reach globally and needs to re-lay.pdf
HeadWallRam Inc. has expanded its reach globally and needs to re-lay.pdf
 
Help I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfHelp I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdf
 
For this part you will need to analyze the provided logfile part2.lo.pdf
For this part you will need to analyze the provided logfile part2.lo.pdfFor this part you will need to analyze the provided logfile part2.lo.pdf
For this part you will need to analyze the provided logfile part2.lo.pdf
 
Ginny (45) is unmarried. Who of the following may be Ginnys quali.pdf
Ginny (45) is unmarried. Who of the following may be Ginnys quali.pdfGinny (45) is unmarried. Who of the following may be Ginnys quali.pdf
Ginny (45) is unmarried. Who of the following may be Ginnys quali.pdf
 

Recently uploaded

UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfNirmal Dwivedi
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111GangaMaiya1
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Celine George
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use CasesTechSoup
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonhttgc7rh9c
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17Celine George
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 

Recently uploaded (20)

Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 

I need help on this 5 and 6. here is the code so far import jav.pdf

  • 1. I need help on this 5 and 6. here is the code so far: import javax.swing.*; import java.awt.*; import java.util.*; /** * !!! Put in description of your program here !!! * * @author !!! your name here !!! * */ public class AngryBirds extends JPanel { /** * Here are some variables you are likely to find useful. I have created * this variables outside of any method, so that they are available to all * the methods. * * (Typically instance variables like this should be labeled as "public" or * "private" but I have omitted this designation since you are not familiar * with the meanings of these terms yet.) * * Show care not to create local variables with the same names as these * ones! */ double timeInterval; double velocity; double angle; /** * paint * * Draws the Angry Birds simulation on the graphics window * * @param g the Graphics object for the window */
  • 2. public void paint(Graphics g) { super.paint(g); // do not edit // Set background color Color skyBlueDay = new Color(135, 206, 250); setBackground(skyBlueDay); // Draw horizon (ground) g.setColor(new Color(34, 139, 34)); // Green color for the ground g.fillRect(0, getHeight() - 50, getWidth(), 50); // Draw structure (e.g., a wooden block) g.setColor(new Color(139, 69, 19)); // Brown color for the structure g.fillRect(200, getHeight() - 100, 80, 80); // Draw pigs in the structure (green round pigs with happy faces) g.setColor(Color.GREEN); // Pig 1 g.fillOval(215, getHeight() - 85, 20, 20); // Head g.setColor(Color.BLACK); // Pig's features g.fillArc(220, getHeight() - 80, 6, 6, 180, 180); // Happy mouth g.fillOval(222, getHeight() - 85, 2, 2); // Left eye g.fillOval(226, getHeight() - 85, 2, 2); // Right eye // Pig 2 g.setColor(Color.GREEN); g.fillOval(235, getHeight() - 85, 20, 20); // Head g.setColor(Color.BLACK); // Pig's features g.fillArc(240, getHeight() - 80, 6, 6, 180, 180); // Happy mouth g.fillOval(242, getHeight() - 85, 2, 2); // Left eye g.fillOval(246, getHeight() - 85, 2, 2); // Right eye // Pig 3 g.setColor(Color.GREEN); g.fillOval(255, getHeight() - 85, 20, 20); // Head
  • 3. g.setColor(Color.BLACK); // Pig's features g.fillArc(260, getHeight() - 80, 6, 6, 180, 180); // Happy mouth g.fillOval(262, getHeight() - 85, 2, 2); // Left eye g.fillOval(266, getHeight() - 85, 2, 2); // Right eye // Draw slingshot g.setColor(new Color(139, 69, 19)); // Brown color for slingshot base g.fillRect(50, getHeight() - 20, 20, 100); // Slingshot base // Angry bird (Red bird) g.setColor(new Color(255, 0, 0)); // Red color for the bird g.fillOval(30, getHeight() - 50, 40, 40); // Body g.setColor(Color.BLACK); // Bird's features g.fillArc(40, getHeight() - 45, 10, 10, 0, -180); // Happy mouth g.fillOval(35, getHeight() - 50, 8, 8); // Left eye g.fillOval(45, getHeight() - 50, 8, 8); // Right eye //put your code here }//paint /** * init * * prompts user for information about the simulation */ public void init() { // prompt user for information String time = ""; //used to store user input do { time = JOptionPane.showInputDialog("Enter the time interval (>0)."); try { timeInterval = Double.parseDouble(time); } catch (NumberFormatException e)
  • 4. { // Handle invalid input (non-numeric) timeInterval = -1; // Set to a negative value to trigger the loop } } while (timeInterval <= 0); String velocityStr = ""; boolean validVelocityInput = false; while (!validVelocityInput) { velocityStr = JOptionPane.showInputDialog("Enter the velocity (m/s) (>0)."); if (velocityStr != null && !velocityStr.isEmpty()) { try { velocity = Double.parseDouble(velocityStr); if (velocity > 0) { validVelocityInput = true; } else { JOptionPane.showMessageDialog(null, "Velocity must be greater than 0."); } } catch (NumberFormatException e) { JOptionPane.showMessageDialog(null, "Invalid input. Please enter a numeric value."); } } else { JOptionPane.showMessageDialog(null, "Input cannot be empty. Please enter a value."); } }
  • 5. String angleStr = ""; boolean validAngleInput = false; while (!validAngleInput) { angleStr = JOptionPane.showInputDialog("Enter the angle (radians) (0 <= angle <= ?/2)."); if (angleStr != null && !angleStr.isEmpty()) { try { angle = Double.parseDouble(angleStr); if (angle >= 0 && angle <= Math.PI / 2) { validAngleInput = true; } else { JOptionPane.showMessageDialog(null, "Angle must be between 0 and ?/2."); } } catch (NumberFormatException e) { JOptionPane.showMessageDialog(null, "Invalid input. Please enter a numeric value."); } } else { JOptionPane.showMessageDialog(null, "Input cannot be empty. Please enter a value."); } } } /** * This constructor method creates the window for you.
  • 6. * Do not modify it. */ public AngryBirds() { super(); } /** * main * This method starts the application. It creates a new AngryBirds object. * Do not modify this except that you may increase the window size * up to a maximum of 1000x1000. */ public static void main(String[] args) { //Create the window JFrame frame = new JFrame(); frame.setSize(500,500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Gather input from the user AngryBirds ab = new AngryBirds(); frame.add(ab); ab.init(); //Display the window frame.setVisible(true); frame.repaint(); } }//class AngryBirds [30%] Your paint method should use a loop to draw the position of the angry bird at each time increment while the bird is in the air (y position >=0 ). Your code should honor the user's inputs in this regard. You may assume no wind resistance. Important: This is not an animation; you'll be drawing a fixed image. For example, the image at right statically depicts the motion of a circle moving through an arc. [10%] Your loop should stop drawing the bird once it hits the ground or the structure. It is okay if it draws the bird at a position that is outside of the window boundary
  • 7. because it is too high or too far to the right. ogistics and Hints - The starter code is just a .java file. To use it, you will need to create a new BlueJ project then create a class named AngryBirds in the project. Finally, replace BlueJ's default code for the AngryBirds class with the starter code. - Your graphics should be recognizable but need not be particularly well drawn. They do not need to match the quality of the actual Angry Birds game. - Since you will need to draw the angry bird in multiple locations, you will probably want to create a method that can draws the bird at a specified x,y location. - Below is pseudocode for drawing the arc of the bird's path. This code assumes Cartesian coordinates (i.e., the y-axis goes up as normal). When painting the bird on the screen, you'll have to convert the y-value to graphics coordinates (y-axis inverted). 0 Assign x and y-position to the starting coordinate of the angry bird (the slingshot). o Assign time =0. o Main Loop: While bird is in the air (y-position is above the ground): - Calculate x-position at the current time: velocitycos(angle)time - Calculate y-position at the current time: velocity sin( angle) time 0.59.8 time 2 - Update the time by adding the timeInterval to it. - Draw the bird. Don't forget to invert the y-axis. - If the bird has hit the structure (something you shall have to determine based on your structure's position and design) then exit the loop. - The sin and cos functions are available in the Math class. Note that these functions expect angles in radians (not degrees). - Your bird position calculations should be using doubles, but you will need to convert these to ints to use as coordinates for drawing. Use a type cast to do this conversion. - Put all your dialog windows in the init() constructor and all your drawing in the paint() method.