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.
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...
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/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...
In C Program #include Create a C program that calculates the gross and net pay given...
In C Program #include Create a C program that calculates the gross and net pay given a user-specified number of hours worked, at minimum wage. The program should compile without any errors or warnings (e.g., syntax errors) The program should not contain logical errors such as subtracting values when you meant to add (e.g., logical errors) The program should not crash when running (e.g., runtime errors) When you run the program, the output should look like this: Hours per Week:...
Create the pseudocode solution to a program that calculates the final score and letter grade for...
Create the pseudocode solution to a program that calculates the final score and letter grade for one student. Please use the following grading system: 9 Homework Assignments – 100 points each 10 points 11 Quizzes – 100 points each 5 points 5 Projects – 100 points each 10 points 6 Discussion posts – 100 points each 10 points 4 Exams – 100 points each 65 points A = 90 – 100% B = 80 – 89% C = 70 –...
Modify the provided code to create a program that calculates the amount of change given to...
Modify the provided code to create a program that calculates the amount of change given to a customer based on their total. The program prompts the user to enter an item choice, quantity, and payment amount. Use three functions: • bool isValidChoice(char) – Takes the user choice as an argument, and returns true if it is a valid selection. Otherwise it returns false. • float calcTotal(int, float) – Takes the item cost and the quantity as arguments. Calculates the subtotal,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT