Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am sorry I am so frustrated with this assignment. The images above are all the

ID: 3803961 • Letter: I

Question

I am sorry I am so frustrated with this assignment. The images above are all the instructions the Professor gave me. All I know is that I must use an array and arrayList and must take in 2 numbers to determine how many things in the array and array List that I draw. I have to have at least 5 or 6 java files for this assingment( which contains projectMain.java, setup.java, cityclass.java, object1.java, object2.java and maybe object3.java). I currently have done the following code. I am crying for this project. Please help me. Thank you very much.

import java.util.*;
import java.awt.*;
import javax.swing.*;

I have a projectMain.java as follow:

public class assignment2Main
{
public static void main(String[]args)
{
JFrame frame=new JFrame("My City");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new setup());
frame.pack();
frame.setVisible(true);
}
}

The following is my setUp.java(Which contains a constructor, a internal class drawingPanel, a buttonListener)

public class setup extends JPanel
{
private JButton draw;
private JTextField howMany1, howMany2;
private DrawingPanel drawingPanel;
private City myCity;

setup(){
setLayout(new BorderLayout());
JLabel label1=new JLabel("How many stars would you like to draw?");
howMany1=new JTextField(20);
JLabel label2=new JLabel("How many people would you like to draw?");
howMany2=new JTextField(20);
draw=new JButton("Draw picture");
JPanel buttonPanel=new JPanel();
add(buttonPanel,BorderLayout.WEST);
buttonPanel.setLayout(new FlowLayout());
buttonPanel.add(label1);
buttonPanel.add(howMany1);
buttonPanel.add(label2);
buttonPanel.add(howMany2);
buttonPanel.add(draw);

drawingPanel=new DrawingPanel(800,600);
add(drawingPanel,BorderLayout.CENTER);
buttonPanel.setPreferredSize(new Dimension(300,100));
draw.addActionListener(new buttonListener());
}



private class DrawingPanel extends JPanel
{
private int width;
private int height;
private DrawingPanel(int width, int height)
{
this.width=width;
this.height=height;
setPreferredSize(new Dimension(width,height));
myCity=new city();
}
private void setHowMany(int number, int number2)
{
if(number<1)
number=1;
if(number2<1)
number2=1;
myCity.createStars(number);
myCity.createPeople(number);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2=(Graphics2D)g;
myCity.drawCity(g2);
}
}
private class buttonListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
int num=Integer.parseInt(howMany1.getText());
int num2=Interger.parseInt(howMany2.getText());
drawingPanel.setHowMany(num,num2);
drawingPanel.repaint();
}
}
}

My main problem are the Drawingclass.java part and the creating objects.java(which I have no idea how to do it. Please please help me. Thank you so much.) The following are parts of my code.

The following part is city.java.

public class City
{
ArrayList<star>starList;
stickFigure[]peopleList;
City()
{
starList=new ArrayList<star>();
people=new stickFigure[1];
int x=0;
int y=0;
// star temp=new star(x,y, width, height);
//starList.add(temp);
stickFigure temp=new stickFigure(x,y);
peopList[0]=temp;
people[0].drawStickFigur(g);
}
public void createStars(int number)
{
Random r=new Random();
for(i=0; i<number; i++)
{
int x=r.nextInt(700);
int y=r.nextInt(20);
width=r.nextInt(5);
height=r.nextInt(5);
star temp=new star(x,y,width,height);
starList.add(temp);
}
}
public void createPeople(int number)
{
peopleList =new stickFigure[number];
Random r=new random();
for(int i=0; i<number; i++)
{
int x=r.nextInt(800);
int y=r.nextInt(10)+580;
stickFigure temp=new stickFigure(x,y);
peopleList.add(temp);
}
}
public void drawCity(Graphics dlh)
{
for(int i=0; i<starList.size(); i++)
starList.get(i).drawStar(dlh);
dlh.setColor(Color.random);
building(dlh,10,50,100,500,Color.Black);
building(dlh,110,200,150,350,Color.White);
building(dlh,10,50,100,500,Color.Black);

(I have not finish this part. )
for(int j=0;j<peopleList.length;j++)
peopleList.get(j).drawStickFigure(dlh);

}
public void building(Graphics dlh, int x, int y, int width, int height, Color color)
{
}
}

The following part is StickFigure.java

public class stickFigure
{
private int x;
private int y;
private Color color;
stickFigure(int xx, int yy)
{
x=xx;
y=yy;
int red=(int)(Math.random()*255)+1;
int green=(int)(Math.random()*255)+1;
int blue=(int)(Math.random()*255)+1;
color=new Color(red,green,blue);
}
public void drawStickFigure(Graphics g)
{
Graphics2D g2=(Graphics2D)g;
g2.setColor(color);
g2.setStroke(new BasicStroke(5));
g2.drawLine(140,575,150,550);
g2.drawLine(160,575,150,550);
g2.drawLine(150,520,150,550);
g2.drawOval(140,500,20,20);
g2.drawLine(125,520,150,530);
g2.drawLine(175,520,150,530);

}
}

