Concept explainers
Days in a Month
Write a class named MonthDays, The class’s constructor should accept two arguments:
- An integer for the month (1 = January, 2 February, etc.).
- An integer for the year
The class should have a method named numberOfDays that returns the number of days in the specified month. The method should use the following criteria to identify leap years:
- 1. Determine whether the year is divisible by 100. If it is, then it is a leap year if and if only it is divisible by 400. For example, 2000 is a leap year but 2100 is not.
- 2. If the year is not divisible by 100, then it is a leap year if and if only it is divisible by 4. For example, 2008 is a leap year but 2009 is not.
Demonstrate the class in a
Enter a month (1-12): 2 [Enter]
Enter a year: 2008 [Enter]
29 days
Want to see the full answer?
Check out a sample textbook solutionChapter 6 Solutions
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Additional Engineering Textbook Solutions
Starting Out With Visual Basic (8th Edition)
Starting out with Visual C# (4th Edition)
C How to Program (8th Edition)
Starting Out With Visual Basic (7th Edition)
Software Engineering (10th Edition)
Computer Systems: A Programmer's Perspective (3rd Edition)
- Assignment: Dice Rolling Program Objective: Create a Java program that rolls two dice and displays the results. The program should have two Java classes: one for a single die and another for a pair of dice. Assignment Details: User Input: Ask the user to specify the number of sides they want on each die. Ensure that the user's input is within a reasonable range. Dice Rolling: Simulate rolling the dice using Math.random() based on the user's chosen number of sides. Display the sum of the values rolled, e.g., "5 + 3 = 8." Special Combinations: If the dice roll results in combinations of 2, 7, or 12, print special messages: "1 + 1 = 2 snake eyes!" "3 + 4 = 7 craps!" "6 + 6 = 12 box cars!" Main Method: In the main method, create a pair of dice, roll them, and display the results. Allow the user to decide whether to continue rolling the dice or exit the program. Additional Features: You are welcome to add more features or enhancements to the program if desired. In…arrow_forwardQuestion - Create a class named Pizza with the following data fields: description - of type String price - of type double The description stores the type of pizza (such as sausage and onion). Include a constructor that requires arguments for both fields and a method named display to display the data. For example, if the description is 'sausage and onion' and the price is '14.99', the display method should output: sausage and onion pizza Price: $14.99 Create a subclass named DeliveryPizza that inherits from Pizza but adds the following data fields: deliveryFee - of type double address - of type String The description, price, and delivery address are required as arguments to the constructor. The delivery fee is $3 if the pizza ordered costs more than $15; otherwise it is $5. Code that is not accepted - class DeliveryPizza extends Pizza { private double deliveryFee; private String address; public DeliveryPizza(String desc, double price, double deliveryFee, String address){…arrow_forwardQuickly please i need help in 15 minutes please please please pleasearrow_forward
- The program must include two classesclGradesGraph and GradesGrapghDemo. GradesGraphDemo (one method)- Main method only GradesGraph- Include at least 4 methods (No credits without at least 4 methods!!!) Create a class that represents the grade distribution for a given course. In this class you should write methods to perform the following tasks: Read the number of each of the letter grades A, B, C D and F Set the number of letter grades A, B, C, D and F Return the total number of grades Return the percentage of each letter grade as a whole number between 0 and 100 inclusive Draw a bar graph of the grade distributionThe graph should have five bars, one per grade. Each bar can be a horizontal row of asterisks, such that the number of asterisks in a row is proportionate to the percentage of grades in each category. For example, let on asterisk represent 2%, so 50 asterisks correspond to 100%. Mark the horizontal axis at 10% increments from 0 to 100% and label each line with a letter…arrow_forwardCargo Ships This question involves cargo ships that carry a specific number of cargo containers. Each ship has a maximum number of cargo containers that it can hold and a current number of cargo containers that it is holding. You can see more details in the Ship class that is provided for you. Part A For part A, you will be completing the nextToUnload() method. This takes no input and returns a Ship from the ships instance variable that has the highest percentage of its cargo hold filled (as measured by current hold / capacity). If two ships have the same percentage, then it should return the first ship with that percentage. If all of the ships in the ships array are empty (ie. no cargo), the method should return null. Part B For part B, you will complete the two unloadShip methods. The first method takes a Ship object and unloads all of the cargo from that ship. The second method takes a Ship and an int and unloads the specified number of containers from the ship. If the number of…arrow_forwardQuestionarrow_forward
- A special static method named is used to provide a starting point for the execution of a program using the class that declares it. *arrow_forwardChapter 4 Project Project Name: Chpt4_Project Class Name: Chpt4_Project Write a Java program that accepts names of members on a tug of war team, computes their total weight, and determines if their total is less than the maximum weight allowed. There can be no more than three member. team. This is an international competition and the maximum team weight is 272.16 kg, which is 600 lbs. The formula to convert lbs to kg is: kg = lb 2.2046 Inputs: The name of the team, its members' names, and the weight of each member. The name variables must strings and weight variables must be doubles. The member weights will be entered in lbs and must be converte to determine if the team exceeds the maximum weight allowed. The name of the team is: Enter the name of member 1: Enter the weight of member 1 in lbs (must be decimal value): Enter the name of member 2: Enter the weight of member 2 in lbs (must be decimal value): Enter the name of member 3: Enter the weight of member 3 in lbs (must be decimal…arrow_forwardRolling Dice Simulator [Java Assignment]Objective: Create a Java program that rolls two dice and displays the results. The program should have two Java classes: one for a single die and another for a pair of dice. Assignment Details: User Input: Ask the user to specify the number of sides they want on each die. Ensure that the user's input is within a reasonable range. Dice Rolling: Simulate rolling the dice using Math.random() based on the user's chosen number of sides. Display the sum of the values rolled, e.g., "5 + 3 = 8." Special Combinations: If the dice roll results in combinations of 2, 7, or 12, print special messages: "1 + 1 = 2 snake eyes!" "3 + 4 = 7 craps!" "6 + 6 = 12 box cars!" Main Method: In the main method, create a pair of dice, roll them, and display the results. Allow the user to decide whether to continue rolling the dice or exit the program. Additional Features: You are welcome to add more features or enhancements to the program if desired.…arrow_forward
- PLEASE CODE IN PYTHON PLEASE USE THE CLASS FUNCTION In python, create a LunchOrder application that prompts the user for the number of hamburgers, salads, french fries, and sodas and then displays the total for the order. The LunchOrder application should includea Food object with a constructor that accepts the price, fat, carbs, and fiber for an item. Food methods should return the price of the item and return the fat, carbohydrates, and fiber. Use the chart below forfood prices and nutrition information:arrow_forwardMethods are functions which are declared inside a class. True Falsearrow_forwardin C# i need to Create a BankAccount class with the following properties: Account Number (string) Account Holder Name (string) Balance (double) Account Type (enum: Savings, Current) Create the following methods in the BankAccount class: Deposit(double amount): Method to deposit money into the account Withdraw(double amount): Method to withdraw money from the account CheckBalance(): Method to check the current balance of the account Create a Bank class with the following properties: List of bank accounts (List<BankAccount>) Create the following methods in the Bank class: AddAccount(BankAccount account): Method to add a new bank account to the list of accounts RemoveAccount(string accountNumber): Method to remove an existing bank account from the list of accounts SearchAccount(string accountNumber): Method to search for an existing bank account and return the account details Create a Program class with the Main method, and implement the following functionality:…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage