Java代写 | Java GUI | Netbeans HW 代写

Homework/HW代写,主要要求使用NetBeans完成一个Java GUI的作业程序编码,程序主要功能是在start code基础上实现绘图功能。

Homework 2 – The Basics of Java – If Statements and Data Types


The aim of this lab is to learn about different variable types, integer arithmetic, and if statements. If very important in Java.

Visual Learners

  • Download Week2Visual rar from ICE. Unpack it into your Netbeans Projects
  • Use File -> Open Project to open
  • Run and play with
  • Open java in Netbeans. Have a look at it, but don’t worry about all the code (it will all make sense in a few weeks!). Scroll down to this section:
  • Change the position on screen where the colour change happens
  • Add more if or else if statements to make four colour bands
  • Add two nested if statements to split the screen into four quarters: top left, top right, bottom left, bottom
  • Try changing the colours. You can create your own colours like this:

Color myColor = new Color(0, 255, 0); graphics.setColor(myColor);

  • Change drawOval to
  • Change the size of the oval/circle
  • Change to drawRect or
  • Enjoy!

Area of a Circle

In your lab this week, you worked on various simple problems. Here, we will solve a real problem, the area of a circle, 𝑎 = 𝜋𝑟! . Comment out your previous code, but do not delete it!

  • Assuming that the radius is 7, use variables to create a calculation. Look at the results of your calculations. Do they match what you expect? If you do not understand, ask a
  • Assume that the radius is defined using the double variable radius, and then write a small program to calculate and display the area of a circle. The console output should look like:
  • Once you have done this, the next thing we wish to do is build a simple if statement to decide if the circle is big enough. IF the area of a circle is greater than a certain threshold, then we want to display an additional message saying it is a big circle, ELSE, we want to say this is a small
  • When you have it working, set the threshold variable to be 50, and experiment with different values of radius. For example, here are two different messages for under and over the limit:

The radius is 3.0

The area is 28.274333882308138

This is a small circle


The radius is 7.0

The area is 153.93804002589985

This is a big circle

  • When you have this working, you have successfully made use of Java to solve a real world calculation, and you created a working IF statement!

Gender switches with Booleans

The very first program you made last week was a “hello” paragraph to describe yourself. The output should look something like:

Hello Andrew Hello Joe

My name is Andrew, and I’m a lecturer in CS

My name is Andrew, my school was Montrose, and my hometown is Arbroath.

Name: Andrew, Age: 32, Student number: 12345678

  • You should also have replaced the individual values with variables, so that you could easily substitute your classmate’s details
System.out.println("Name: "+ yourName +", Age: " +age + ", Student number: " + studNum);
  • The next challenge is that we wish to make this third person, and we should also use a Boolean variable (i.e. true or false) to determine whether to use the male or female. For example, if female = true, then we should see:

Her name is Andrew, and she is a lecturer in CS

  • Whereas if female = false, then we should see His name is Andrew, and he is a lecturer in CS
  • This is challenging, and will require string variables for gender, an If statement, and Boolean variables!

Days of The Week – Multiple Condition If statements

An alternative way to represent the data above is to use the AND (&&) operator, as discussed in the lecture notes. This will prevent confusing nested if statements. This is an extra challenge, to do in your own time!

  • If you have completed your Days of the Week project this week, you should have a series of complex nested if statements, that look like this:
if(condition1 ==true){ if(condition2 == value){

Display output

}   else if(condition2 == value2){ Display output

} else {

No output found


  • You could also represent this if statement with the && operator
if((condition1 ==true) &&(condition2 == value)) { Display output


else if((condition1 ==true) &&(condition2 == value2)) { Display output

} else {

No output found

  • Note that this approach has strengths and weaknesses. Create a copy of your days of the week class, and try to implement your code using multiple operators.
  • Note the use of brackets and the && operator!



本网站支持淘宝 支付宝 微信支付  paypal等等交易。如果不放心可以用淘宝交易!

E-mail: [email protected]  微信:dmxyzl003





本网站支持淘宝 支付宝 微信支付  paypal等等交易。如果不放心可以用淘宝交易!

E-mail: [email protected]  微信:itcsdx