I have not started the star.java .

Would you please help me correcte my code and add one or two more objects(i.e.a moon in the sky). Thank you so much!

Go to Outside Assignments Upload the Project 1 zipped file Guerrero

Explanation / Answer

import java.util.*;
import java.awt.*;
import javax.swing.*;

I have a projectMain.java as follow:

public class assignment2Main
{
public static void main(String[]args)
{
JFrame frame=new JFrame("My City");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new setup());
frame.pack();
frame.setVisible(true);
}
}

The following is my setUp.java(Which contains a constructor, a internal class drawingPanel, a buttonListener)

public class setup extends JPanel
{
private JButton draw;
private JTextField howMany1, howMany2;
private DrawingPanel drawingPanel;
private City myCity;

setup(){
setLayout(new BorderLayout());
JLabel label1=new JLabel("How many stars would you like to draw?");
howMany1=new JTextField(20);
JLabel label2=new JLabel("How many people would you like to draw?");
howMany2=new JTextField(20);
draw=new JButton("Draw picture");
JPanel buttonPanel=new JPanel();
add(buttonPanel,BorderLayout.WEST);
buttonPanel.setLayout(new FlowLayout());
buttonPanel.add(label1);
buttonPanel.add(howMany1);
buttonPanel.add(label2);
buttonPanel.add(howMany2);
buttonPanel.add(draw);

drawingPanel=new DrawingPanel(800,600);
add(drawingPanel,BorderLayout.CENTER);
buttonPanel.setPreferredSize(new Dimension(300,100));
draw.addActionListener(new buttonListener());
}



private class DrawingPanel extends JPanel
{
private int width;
private int height;
private DrawingPanel(int width, int height)
{
this.width=width;
this.height=height;
setPreferredSize(new Dimension(width,height));
myCity=new city();
}
private void setHowMany(int number, int number2)
{
if(number<1)
number=1;
if(number2<1)
number2=1;
myCity.createStars(number);
myCity.createPeople(number);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2=(Graphics2D)g;
myCity.drawCity(g2);
}
}
private class buttonListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
int num=Integer.parseInt(howMany1.getText());
int num2=Interger.parseInt(howMany2.getText());
drawingPanel.setHowMany(num,num2);
drawingPanel.repaint();
}
}
}

My main problem are the Drawingclass.java part and the creating objects.java(which I have no idea how to do it. Please please help me. Thank you so much.) The following are parts of my code.

The following part is city.java.

public class City
{
ArrayList<star>starList;
stickFigure[]peopleList;
City()
{
starList=new ArrayList<star>();
people=new stickFigure[1];
int x=0;
int y=0;
// star temp=new star(x,y, width, height);
//starList.add(temp);
stickFigure temp=new stickFigure(x,y);
peopList[0]=temp;
people[0].drawStickFigur(g);
}
public void createStars(int number)
{
Random r=new Random();
for(i=0; i<number; i++)
{
int x=r.nextInt(700);
int y=r.nextInt(20);
width=r.nextInt(5);
height=r.nextInt(5);
star temp=new star(x,y,width,height);
starList.add(temp);
}
}
public void createPeople(int number)
{
peopleList =new stickFigure[number];
Random r=new random();
for(int i=0; i<number; i++)
{
int x=r.nextInt(800);
int y=r.nextInt(10)+580;
stickFigure temp=new stickFigure(x,y);
peopleList.add(temp);
}
}
public void drawCity(Graphics dlh)
{
for(int i=0; i<starList.size(); i++)
starList.get(i).drawStar(dlh);
dlh.setColor(Color.random);
building(dlh,10,50,100,500,Color.Black);
building(dlh,110,200,150,350,Color.White);
building(dlh,10,50,100,500,Color.Black);

(I have not finish this part. )
for(int j=0;j<peopleList.length;j++)
peopleList.get(j).drawStickFigure(dlh);

}
public void building(Graphics dlh, int x, int y, int width, int height, Color color)
{
}
}

The following part is StickFigure.java

public class stickFigure
{
private int x;
private int y;
private Color color;
stickFigure(int xx, int yy)
{
x=xx;
y=yy;
int red=(int)(Math.random()*255)+1;
int green=(int)(Math.random()*255)+1;
int blue=(int)(Math.random()*255)+1;
color=new Color(red,green,blue);
}
public void drawStickFigure(Graphics g)
{
Graphics2D g2=(Graphics2D)g;
g2.setColor(color);
g2.setStroke(new BasicStroke(5));
g2.drawLine(140,575,150,550);
g2.drawLine(160,575,150,550);
g2.drawLine(150,520,150,550);
g2.drawOval(140,500,20,20);
g2.drawLine(125,520,150,530);
g2.drawLine(175,520,150,530);

}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote