Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Library>CS 107 home 2.23: Lab2c f we cast the int to a byte like so ? Help/ FAQ

ID: 3888364 • Letter: L

Question

Library>CS 107 home 2.23: Lab2c f we cast the int to a byte like so ? Help/ FAQ int i = 5; byte b - (byte) i; The int value will be truncated to fit within the memory space atlocated for byte ALWAYS BE CAREFUL WHEN CASTING VALUES! MAKE SURE YOU ARE COMPLETELY SURE WHAT THE RESULT WILL BE OR IT CAN LEAD TO TERRIBLE ISSUES IN YOUR PROGRAM Programming task The class will be called Eggs java. Meadowdale Dairy Farm sells organic brown eggs to local customers. They charge:-$3.25 for a dozen eggs -45 cents for individual eggs (not part of a dozen) As a special re-opening promotion, Meadowdale Dairy Farm will floor the price of the eggs (only charge the whole dollar amount) Write a class that accepts only one input from the user. for the number of eggs in the customer's order. After this, display the amount owed with a full explanation. Use arithmetic operations to calculate the correct dozens/loose eggs and total cost. For example, typical output might be: . That 'a 2 dozen at $3.25 per dozen and 3 loose eggs at 45 centa per each for a total of $7.85. With the special promotion, you pay $7! 0/ 10 LAB ACTIVITY 2.23.1: Lab2c Eggs,java 2 public class Eggs t 3 public static void mainCString args) t 4 Double Dozen-3.25; 5 Double Loose-,45; 6 Double Totalcost-0.00;

Explanation / Answer

import java.util.*;
import java.util.Scanner;
public class Eggs{
public static void main(String[] args){

double dozen = 3.25;
double loose = 0.45;
double totalcost = 0.00;

Scanner sc = new Scanner(System.in);
System.out.println("Enter number of eggs you want");
int eggs = sc.nextInt();
int doz = eggs/12;
int loo = eggs%12;
int l = (int)(loose*100);
totalcost = (doz*3.25)+(loo*0.45);
byte promotionsingle = (byte)totalcost;
System.out.println("You orderes "+eggs+" eggs. That's "+ doz +" dozen at ");
System.out.println("$ "+dozen+" per dozen and "+loo+" loose eggs at "+l);
System.out.println(" cents per each for a total of $"+totalcost+" . With the");
System.out.println("special promotion, you pay $"+promotionsingle+" !");

}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote