I\'m in java 1 can you help me with this code please. I have to use if estatemen
ID: 3665895 • Letter: I
Question
I'm in java 1 can you help me with this code please. I have to use if estatement.
Programming Concepts 1. If statements Assignment Description A music store is selling CDs. The more you buy, the cheaper the cost per CD. Here are the prices: Number of CDs 1-5 6-10 11 or more Price/CD $15/CD $10/CD $5/CD Note: If the user enters 0 or a negative value, print a goodbye message, and don't calculate the total cost. Assignment Requirements 1. Prompt the user for the number of CDs they want to buy. 2. Output the cost/CD, the number of CDs they are buying, and the total cost. 3. If the user enters O or a negative value, print a goodbye message. 4. Do not use logical operators (&&) a. This means to not do: if (num CDs 1 && numCDsExplanation / Answer
import java.util.*;
import java.lang.*;
import java.io.*;
/**
* @author computerhives team
*/
class CDprices {
private double cost;
private int total;
private double amt;
private int numcds;
Integer objCost,objAmt;
// For Amount
void input() throws IOException {
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(in);
System.out.println("How many CDs would you like to?");
numcds = Integer.parseInt(br.readLine());
}
void calculate() {
String computerMove;
switch (numcds) {
case 0:
System.out.println("I'm sorry you didn't find any thing you like.");
break;
case 1:
case 2:
case 3:
case 4:
case 5:
objCost = new Integer(15);
objAmt = new Integer( numcds);
cost = objCost.doubleValue();
total = numcds;
amt=cost* objAmt.doubleValue();
break;
case 6:
case 7:
case 8:
case 9:
case 10:
objCost = new Integer(10);
objAmt = new Integer( numcds);
cost = objCost.doubleValue();
total = numcds;
amt=cost* objAmt.doubleValue();
break;
default:
objCost = new Integer(5);
objAmt = new Integer( numcds);
cost = objCost.doubleValue();
total = numcds;
amt=cost* objAmt.doubleValue();
break;
}
}
void display() {
if(numcds!=0)
{
System.out.println("The Cost of the CD is "+cost);
System.out.println("You havan " +total+ " CDs");
System.out.println("Your Total cost is "+amt);
System.out.println("Thank you!");
}
}
public static void main(String args[])throws IOException {
CDprices ob=new CDprices();
ob.input();
ob.calculate();
ob.display();
}
}
input:
How many CDs would you like to?10
OutPut:
The Cost of the CD is 10.0
You havan 10 CDs
Your Total cost is 100.0
Thank you!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.