Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have this assignment where im supposed to create 3 cubes .. the proff. wants us to use both BufferedReader and Scanner. im not sure

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:\Users\Amjad PC\Desktop\ciss 111\assignment\c.java [line: 22] Error: length cannot be resolved to a variable File: C:\Users\Amjad PC\Desktop\ciss 111\assignment\c.java [line: 25] Error: legnth cannot be resolved to a variable File: C:\Users\Amjad PC\Desktop\ciss 111\assignment\c.java [line: 27] Error: color cannot be resolved to a variable File: C:\Users\Amjad PC\Desktop\ciss 111\assignment\c.java [line: 28] Error: color cannot be resolved to a variable File: C:\Users\Amjad PC\Desktop\ciss 111\assignment\cube.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()); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

More Books

Students also viewed these Databases questions

Question

4. How has e-commerce affected business-to-business transactions?

Answered: 1 week ago