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

I have this assignment where im supposed to create 3 cubes .. the proff. wants u

ID: 3904635 • Letter: I

Question

I have this assignment where im supposed to create 3 cubes .. the proff. wants us to use both BufferedReader and Scanner. im not sure why its not compiling even though i tried everything i know. its not compiling and shows these erroes

File: C:UsersAmjad PCDesktopciss 111ssignmentc.java [line: 22]
Error: length cannot be resolved to a variable
File: C:UsersAmjad PCDesktopciss 111ssignmentc.java [line: 25]
Error: legnth cannot be resolved to a variable
File: C:UsersAmjad PCDesktopciss 111ssignmentc.java [line: 27]
Error: color cannot be resolved to a variable
File: C:UsersAmjad PCDesktopciss 111ssignmentc.java [line: 28]
Error: color cannot be resolved to a variable
File: C:UsersAmjad PCDesktopciss 111ssignmentcube.java [line: 72]
Error: yes cannot be resolved to a variable

=======================================================================

this is the program

/* Amjad
Cube assign/* Amjad
Cube assignment
This program will make cubes
*/
import java.util.Scanner;
import java.io.*;
public class c
{
public static void main(String[] args) throws IOException
{
cube cube1 = new cube();
  
BufferedReader br = new
BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(System.in);

System.out.print("Change Cube 1?: ");
if (br.readLine() == "yes"){
System.in.read();
System.out.println("Enter the length of the first cube: ");
length = sc.nextDouble();
//System.in.read();
//System.in.read();
cube1.setlength(legnth);
System.out.println("Enter the color of the first cube: ");
color = br.readLine();
cube1.setcolor(color);
yesOrNo(cube1);
cube1.printCube(1);
}
  
/*  
if (br.readLine() == "no"){
cube1.printCube(1);
}
  
System.out.print("Change Cube 2?: ");
if (br.readLine() == "yes"){
System.in.read();
System.out.println("Enter the length of the second cube: ");
cube2.setlength(br.read);
System.in.read();
System.in.read();
System.out.println("Enter the color of the second cube: ");
cube2.setcolor(br.readLine());
yesOrNo(cube2);
cube2.printCube(2);
}
if (br.readLine() == "no"){
cube2.printCube(2);
}
  
System.out.print("Change Cube 3?: ");
if (br.readLine() == "yes"){
System.in.read();
System.out.println("Enter the length of the third cube: ");
cube3.setlength(br.read());
System.in.read();
System.in.read();
System.out.println("Enter the color of the third cube: ");
cube3.setcolor(br.readLine());
yesOrNo(cube3);
cube3.printCube(3);
}
if (br.readLine() == "no"){
cube3.printCube(3);
}
*/

  
}

public static void yesOrNo(cube cubeN)
{
  
BufferedReader br = new
BufferedReader(new InputStreamReader(System.in));  

System.out.println("Enter if the first cube is filled (yes/no): ");

String yn = "";

try {
yn = br.readLine();
} catch (IOException e) {

e.printStackTrace();
}
if (yn.toLowerCase() == "yes")
{
cubeN.setfill(true);
}
else if (yn.toLowerCase() == "no")
{
cubeN.setfill(false);
}
else
{
System.out.print("Invalid Input (yes/no): ");
yesOrNo(cubeN);
}
}
}

================================================================

this is the defining file .

/* Amjad
Cube assignment
This class will define a cube
*/
public class cube
{
private double length;
private String color;
private double surface;
private double volume;
private boolean fill;
  
public cube()
{
length = 1.00;
color = "black";
surface = (6 * Math.pow(1.00, 2));
volume = Math.pow(1.00, 3);
fill = false;
}
  
public void setlength(double l)
{
length = l;
}
public void setcolor(String co)
{
color = co;
}
public void setfill(boolean f)
{
fill = f;
}  
  
public double getlength()
{
return length;
}
public String getcolor()
{
return color;
}
public double getsurface()
{
surface = (6 * Math.pow(getlength(), 2));
return (6 * Math.pow(getlength(), 2));
}
public double getvolume()
{
volume = (Math.pow(getlength(), 3));
return (Math.pow(getlength(), 3));
}
public boolean getfill()
{
return fill;
}
public void printCube(int index)
{
System.out.print("Cube " + index + " ");
  
String yesOrNo = "";
if (getfill() == true){
yesOrNo = "yes";
}
  
if (getfill() == false){
yesOrNo = "no";
}
  
System.out.print("say " + yesOrNo + " to change ");
  
if (yesOrNo == yes){
System.out.print("length: " + getlength());
System.out.print(" color: " + getcolor());
System.out.print(" fill: " + getfill());
}
}
  
  
  
  
  
}

