Question

Need java code for both questions..thx

> Problem 1 U As you know the ber of days in achthof our ca . Forway 2 days in a year, or days other • April S a d November 3

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// "DaysInMonth.java"

import java.util.Scanner;

public class DaysInMonth {

   public static void main(String[] args) {
      
       Scanner sc=new Scanner(System.in);
      
       System.out.println("Enter month (1-12)");
      
       int month=sc.nextInt();
      
       int normal_year_month_days[]= {31,28,31,30,31,30,31,31,30,31,30,31};
       int leap_year_month_days[]= {31,29,31,30,31,30,31,31,30,31,30,31};
      
       System.out.println("Enter year (1000-3000)");
      
       int year=sc.nextInt();
      
       if(month<1 || month>12 || year<1000 ||year>3000)
       {
           System.out.println("Error - month and/or year out of bounds");
       }
      
       if(year % 400 ==0) //it is a leap year
       {
           //month-1 is done since array index starts from 0
           System.out.println(month+"/"+year+" contains "+leap_year_month_days[month-1]+" days");
          
       }
       else if(year % 4==0 && year % 100==0)//not a leap year
       {
           System.out.println(month+"/"+year+" contains "+normal_year_month_days[month-1]+" days");
       }
       else//leap year
       {
           System.out.println(month+"/"+year+" contains "+leap_year_month_days[month-1]+" days");
       }

   }

}

//Output

Enter month (1-12) 2 Enter year (1000-3000) 2004 2/2004 contains 29 days

2."Airportparking.java"

import java.util.Scanner;

public class Airportparking {

   public static void main(String[] args) {
      
       Scanner sc=new Scanner(System.in);
       System.out.println("enter nos of years parked");
       int mins=sc.nextInt();
      
       float amount=0;
               //while(mins!=0)
               if(mins<=30)
               {
                   System.out.println("$0");
               }
               else if(mins>30 && mins<=60)
               {
                   System.out.println("$2");
               }
               else if(mins>60 && mins<1440)
               {
                   amount=(float) (Math.ceil((float)(mins-60)/30)+2); //rounding up to nearest integer
                   System.out.println("$"+amount);
               }
               else
               {
                   float q=mins/1440;
                   amount+=q*24;
                  
                   float r=mins%1440;
                   r=r-30; //zero cost for first 30 minutes
                  
                   r=r/30;
                   r=(float) Math.ceil(r);//rounding to next half hour
                   if(r>1)
                   {
                   amount+=(r-1)*1+2;
                   }
                   else
                   {
                       amount+=2;
                   }
                   System.out.println("$"+amount);
               }
          

   }

}

Output:-

enter nos of years parked 31

Add a comment
Know the answer?
Add Answer to:
Need java code for both questions..thx > Problem 1 U As you know the ber of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Java You are to write a program that determines the day of the week for...

    In Java You are to write a program that determines the day of the week for New Year's Day in the year 3000. To do this, you must create your own date class (MyDate) and use the following interface and main program: /** Interface for Date objects to be used by the Year3000 driver program. @author Jon Sorenson */ public interface DateInterface { /** @return the day of the month (1-31) */ public int getDay(); /** @return the day of...

  • Please use public class for java. Thank you. 1. (10 points) Write a method that computes...

    Please use public class for java. Thank you. 1. (10 points) Write a method that computes future investment value at a given interest rate for a specified number of years. The future investment is determined using the formula futurelnvestmentValue numberOfYears 12 investmentAmount X ( monthlyInterestRate) Use the following method header: public static double futurelnvestmentValue( double investmentAmount, double monthlyInterestRate, int years) For example, futureInvestmentValue 10000, 0.05/12, 5) returns 12833.59. Write a test program that prompts the user to enter the investment...

  • write programs with detailed instructions on how to execute. code is java What you need to...

    write programs with detailed instructions on how to execute. code is java What you need to turn in: You will need to include an electronic copy of your report (standalone) and source code (zipped) of your programs. All programming files (source code) must be put in a zipped folder named "labl-name," where "name" is your last name. Submit the zipped folder on the assignment page in Canvas; submit the report separately (not inside the zipped folder) as a Microsoft Word...

  • Write in python code Project 11-1: Birthday Calculator Create a program that accepts a name and...

    Write in python code Project 11-1: Birthday Calculator Create a program that accepts a name and a birth date and displays the person's birthday the current day, the person's age, and the number of days until the person's next birthday Console Birthday Calculator Enter name: Joel Enter birthday (MM/DD/YY): 2/4/68 Birthday: Sunday, February 04, 1968 Today: Joel is 48 years old. Joel's birthday is in 73 days Tuesday, November 22, 2016 Continue? (y/n): y Enter name: Django Enter birthday (MM/DD/YY):...

  • USE JAVA Problem 1: Guess a Number You are writing a program for a number guessing...

    USE JAVA Problem 1: Guess a Number You are writing a program for a number guessing game. For playing "Guess a Number", the program will generate a number for player to guess from within a range specified by the player. The program will take as input the lowest number in the range and the highest number in the range from the player, and then a series of guesses of the form: <n,>n, = n, where n is the number guessed....

  • A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes...

    A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are: 1) The year must be divisible by 4 2) If the year is a century year...

  • I need java code... Background Suppose you're working on the next great cligital assistant to compete...

    I need java code... Background Suppose you're working on the next great cligital assistant to compete with the likes of Siri, Cortana Alexa, and the lameless Google Assistant. An important part of your assistant is a text-10-speerlingine, You've managed to get your assistant to pronounce Englisli words, but you've hit a sag! The resistant is unable to pronounce numbers. When it sees 6243, it just says "six two four three insteud of the proper "six thousand two hundred forty three."...

  • I need the pseudocode and python for the four attached problems: 1. (Chapter 5 - For...

    I need the pseudocode and python for the four attached problems: 1. (Chapter 5 - For Loop) Logic Technical College has a current tuition of $10,000 per year. Tuition is scheduled to increase by 5% each year. Using a FOR loop, design a program that calculates and displays the tuition each year for the next ten years, like so: The tuition for year 1 will be: 10500.00 The tuition for year 2 will be: 11025.00 ……….. (You, of course will...

  • JAVA... QUESTION 3 IS A CONTINOUS TO Q2 CAN YOU SEND THE CODE SEPARATELY FOR EACH...

    JAVA... QUESTION 3 IS A CONTINOUS TO Q2 CAN YOU SEND THE CODE SEPARATELY FOR EACH Q , I BE SO THANKFUL Q2. Implement a program to store the applicant’s information for a visa office. You need to implement the following: A super class called Applicant, which has the following instance variables: A variable to store first name of type String. A variable to store last name of type String. A variable to store date of birth, should be implemented...

  • 1.Given a positive integer number says n, write a java program to print the first n...

    1.Given a positive integer number says n, write a java program to print the first n squared numbers recursively. Sample run 1: Enter the value of n: 5 ------------------------------------- First 5 square numbers are: 1 4 9 16 25 Sample run 2: Enter the value of n: 10 ------------------------------------- First 10 square numbers are: 1 4 9 16 25 36 49 64 81 100 Sample run 3: Enter the value of n: 12 ------------------------------------- First 12 square numbers are: 1...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT