Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

iLab 3 Arrays, Classes, and Objects - Cylinder and Date JAVA

gdeluna27
gdeluna27 


STEP 1: Cylinder Create a class called Cylinder.java that contains two double-precision instance variables named radius and height. The class should include a constructor that initializes the radius and height variables. Also, you need a class method named volume() that returns the volume of a Cylinder object. The volume of a cylinder is given by its radius squared times its height times Pi (radius * radius * height * Math.PI). You can either use the value 3.1416 for Pi or use the Java provided value named Math.PI. Write a class called CylinderTest.java and declare an array of three Cylinder objects to call the methods you declared in the Cylinder class. Make sure that all class methods are called from main(). Have main() display the value returned by volume() and verify the returned value by hand calculations (paper/pencil). Prompt the user to enter the values for the radius and height of each Cylinder object in the array. Grading Rubric Cylinder Points Description Standard header included 1 Must contain program's name, student name, and description of the program Program compiles 2 Program does not have any error Program executes 2 Program runs without any error Created Cylinder class 3 Program contains the Cylinder class Constructor created that initializes variables 2 A constructor method exists in the Cylinder class and initializes radius and height Contains a volume method 2 The volume method exists in the Cylinder class and it returns the volume of a Cylinder object CylinderTest class, which drives the application, is created 4 A driver class with the main method Correct output is displayed 4 Program displays the radius, height, and volume of three Cylinder objects Subtotal 20 STEP 2: Date (20 points) Create a program called Date.java to perform error-checking on the initial values, for instance: fields month, day, and year. Also, provide a method nextDay() to increment the day by one. The Date object should always remain in a consistent state. Write a program called DateTest.java that prompts the user to enter the month, day, and year as numeric values. This program then creates a Date object using the Date class you just created and tests the nextDay() method. This can be done in a loop of 40 iterations: the Date object calls the nextDay() method and prints the date during each iteration of the loop. This loop is to illustrate that the nextDay() method works correctly. Test the following cases: Incrementing into the next month, for example, use date: 02/28/2011 Incrementing into the next year, for example, use date: 11/27/2011 Incrementing into the next month in a leap year, for example, use date: 02/28/2012 Sample Program Output: Checking increment Date object constructor for date 11/27/2011 Incremented Date:11/28/2011 Incremented Date:11/29/2011 Incremented Date:11/30/2011 Day 31 invalid. Set to day 1. Incremented Date:12/1/2011 Incremented Date:12/2/2011 ... Incremented Date:12/30/2011 Incremented Date:12/31/2011 Day 32 invalid. Set to day 1. Incremented Date:1/1/2012 Incremented Date:1/2/2012 Incremented Date:1/3/2012 Incremented Date:1/4/2012 Incremented Date:1/5/2012 Incremented Date:1/6/2012 Grading Rubric Date Points Description Standard header included 1 Must contain program’s name, student name, and description of the program Program compiles 2 Program does not have any error Program executes 2 Program runs without any error Created Date class 6 Date class has nextDay method and does not use any other predefined Java class for date DateTest class, which drives the application, is created 4 User enters the values for month, day, and year in a numeric format and test the nextDay method Correct output is displayed 5 The correct date increment is displayed Subtotal 20 Attachments
Tags
Clarifications

Answers

iLab 3 - Cylinder and Date JAVA classes

Seeker
Seeker 



Eclipse project attached ..... Attachments
iLab3.zip (14 K) Download













Preview
version="1.0" encoding="UTF-8"

Preview
OutputVersion="1"><TaskRepository kind="bugzilla" url="https://bugs.eclipse.org/bugs" version="3.6" encoding="UTF-8" timezone="America/New_York" org.eclipse.mylyn.tasklist.repositories.proxy.usedefault="true" org.eclipse.mylyn.tasklist.repositories.savePassword="true"

Preview
encoding="UTF-8" standalone="no"?><TaskList

Preview
public double getHeight(){ return this.height; } public double getRadius(){ return this.radius; }

Preview
currentCylinder++; }catch(Exception e){ System.out.println("Invalid numbers entered for height or radius. Please retry."); } } // iterate the cylinder objects inside the cylinder array currentCylinder = 1; for(Cylinder single : testCylinders){ System.out.println("Cylinder number " + currentCylinder + ": Height = "

Preview
this.day++; // largest day allowed for the current month int maxDay = daysInMonth.get(this.month); // if the current month is February and we are in a leap year, add one day to Feb's largest day if(isLeapYear() && this.month == 2){ maxDay++; }

Preview
enter a starting numeric year in the yyyy format"); String syear = input.nextLine(); int month = 0, day = 0, year = 0; try{ // User input year in wrong format, let them retry if(syear.length() != 4){ System.out.println("Year not correct format");

Screenshots
Purchase Answer