Final project 4) Magic Dates The date June 10, 1960, is special because when it
ID: 3848109 • Letter: F
Question
Final project
4) Magic Dates
The date June 10, 1960, is special because when it is written in the following
format, the month times the day equals the year.
Design a program that asks the user to enter a month (in numeric form), a day, and
a two-digit year. The program should then determine whether the month times the
day equals the year. If so, it should display a message saying the date is magic. Otherwise,
it should display a message saying the date is not magic.
5)The colors red, blue, and yellow are known as the primary colors because they
cannot be made by mixing other colors. When you mix two primary colors, you
get a secondary color, as shown here:
When you mix red and blue, you get purple.
When you mix red and yellow, you get orange.
When you mix blue and yellow, you get green.
Design a program that prompts the user to enter the names of two primary colors
to mix. If the user enters anything other than “red,” “blue,” or “yellow,” the program
should display an error message. Otherwise, the program should display the
name of the secondary color that results.
6. Book Club Points
Serendipity Booksellers has a book club that awards points to its customers based
on the number of books purchased each month. The points are awarded as follows:
If a customer purchases 0 books, he or she earns 0 points.
If a customer purchases 1 book, he or she earns 5 points.
If a customer purchases 2 books, he or she earns 15 points.
If a customer purchases 3 books, he or she earns 30 points.
If a customer purchases 4 or more books, he or she earns 60 points.
Design a program that asks the user to enter the number of books that he or she
has purchased this month and displays the number of points awarded.
7. Software Sales
A software company sells a package that retails for $99. Quantity discounts are
given according to the following table:
Quantity Discount
10–19 20%
20–49 30%
50–99 40%
100 or more 50%
Design a program that asks the user to enter the number of packages purchased.
The program should then display the amount of the discount (if any) and the total
amount of the purchase after the discount.
Explanation / Answer
Question 4
import java.util.Scanner;
class Magic
{
public static void main(String arsg[])
{
int mon,yr,day,tr;
Scanner sc=new Scanner(System.in); //taking the user input
System.out.println("Please enter a month");
mon = sc.nextInt();
System.out.println("Please enter a day");
day = sc.nextInt();
System.out.println("Please enter a year");
yr = sc.nextInt();
tr=yr%100; //storing the last two digit of the year
if(mon*day==tr) //checking whether it matche the condition
System.out.println("It is a magic date"); //displaying the result
else
System.out.println("It is not a magic date");
}
}
Question 5
import java.util.Scanner;
class Colpri
{
public static void main(String arsg[])
{
String c1,c2;
Scanner sc=new Scanner(System.in); //taking the user input
System.out.println("Enter the first primary colour");
c1=sc.nextLine();
System.out.println("Enter the second primary colour");
c2=sc.nextLine(); //matching the condtion
if(c1.equalsIgnoreCase("red") && c2.equalsIgnoreCase("blue") || c1.equalsIgnoreCase("blue") && c2.equalsIgnoreCase("red"))
System.out.println("The colour you get is : purple");
else if(c1.equalsIgnoreCase("red") && c2.equalsIgnoreCase("yellow") || c1.equalsIgnoreCase("yellow") && c2.equalsIgnoreCase("red"))
System.out.println("The colour you get is : orange");
else if(c1.equalsIgnoreCase("blue") && c2.equalsIgnoreCase("yellow") || c1.equalsIgnoreCase("yellow") && c2.equalsIgnoreCase("blue"))
System.out.println("The colour you get is : green");
else
System.out.println("Invalid choice of clours"); //if condition doesnot matches with any
}
}
Question 6
import java.util.Scanner;
class Books
{
public static void main(String arsg[])
{
int n;
Scanner sc=new Scanner(System.in); //taking the user input
System.out.println("Enter the number of books purchased this month");
n=sc.nextInt();
if(n==0) //checking the condition
System.out.println("You have earned 0 points.");
else if(n==1)
System.out.println("You have earned 5 points.");
else if(n==2)
System.out.println("You have earned 15 points.");
else if(n==3)
System.out.println("You have earned 30 points.");
else
System.out.println("You have earned 60 points.");
}
}
Question 7
import java.util.Scanner;
class Discount
{
public static void main(String arsg[])
{
int n;
double dis,amount;
dis=0.0;
Scanner sc=new Scanner(System.in); //taking the user input
System.out.println("Enter the number of packages purchased");
n=sc.nextInt(); //checking the condtion
if(n<10)
dis=0.0;
else if(n>=10 && n<=19)
dis=0.2;
else if(n>=20 && n<=49)
dis=0.3;
else if(n>=50 && n<=99)
dis=0.4;
else
dis=0.5;
amount=(99-(99*dis)); //calculating the amount to be paid
System.out.println("Amount of discount is "+(dis*100)+"%"); //displaying the result
System.out.println("Total amount to be paid is $"+amount);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.