Question

In: Computer Science

Write the basic JAVA code for the beginners and follow all the instructions listed 1. A...

Write the basic JAVA code for the beginners and follow all the instructions listed

1. A year with 366 days is called a leap year. A year is a leap year if it is divisible by 4 (for e.g., 1980), except that it is not a leap year if it is also divisible by 100 (for e.g., 1900); however, it is a leap year if it is further divisible by 400 (for e.g., 2000).

Write a program that prompts the user to enter a year and displays whether that year is a leap year. The program should repeatedly prompt the user for a year until the user enters a sentinel value of -99 to quit the program. Note that you will need to use the mod function (%) to determine divisibility by a number. You CANNOT use the class GregorianCalendar and any of its methods.

2. Write a java program to print student’s total marks, percentage and grade. User input is given to enter number of subjects and then prompts user to enter marks. Calculate Total marks, Student Percentage, Student Grade.

Note:

1. Maximum marks for a subject is 100.

2. percentage = (totalMarks/(count*100)) * 100;

>=90 is Grade A

>=80 and <=89.99 is Grade B

>=70 and <=79.99 is Grade C

>=60 and <=69.99 is Grade D

< 60 is Fail

Tips: use scanner for inputs, use for loop (to iterate and store marks), use switch statement (to print grades).

Sample Output:

Enter Number of Subject(s): 3

Enter Marks of 3 Subject(s):

70

80

90

Total Marks : 240

Student Percentage: 80

Student Grade : B

Solutions

Expert Solution

Program 1:-

Screenshot of program code:-

Screenshot of output:-

Program code to copy:-

//Program to check whether a given year is leap year or not
import java.util.Scanner;
public class LeapYear {

   public static void main(String[] args) {
       Scanner stdin = new Scanner(System.in); // For standard input
       int year;
       do {
           //Prompt & read a year from user
         System.out.print("Enter a year <enter sentinel value -99 to quit the program>: ");
         year = stdin.nextInt();
        
         if(year !=-99) {
         //Checking if a year is divisible by 4
             if(year % 4 == 0) {
                 //Checking if a year is divisible by 100
                 if(year % 100 == 0) {
                 //Checking if a year is divisible by 400
                     if(year % 400 == 0)
                         System.out.println(year + " is a Leap Year");
                     else
                         System.out.println(year + " is not a Leap Year");
                 }
                 else
                     System.out.println(year + " is a Leap Year");
             }
             else
                 System.out.println(year + " is not a Leap Year");
         }
        
       }while(year!=-99);
      
   }
}

Program 2:-

Screenshot of program code:-

Screenshot of output:-

Program code to copy:-

import java.util.Scanner;
public class StudentMarksGrade {

   public static void main(String[] args) {
       Scanner in = new Scanner(System.in);
      
       //Prompt & read Number of Subject(s) from user
       System.out.print("Enter Number of Subject(s): ");
int count = in.nextInt();
  
double totalMarks = 0;
//Prompt the user to enter marks of subjects
System.out.println("Enter Marks of " + count + " Subject(s): ");
for(int i=1; i<=count; i++) {
   //Read the marks of subjecy from user
double marks = in.nextDouble();
//Calculate total marks
totalMarks += marks;
}
//Calculate percentage
double percentage = (totalMarks/(count*100)) * 100;
  
//Display total marks & percentage
System.out.println("Total Marks: " + totalMarks);
System.out.println("Student Percentage: " + percentage);
  
//Determine grade
char grade;
if(percentage>=90)
   grade = 'A';
else
if(percentage>=80)
   grade = 'B';
else
if(percentage>=70)
   grade = 'C';
else
if(percentage>=60)
   grade = 'D';
else
   grade = 'F';
  
//Display grade
switch(grade) {
   case 'A': System.out.println("Student Grade : " + grade);
           break;
   case 'B': System.out.println("Student Grade : " + grade);
                   break;
   case 'C': System.out.println("Student Grade : " + grade);
                   break;
   case 'D': System.out.println("Student Grade : " + grade);
                   break;
   case 'F': System.out.println("Student Grade : Fail");
}
  
   }

}


Related Solutions