Explanation / Answer

This is basically because you have misspelled the words and haven't defined the data type.

The corrected code is

import java.util.Scanner;
import java.io.*;
public class c {
public static void main(String[] args) throws IOException {
cube cube1 = new cube();

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(System.in);

System.out.print("Change Cube 1?: ");
if (br.readLine() == "yes") {
System.in.read();
System.out.println("Enter the length of the first cube: ");
double length = sc.nextDouble();
//System.in.read();
//System.in.read();
cube1.setlength(length);
System.out.println("Enter the color of the first cube: ");
String color = br.readLine();
cube1.setcolor(color);
yesOrNo(cube1);
cube1.printCube(1);
}

/*  
if (br.readLine() == "no"){
cube1.printCube(1);
}
  
System.out.print("Change Cube 2?: ");
if (br.readLine() == "yes"){
System.in.read();
System.out.println("Enter the length of the second cube: ");
cube2.setlength(br.read);
System.in.read();
System.in.read();
System.out.println("Enter the color of the second cube: ");
cube2.setcolor(br.readLine());
yesOrNo(cube2);
cube2.printCube(2);
}
if (br.readLine() == "no"){
cube2.printCube(2);
}
  
System.out.print("Change Cube 3?: ");
if (br.readLine() == "yes"){
System.in.read();
System.out.println("Enter the length of the third cube: ");
cube3.setlength(br.read());
System.in.read();
System.in.read();
System.out.println("Enter the color of the third cube: ");
cube3.setcolor(br.readLine());
yesOrNo(cube3);
cube3.printCube(3);
}
if (br.readLine() == "no"){
cube3.printCube(3);
}
*/


}

public static void yesOrNo(cube cubeN) {

BufferedReader br = new
BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter if the first cube is filled (yes/no): ");

String yn = "";

try {
yn = br.readLine();
} catch (IOException e) {

e.printStackTrace();
}
if (yn.toLowerCase() == "yes") {
cubeN.setfill(true);
} else if (yn.toLowerCase() == "no") {
cubeN.setfill(false);
} else {
System.out.print("Invalid Input (yes/no): ");
yesOrNo(cubeN);
}
}
}

//=== === === === === === === === === === === === === === === === === === === === === =

//this is the defining file.

/* Amjad
Cube assignment
This class will define a cube
*/
class cube {
private double length;
private String color;
private double surface;
private double volume;
private boolean fill;

public cube() {
length = 1.00;
color = "black";
surface = (6 * Math.pow(1.00, 2));
volume = Math.pow(1.00, 3);
fill = false;
}

public void setlength(double l) {
length = l;
}
public void setcolor(String co) {
color = co;
}
public void setfill(boolean f) {
fill = f;
}

public double getlength() {
return length;
}
public String getcolor() {
return color;
}
public double getsurface() {
surface = (6 * Math.pow(getlength(), 2));
return (6 * Math.pow(getlength(), 2));
}
public double getvolume() {
volume = (Math.pow(getlength(), 3));
return (Math.pow(getlength(), 3));
}
public boolean getfill() {
return fill;
}
public void printCube(int index) {
System.out.print("Cube " + index + " ");

String yesOrNo = "";
if (getfill() == true) {
yesOrNo = "yes";
}

if (getfill() == false) {
yesOrNo = "no";
}

System.out.print("say " + yesOrNo + " to change ");

if (yesOrNo.equals("yes")) {
System.out.print("length: " + getlength());
System.out.print(" color: " + getcolor());
System.out.print(" fill: " + getfill());
}
}
}

Equate two strings using .equals only and do give a thumbs up and in case there are doubts leave a comment.