In: Computer Science
Task #1 – Software Sales
A software company sells a package that retails for $99. Quantity
discounts are given according to the following:
Quantity Discount
1 - 9 NO DISCOUNT
10 – 19 20%
20 – 49 30%
50 – 99 40%
100 or more 50%
Your program calculates the final purchase price of the software
packages based on the quantity purchased. If a value of 0 or less
(a negative number) is entered, display the message “Invalid
Quantity” and end the program.
Input:
Ask the user to enter the quantity of packages purchased.
Process:
Calculate the subtotal (quantity * $99)
Apply the discount based on the discount schedule shown
above.
Output:
Display the number of products purchased, the amount of the
discount (if any) and the total amount of the purchase after the
discount. Correctly format your output as currency ($xx.xx).
Sample User Input:
Enter the number of products purchased > 15
Sample User Output:
Your purchase of 15 products provides a quantity discount is
20%
Your total purchase price is $1198.00
Task #2 – The Bookseller
As a bookseller, you have a book club that awards points to its
customers based on the number of books published each month.
The points awarded are as follows:
If the customer purchases 0 books, he/she earns 0 points
If the customer purchases 1 book, he/she earns 5 points
If the customer purchases 2 books, he/she earns 15 points
If the customer purchases 3 books, he/she earns 30 points
If the customer purchases 4 or more books, he/she earns 60
points
Write a program that asks the user to enter the number of books
that he or she has purchased and then displays the number of points
awarded. Use the SWITCH statement for this problem.
Input:
Prompt the user for the number of books purchased
Process:
Determine the number of points awarded based on the point schedule
shown above
Output:
Display the number of points earned
Sample User Input:
Enter the number of books purchased > 1
Sample User Output:
You have earned 5 points
Task #3 – How much would you weigh on Mars
This task allows the user to determine how much they would weigh on
any one of the planets in our Solar System.
How much you weigh depends on your mass, the mass of the planet,
and the distance you are from the center of the planet. Since the
various planets in our Solar System are different sizes, you will
weigh less or more depending on the planet you are on. I will spare
you some of the calculations and simplify it to: Weight = Mass x
Surface Gravity
So, if you know your weight on Earth and the surface gravity on
Earth, you can calculate your mass. You can then calculate your
weight on any other planet by using the surface gravity of that
planet in the same equation.
Process:
Read the Planet Name
Read your body mass
Using the Table of Mass shown below, calculate and display your
weight using the equation:
Weight = Mass x Surface Gravity
Table of Surface Gravity for various planets
Mercury: 0.055
Venus: 0.82
Earth: 1.0
Mars: 0.11
Jupiter: 318
Saturn: 95.2
To simplify even further, I’m not giving you all of the planets in
our Solar System.
In order to perform this task, you need some form of selection
flow. The choice is up to you!
You will need to validate that a correct planet name was entered.
Consider a mixed case entry of the planet – this is acceptable.
However, misspellings are NOT acceptable.
If not, display a message indicating that the name entered was
invalid and then exit the program!
Case 1:
Sample User Input for valid user input:
Enter the planet name> EArth
Enter your body mass (in pounds) > 100
Sample User Output:
Based on your body mass of 100, on the planet Earth, you would
weigh 100 pounds
Case 2:
Sample User Input for invalid user input:
Enter the planet name> Earttttth
Enter your body mass (in pounds) > 100
Sample User Output:
You have entered an invalid planet name
Need this code in Java!
Please up vote ,comment if any query . Thanks for question . Be safe .
Note : check attached image for output .
Task 1 Program : ***********************************DiscountMain.java*******************************
import java.util.Scanner;
public class DiscountMain {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in); //console read scanner
object
while(true)
{
int discount=0;
System.out.print("Enter the number of products purchased > ");
//prompt for number of items purchased
int itemPurchased=sc.nextInt(); //read item purchased
if(itemPurchased>=1 && itemPurchased<=9) //if 1 to
9 no discount applied
{
discount=0;
}
else if(itemPurchased>=10 && itemPurchased<=19)
//if 10-19 20%
{
discount=20;
}
else if(itemPurchased>=20 && itemPurchased<=49) //if
20-49 30%
{
discount=30;
}
else if(itemPurchased>=50 && itemPurchased<=99) //if
50-99 40%
{
discount=40;
}
else if(itemPurchased>=100) //if 100>= 50%
{
discount=50;
}
else //invalid quantity
{
System.out.println("Invalid Quantity");
break;
}
//print purchase
System.out.println("Your purchase of "+itemPurchased+" products
provides a quantity discount is "+discount+"%");
double totalPurchase=(itemPurchased*99)-(itemPurchased*99)*.20;
//(item*99)-((item*99)*20/100)
String totalCost=String.format("%.2f", totalPurchase);//convert
into string for 2 decimal places
System.out.println("Your total purchase price is $"+totalCost);
//print discount
}
}
}
Output : Discount
Task2 Program : ****************************BookMain.java***************
import java.util.Scanner;
public class BookMain {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in); //console read scanner
object
System.out.print("Enter the number of books purchased > ");
//prompt for number of books purchased
int booksPurchased=sc.nextInt(); //read books
//switch case for books
switch(booksPurchased)
{
case 0: //if 0 books points also 0
System.out.println("You have earned 0 points");
break;
case 1: //1 for 5 point
System.out.println("You have earned 5 points");
break;
case 2: //2 for 15
System.out.println("You have earned 15 points");
break;
case 3:
System.out.println("You have earned 30 points");
break;
default: //if 4 or more 60 points
System.out.println("You have earned 60 points");
break;
}
}
}
Output : books task
Task 3 Program : **********************PlanetMain.java*******************************
import java.util.Scanner;
public class PlanetMain {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in); //console read scanner
object
while(true) //infinite loop
{
double weight=0.0; //declare weight
boolean exitFlag=false; //exit flag set false
System.out.print("Enter planer name >"); //prompt for planet
name
String planetName=sc.nextLine(); //read name
planetName= planetName.toLowerCase();//convert it into lower
case
System.out.print("Enter your body mass (in pounds)>"); //prompt
for weight
double mass= Double.parseDouble(sc.nextLine()); //read as string
and convert it into double
switch(planetName) //switch case for planet name
{
case "mercury": //for mercury
weight=mass*0.055;
break;
case "venus":
weight=mass*0.82;
break;
case "earth":
weight=mass*1.0;
break;
case "mars":
weight=mass*0.11;
break;
case "jupiter":
weight=mass*318;
break;
case "saturn":
weight=mass*95.2;
break;
default: //if invalid planet name
System.out.println("You have entered an invalid planet name.");
//print error message
exitFlag=true; //set exit flag to true
break;
}
if(exitFlag) //break from loop
{
break;
}
System.out.println("Based on your body mass of "+mass+", on the
planet "+planetName+", you would weigh "+weight+" pounds");
}
}
}
Output : Planet Task
Please up vote ,comment if any query .