JAVA CODE BEGINNERS, I already have the demo code included Write a Bottle class. The Bottle...
JAVA CODE BEGINNERS, I already have the demo code included Write a Bottle class. The Bottle will have one private int that represents the countable value in the Bottle. Please use one of these names: cookies, marbles, M&Ms, pennies, nickels, dimes or pebbles. The class has these 14 methods: read()(please use a while loop to prompt for an acceptable value), set(int), set(Bottle), get(), (returns the value stored in Bottle), add(Bottle), subtract(Bottle), multiply(Bottle), divide(Bottle), add(int), subtract(int), multiply(int), divide(int), equals(Bottle), and toString()(toString()...
JAVA CODE FOR BEGINNERS!! DON'T USE FOR OR WHILE METHODS PLEASE! Write a program that reads...
JAVA CODE FOR BEGINNERS!! DON'T USE FOR OR WHILE METHODS PLEASE! Write a program that reads three strings from the keyboard. Although the strings are in no particular order, display the string that would be second if they were arranged lexicographically.
I am in beginners java course so using the most simple/basic JAVA please complete the following...
I am in beginners java course so using the most simple/basic JAVA please complete the following CODE SEGMENTS. (2 parts) FIRST PART: Using ITERATIVE create a METHOD MAX that returns the max element in an ArrayList of ints and prints all of the elements. *you have to use an iterative in the method.* (just need to write the METHOD ONLY not a whole program(will do in 2nd part), assume you are given any numbers/integers. SECOND PART: Now write a class...
I need code written in java for one of my projects the instructions are Write a...
I need code written in java for one of my projects the instructions are Write a program that interacts with the user via the console and lets them choose options from a food menu by using the associated item number. It is expected that your program builds an <orderString> representing the food order to be displayed at the end. (See Sample Run Below). Please note: Each student is required to develop their own custom menus, with unique food categories, items...
The code is bellow. follow this instructions to edit the code : lets assume that instead...
The code is bellow. follow this instructions to edit the code : lets assume that instead of the maximum and minimum values, you want to find the 2nd largest/smallest. For example, in the numbers 1 to 10, this would return 2 and 9 .you will have to change the "max_min" function accordingly. this has a different puepose than "max_min", so you must give it another name. code: #include <stdio.h> #define N 235 void max_min (int a[], int n, int *max,...
As code is given below, follow the instructions: 1. Count the number of comparisons and find...
As code is given below, follow the instructions: 1. Count the number of comparisons and find where to put that counter in the code 2. Pick a random pivot, right pivot, left pivot, middle pivot for each smaller array /sub-array import java.util.*; import java.util.List; public class QuickSort { public static void main(String[] args) { int[] values = { 6, 5, 4, 3, 1, 7, 8 }; System.out.println("Original order: "); for (int element : values) System.out.print(element + " "); IntQuickSorter.quickSort(values); System.out.println("\nFirst...
JAVA CODE BEGINNERS, I already have the DEMO CLASS(NEED YOU TO USE), I need you to...
JAVA CODE BEGINNERS, I already have the DEMO CLASS(NEED YOU TO USE), I need you to use all methods, also switch statements. Write a Temperature class. The class will have three conversion methods: toCelsius(), toKelvin() and toFahrenheit(). These methods will return a Temperature in those three scales equal to the this temperature. Note that the value of this is not changed in these conversions. In addition to these three conversion methods the class will have methods add(Temperature), subtract(Temperature), multiply(Temperature), and...
Write a Java test program, all the code should be in a single main method, that...
Write a Java test program, all the code should be in a single main method, that prompts the user for a single character. Display a message indicating if the character is a letter (a..z or A..Z), a digit (0..9), or other. Java's Scanner class does not have a nextChar method. You can use next() or nextLine() to read the character entered by the user, but it is returned to you as a String. Since we are only interested in the...
please write the java code so it can run on jGRASP Thanks! CODE 1 1 /**...
please write the java code so it can run on jGRASP Thanks! CODE 1 1 /** 2 * SameArray2.java 3 * @author Sherri Vaseashta4 * @version1 5 * @see 6 */ 7 import java.util.Scanner;8 public class SameArray29{ 10 public static void main(String[] args) 11 { 12 int[] array1 = {2, 4, 6, 8, 10}; 13 int[] array2 = new int[5]; //initializing array2 14 15 //copies the content of array1 and array2 16 for (int arrayCounter = 0; arrayCounter < 5;...
Instructions: Please write all answers in java Each problem should be completed as a single separate...
Instructions: Please write all answers in java Each problem should be completed as a single separate .java file, each with its own main(). Inputs should be read using a Scanner object and output should be printed using System.out.println. As you finish each question, submit your code to the autograder at: http://162.243.28.4/grader/homework2.html Make sure to include your name at the top as a single word. The submission utility will test your code against a different input than the sample given. When...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT