Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Assistance, Suppose the Get/Set Program example available for download in this weeks lecture was changed slightly . The change was with one line of

Java Assistance,

Suppose the Get/Set Program example available for download in this weeks lecture was changed slightly. The change was with one line of code and does not throw an error and the program compiles. No lines of code were deleted, but one line has been edited in the main class.

When the program runs, the output is as follows (user input in red):

This program will determine the number of hours for days, weeks, and months entered.

Please enter a number: 5 There are 0 hours in 5 day(s). There are 0 hours in 5 week(s). There are 0 hours in 5 month(s).

What seems to be the problem with the code?

Below is the Main Class Code from this week.

package getsetsample; /** * @Course: SDEV 250 ~ Java Programming I * @Author Name: Steven Hickey * @Assignment Name: getsetsample * @Date: Jun 11, 2015 * @Description: Simple get and set method program to determine hours in day(s), * week(s) and month(s). */ //Imports import java.util.Scanner;

//Begin Class GetSetSample public class GetSetSample {

//Begin Main Method public static void main(String[] args) {

//New Scanner object Scanner sc = new Scanner(System.in);

//Declarations int nums;

//Welcome statement System.out.println("This program will determine the number of hours for days, " + "weeks, and months entered."); //Ask for input from user System.out.print(" Please enter a number: "); nums = sc.nextInt(); //New instance of the subclass and constructor. Send input to subclass TimeCount myTC = new TimeCount(nums); /** Because you have already set the days in the line above, you can now retrieve the final value */ System.out.printf("There are %d hours in %d day(s). ", myTC.getDays(), nums); System.out.printf("There are %d hours in %d week(s). ", myTC.getWeeks(), nums); System.out.printf("There are %d hours in %d month(s). ", myTC.getMonths(), nums); /** Conversely, you can set the values individually as shown below. You can comment out lines 33 - 41 above and uncomment lines 50 - 61 below to see the results. Simply highlight the lines you want to comment (or uncomment) and select Source -> Toggle Comment from the menu at the top of NetBeans. If you decide to try this, you must change the set methods in the subclass to public or you will have errors. */ // //New instance of the subclass and constructor. // TimeCount myTC = new TimeCount(); // // //Set each value // myTC.setDays(nums); // myTC.setWeeks(nums); // myTC.setMonths(nums); // // //Get the derived values // System.out.printf("There are %d hours in %d day(s). ", myTC.getDays(), nums); // System.out.printf("There are %d hours in %d week(s). ", myTC.getWeeks(), nums); // System.out.printf("There are %d hours in %d month(s). ", myTC.getMonths(), nums); } //End Main Method

} //End Class GetSetSample

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

Students also viewed these Databases questions