Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Name: David
- * Class: CS225
- * Program:
- * Problem:
- * Input:
- * Output:
- */
- package classes_3;
- import java.util.Scanner;
- /**
- *
- * @author dcrs
- */
- public class Main
- {//Open Main
- public static void main( String[] args )
- {//Open main
- Introduction();
- /* ---declarations----------------------------------------------------- */
- //have to pre-initialize these because the switch and loop hides them from
- //the Java Virtual Machine compiler.
- Scanner i = new Scanner(System.in);
- Room Kitchen = new Room(), Bedroom = new Room(), Den = new Room();
- double totalArea;
- String[] rooms = { "Kitchen", "Bedroom", "Den" };
- /* ---initializations-------------------------------------------------- */
- /* ---user-input-maybe------------------------------------------------- */
- /* ---calculation-manipulation-engine---------------------------------- */
- for (int count = 0; count < 3; count++) {
- System.out.println("Enter length and width of "+rooms[count]+": ");
- switch(count) {
- case 0:
- Kitchen.setName(rooms[count]);
- Kitchen.setLength(i.nextDouble());
- Kitchen.setWidth(i.nextDouble());
- break;
- case 1:
- Bedroom.setName(rooms[count]);
- Bedroom.setLength(i.nextDouble());
- Bedroom.setWidth(i.nextDouble());
- break;
- case 2:
- Den.setName(rooms[count]);
- Den.setLength(i.nextDouble());
- Den.setWidth(i.nextDouble());
- break;
- }
- }
- totalArea = Kitchen.getArea() + Bedroom.getArea() + Den.getArea();
- /* ---output----------------------------------------------------------- */
- System.out.println(Kitchen.printArea());
- System.out.println(Bedroom.printArea());
- System.out.println(Den.printArea());
- System.out.println("Total Area: "+totalArea);
- Conclusion();
- }//close main
- /* ----------------------------------------------------------------------- *
- * -------------Concluding-Remarks---------------------------------------- *
- * ----------------------------------------------------------------------- */
- public static void Conclusion()
- {//open Conclusion
- }//close Conclusion
- /* ----------------------------------------------------------------------- *
- * -------------Introductory---------------------------------------------- *
- * ----------------------------------------------------------------------- */
- public static void Introduction()
- {//open Introduction
- }//close Introduction
- }//close Main
- public class Room
- {
- private String name;
- private double length;
- private double width;
- private double area;
- /*-------------------------------------------------------------------------*\
- |*---Constructor:-Generate-Initial-Values----------------------------------*|
- \*-------------------------------------------------------------------------*/
- public Room()
- {
- this.name = "Generic Room";
- this.length = 1;
- this.width = 1;
- this.area = length * width;
- }
- public Room( String name, double length, double width )
- {
- this.name = name;
- this.length = length;
- this.width = width;
- this.area = length * width;
- }
- //-------------------------------------------------------------------------*\
- //---Output----------------------------------------------------------------*|
- //-------------------------------------------------------------------------*/
- public String printArea()
- {
- return "Area of "+this.name+": "+this.area;
- }
- public void calculatetArea()
- {
- this.area = length*width;
- }
- /*-------------------------------------------------------------------------*\
- |*---Getters-and-Setters---------------------------------------------------*|
- \*-------------------------------------------------------------------------*/
- public double getArea()
- {
- return area;
- }
- public double getLength()
- {
- return length;
- }
- public double getWidth()
- {
- return width;
- }
- public String getName()
- {
- return name;
- }
- public void setLength( double length )
- {
- this.length = length;
- this.calculatetArea();
- }
- public void setWidth( double width )
- {
- this.width = width;
- this.calculatetArea();
- }
- public void setName( String name )
- {
- this.name = name;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement