JAVA WithNetBEANs package rubixcup import javautilScanner p

J.A.V.A _ W.i.t.h.Net.B.E.A.N.s

package rubix.cup;

import java.util.Scanner;

public class Main {

public static void main(String args[]) {
System.out.println(\"Welcome to the Area and Perimeter Calculator\");
System.out.println();

Scanner sc = new Scanner(System.in);
String choice = \"y\";
while (choice.equalsIgnoreCase(\"y\")) {
// get input from user
System.out.print(\"Enter length: \");
double length = Double.parseDouble(sc.nextLine());

System.out.print(\"Enter width: \");
double width = Double.parseDouble(sc.nextLine());

Rectangle r = new Rectangle(length, width);
  
// format and display output
String message =
\"Area: \" + r.getAreaNumberFormat() + \"\ \" +
\"Perimeter: \" + r.getPerimeterNumberFormat() + \"\ \";
System.out.println(message);

// see if the user wants to continue
System.out.print(\"Continue? (y/n): \");
choice = sc.nextLine();
System.out.println();
}
System.out.println(\"Bye!\");
}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

package stash.mop;

import java.text.NumberFormat;

public class Rectangle {
  
private double length;
private double width;
  
public Rectangle() {
length = 0;
width = 0;
}

public Rectangle(double length, double width) {
this.length = length;
this.width = width;
}

public double getLength() {
return length;
}

public void setLength(double length) {
this.length = length;
}
  
public double getWidth() {
return width;
}

public void setWidth(double width) {
this.width = width;
}

public double getArea() {
double area = width * length;
return area;
}
  
public String getAreaNumberFormat() {
NumberFormat number = NumberFormat.getNumberInstance();
number.setMinimumFractionDigits(3);
String numberFormatted = number.format(this.getArea());
return numberFormatted;
}
  
public double getPerimeter() {
double perimeter = 2 * width + 2 * length;
return perimeter;
}
  
public String getPerimeterNumberFormat() {
NumberFormat number = NumberFormat.getNumberInstance();
number.setMinimumFractionDigits(3);
String numberFormatted = number.format(this.getPerimeter());
return numberFormatted;
}
}

Complete the requirements Add a class named RectangeIO. . Add the following methods to the RectangleIO class: public static void save (Rectangle r) public static void printFile () . Add code to the save method so that it appends the length, width, area, and perimeter of the specified Rectangle obiect to a file named \'rectangles.txt\" that\'s stored in the root directory of the application. * . Add code to the printFile method that reads each line of the text file for the * In the Main class, add code to the while loop that uses the ProductIO class to . After the code that prints the \"Bye!\" message, add code that uses the * Run the application to make sure it works correctly. If this application has application and prints each line to the console. save the Rectangle obiect. ProductIO class to print the contents of the text file for the application made four calculations in its lifetime, it should display data like this after the Bve!\" message: RECTANGLES (lengthlwidthjarealperimeter): 100.0200.020000.0600.0 300.0400.0 120000.01400.0 100.050.0 5000.0300.0 100.0175.017500.0350.0

Solution

RectangleIO.java

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.FileWriter;

import java.io.IOException;

import java.io.InputStreamReader;

public class RectangleIO {

  

   public static void save(Rectangle rect) throws IOException

   {

       File file = new File(\"rectangles\");

       BufferedWriter bw = new BufferedWriter(new FileWriter(file,true));

       String rectToWrite = \"\ \";

       rectToWrite += rect.getLength() + \"|\";

       rectToWrite += rect.getWidth() + \"|\";

       rectToWrite += rect.getArea() + \"|\";

       rectToWrite += rect.getPerimeter();

      

       bw.write(rectToWrite);

       bw.close();

   }

  

   public static void printFile() throws IOException

   {

       File file = new File(\"rectangles\");

       BufferedReader bf = new BufferedReader(new InputStreamReader(new FileInputStream(file)));

      

       String line = null;

       while((line = bf.readLine()) != null)

       {

           System.out.println(line);

       }      

       bf.close();

   }

}

Main.java

import java.io.IOException;

import java.util.Scanner;

public class Main {

public static void main(String args[]) throws IOException {

System.out.println(\"Welcome to the Area and Perimeter Calculator\");

System.out.println();

Scanner sc = new Scanner(System.in);

String choice = \"y\";

while (choice.equalsIgnoreCase(\"y\")) {

// get input from user

System.out.print(\"Enter length: \");

double length = Double.parseDouble(sc.nextLine());

System.out.print(\"Enter width: \");

double width = Double.parseDouble(sc.nextLine());

Rectangle r = new Rectangle(length, width);

RectangleIO.save(r);

// format and display output

String message =

\"Area: \" + r.getAreaNumberFormat() + \"\ \" +

\"Perimeter: \" + r.getPerimeterNumberFormat() + \"\ \";

System.out.println(message);

// see if the user wants to continue

System.out.print(\"Continue? (y/n): \");

choice = sc.nextLine();

System.out.println();

}

System.out.println(\"Bye!\");

RectangleIO.printFile();

sc.close();

}

}

J.A.V.A _ W.i.t.h.Net.B.E.A.N.s package rubix.cup; import java.util.Scanner; public class Main { public static void main(String args[]) { System.out.println(\
J.A.V.A _ W.i.t.h.Net.B.E.A.N.s package rubix.cup; import java.util.Scanner; public class Main { public static void main(String args[]) { System.out.println(\
J.A.V.A _ W.i.t.h.Net.B.E.A.N.s package rubix.cup; import java.util.Scanner; public class Main { public static void main(String args[]) { System.out.println(\
J.A.V.A _ W.i.t.h.Net.B.E.A.N.s package rubix.cup; import java.util.Scanner; public class Main { public static void main(String args[]) { System.out.println(\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site