Question

In: Computer Science

In java. Prefer Bluej Create a program in java that calculates area and perimeter of a...

In java. Prefer Bluej

Create a program in java that calculates area and perimeter of a square - use a class and test program to calculate the area and perimeter; assume length of square is 7 ft.

Solutions

Expert Solution

//save this in Square.java

class Square
{
int side;
Square(int s){
side=s;
}
//method to return area of Square
int area(){
return side*side;
}
  
int perimeter(){
return 4*side;
}
}

//Save it in Main.java

//Main class to create object of Square class and call area and perimeter methods

public class Main{
public static void main(String[] args){
Square obj=new Square(7);//create a square with side=7
System.out.println("Area of square : "+obj.area());
System.out.println("Perimeter of square : "+obj.perimeter());
}
}


Related Solutions

Create a program in java that calculates area and perimeter of a square - use a...
Create a program in java that calculates area and perimeter of a square - use a class and test program to calculate the area and perimeter; assume length of square is 7 ft.
I need to make JAVA program that calculates the area of a brick of a specific...
I need to make JAVA program that calculates the area of a brick of a specific color. I have class Brick with the following UML: String color int number int length int width I made methods: getColor(), getNumber(), getLength(), getWidth() in the class Brick So it starts like this: ##### public Brick(String color, int number, int length, int width) { this.color = color; this.number = number; this.length = length; this.width = width;    }   public String toString() {   return number...
java create a class for triangle and also driver(area and perimeter) also write its getters and...
java create a class for triangle and also driver(area and perimeter) also write its getters and setters for the right triangle
Write a program in Java and run it in BlueJ according to the following specifications: The...
Write a program in Java and run it in BlueJ according to the following specifications: The program reads a text file with student records (first name, last name and grade on each line) and determines their type (excellent or ok). Then it prompts the user to enter a command, executes the command and loops. The commands are the following: "all" - prints all student records (first name, last name, grade, type). "excellent" - prints students with grade > 89. "ok"...
rite a program that will calculate the perimeter and area of a rectangle. Prompt the user...
rite a program that will calculate the perimeter and area of a rectangle. Prompt the user to input the length and width. Calculate the area as length * width. Calculate the perimeter as 2* length + 2* width. Display the area and perimeter. Please use a proper heading in a comment block (name, date, description of the program). Please use comments in your code. Run your program twice using different input. Copy the output and place it at the bottom...
Create a JavaFX program in java that does the following items: Display a drawing area of...
Create a JavaFX program in java that does the following items: Display a drawing area of dimension 500 x 400, with a black background. Provides a radio button group to allow the user to select one of the following three colors: red, green, and blue. Upon startup, the red radio button should be selected. Each time the user clicks in the drawing area, a circle of size 10 of the color selected by the radio button group in item 2...
Write a Java program that calculates a random number 1 through 100. The program then asks...
Write a Java program that calculates a random number 1 through 100. The program then asks the user to guess the number.If the user guesses too high or too low then the program should output "too high" or "too low" accordingly.The program must let the user continue to guess until the user correctly guesses the number. ★Modify the program to output how many guesses it took the user to correctly guess the right number
IN JAVA Write a program that calculates the occupancy rate for each floor of a hotel....
IN JAVA Write a program that calculates the occupancy rate for each floor of a hotel. (Use a sentinel value and please point out the sentinel in bold.) The program should start by asking for the number of floors in the hotel. A loop should then iterate once for each floor. During each iteration, the loop should ask the user for the number of rooms on the floor and the number of them that are occupied. After all the iterations,...
Write a java program that calculates a speeding fine. The user is prompted for the speed...
Write a java program that calculates a speeding fine. The user is prompted for the speed of the vehicle, the posted speed limit and if the offence took place in the construction zone. The fine is calculated at $75 + 3$/ km over the speed limit for the first 20km over + $6 / km for the next 20 and $9/km after that. If the posted limit is 40km, the fine is doubled. If the offence took place in a...
(Write/read data) Write a Program in BlueJ to create a file name Excersise12_15.txt if it does...
(Write/read data) Write a Program in BlueJ to create a file name Excersise12_15.txt if it does not exist. Write 100 integers created randomly into the file using text I/O. Integers are separated by spaces in the file. Read data back from the file and display the data in increasing order. After writing the file to disk, the input file should be read into an array, sorted using the static Arrays.sort() method from the Java API and then displayed in the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT