Question: Instructions: Complete all (4) parts in one program. Submit (1) .java file for a full grade. Part 1: Magic Dates The date June 10, 1960

Instructions: Complete all (4) parts in one program. Submit (1) .java file for a full grade.

Part 1: Magic Dates The date June 10, 1960 is special because when you write it in the following format, the month times the day equals the year. 6/10/60 Write a program that asks the user for the month as a numeric, a day, and a two-digit year. The program should then determine whether the month times the day is equal to the year. If so, display a message saying the date is magic; otherwise, display a message saying the date is not magic.

Part 2: Free Calls Toll-Free numbers have become so popular that the 800-code prefix has run out of available numbers, so the additional 3-digit prefix 877 has been added. Create a program that accepts a 10-digit phone number (no 1 in front) and tells the user if the number is toll-free. Display Not toll-free otherwise.

EXAMPLE Input: 8001234567

Toll-free number

Programming Tip Scan the input in using a string and then break the string into sections using the substring method. Remember to use the string method to check for equality or you can declare the phone number as a long integer and strip the parts mathematically. Labs CSIT 210 Introduction to Programming 2

Part 3: Candy Bar Problem Again You wrote a Java program in the Lab 4 String Objects to determine how many cartons are needed to package candy bars when a carton holds 24 candy bars. Add a nested if statement to display the fee based on the number of cartons calculated.

Number of Cartons Fee charged per carton

1 5 $8

6-10 $7

11-15 $5

Over 15 $3

Here is some code from Lab 4 String Objects candy bar problem.

import java.text.NumberFormat;

import java.util.Scanner;

public class CandyBars { public static void main (String[] args)

{

final double BARSPERCARTON = 24;

int bars; double carton, fee;

NumberFormat fmt = NumberFormat.getCurrencyInstance();

Scanner scan = new Scanner(System.in);

System.out.print(" Enter number of candy bars........");

bars = scan.nextInt();

carton = (Math.ceil(bars/ BARSPERCARTON));

System.out.println(" Cartons = " + (int)carton);

}

}

Part 4: Write a program that lets the user enter 2 numeric values, and an arithmetic operator: +, -, * and / (use scan.next() to accept the operator). Write a switch statement that displays the result of the calculation using the operator and two numbers entered by the user. Be sure to use the default option.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!