你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好
import java.text.NumberFormat;
public class Item
{
private String item;
private int quantity;
private double price;
public Item(String item, double price, int quantity)
{
this.item = item;
this.price=price;
this.quantity=quantity;
}
public String getItem(){
return item;
}
public double getPrice(){
return price;
}
public int getQuantity(){
return quantity;
}
public double getTot(){
return price\*quantity;
}
public String toString()
{
NumberFormat fmt = NumberFormat.getCurrencyInstance();
String description;
description = item + "\\t" + fmt.format(price) + "\\t" + quantity + "\\t";
return description;
}
}
import java.text.NumberFormat;
public class ShoppingCart {
private Item\[\] cart;
private int itemCount;
private int capacity;
private double totalPrice = 0, q=0, p=0;
public ShoppingCart() {
capacity = 100;
cart = new Item\[capacity\];
itemCount = 0;
}
public void addItem(String item, double price, int quantity) {
if (itemCount == cart.length) {
increaseSize();
}
cart\[itemCount\] = new Item(item, price, quantity);
totalPrice+=price\*quantity;
itemCount++;
}
public String toString() {
NumberFormat fmt = NumberFormat.getCurrencyInstance();
String report = "Shopping Cart\\n";
report += "Item\\tUnit Price\\tQuantity\\tTotal\\n";
for (int i = 0; i < itemCount; i++) {
Item it = cart\[i\];
report += it.getItem() + "\\t" + fmt.format(it.getPrice()) + "\\t" + it.getQuantity() + "\\t\\t" + fmt.format(it.getTot()) + "\\n";
}
report += "\\nTotal Price of cart: " + fmt.format(totalPrice);
return report;
}
private void increaseSize() {
Item\[\] temp = new Item\[cart.length + 3\];
for (int i = 0; i < cart.length; i++) {
temp\[i\] = cart\[i\];
}
cart = temp;
}
}
import java.util.Scanner;
public class Shop
{
public static void main(String\[\] args)
{
ShoppingCart cart = new ShoppingCart();
boolean shop=true;
double price;
String item=new String();
int quantity;
Scanner scan=new Scanner (System.in);
while(shop){
System.out.print("Item: ");
item=scan.nextLine();
System.out.print("Price: ");
price=scan.nextDouble();
scan.nextLine();
System.out.print("Quantity: ");
quantity=scan.nextInt();
scan.nextLine();
cart.addItem(item, price, quantity);
System.out.println(cart.toString());
System.out.print("Continue? (true/false)");
shop=scan.nextBoolean();
scan.nextLine();
}
System.out.println(cart.toString());
}
}
//Task 1
import java.util.Scanner;
public class weatherchecker{
public static void main (String args\[\]){
Scanner scan=new Scanner (System.in);
System.out.println("Please enter the temperature:");
double t=scan.nextDouble();
System.out.println("Please enter the weather:");
String w=scan.nextLine();
String Sunny="sunny";
if(w.equals(Sunny)&&t>=20&&t<=30){
System.out.println("Perfect day for a picnic!");
}
else{
System.out.println("Not the best day for a picnic.");
}
}
}
//Task 2
import java.util.Scanner;
public class stringcomparison{
public static void main (String args\[\]){
Scanner scan=new Scanner (System.in);
System.out.println("Please enter:");
String t=scan.nextLine();
String l=scan.nextLine();
if(t.equals(l)){
System.out.println("Strings are identical.");
}
else{
System.out.println("Strings are different.");
}
}
}
//Task 3
import java.util.Scanner;
public class movierecommendation{
public static void main (String args\[\]){
Scanner scan=new Scanner (System.in);
System.out.println("Please enter the type:");
String t=scan.nextLine();
String action="action movies";
String comedies="comedies";
System.out.println("Please enter the rating:");
double r=scan.nextDouble();
if(t.equals(action)&&r>8){
System.out.println("Recommended.");
}
else if (t.equals(comedies)&&r<5){
System.out.println("Try a different one.");
}
else{
System.out.println("You can try this one as well.");
}
}
}
//Task 4
import java.util.Scanner;
public class passwordchecker{
public static void main (String args\[\]){
Scanner scan=new Scanner (System.in);
System.out.println("Please enter the password:");
String p=scan.nextLine();
String up=p.toUpperCase();
int in=p.indexOf("PASSWORD");
if(p.length()<8||in>=0){
System.out.println("Invalid password");
}
else{
System.out.println("Password is valid");
}
}
}
//Task 5
import java.util.Scanner;
public class discounteligibility{
public static void main (String args\[\]){
Scanner scan=new Scanner (System.in);
System.out.println("Please enter whether you are a member:");
boolean Member=scan.nextBoolean();
System.out.println("Please enter the money:");
double m=scan.nextDouble();
if(Member=true||m>=100){
System.out.println("Eligible for discount.");
}
else{
System.out.println("Not eligible for discount.");
}
}
}
//Task 6
import java.util.Scanner;
public class comparingnumber{
public static void main (String args\[\]){
Scanner scan=new Scanner (System.in);
System.out.println("Please enter the first number:");
int f=scan.nextInt();
System.out.println("Please enter the second number:");
int s=scan.nextInt();
if(f==s){
System.out.println("Numbers are equal.");
}
else if (f>s){
System.out.println("First number is greater.");
}
else{
System.out.println("Second number is greater.");
}
}
}
![]()











