有谁帮我机智?扫描仪stdin? [英] CAn anyone help me wit the?? scanner stdin?

查看:61
本文介绍了有谁帮我机智?扫描仪stdin?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是个问题?谁能帮帮我?有点困惑..使用JcreatorLe

This is the question?.. can anyone help me?? kinda confused..using JcreatorLe


批发图书经销商需要一个程序来编写他通过电话为客户订购的图书订单的发票。每个订单通常包含多个书名的多个副本。程序应询问用户是否有订单要处理。如果用户回答是,那么程序应该询问订单中第一本书的价格和这些书的数量。然后该程序应显示这些书的成本,包括7.5%的销售税。然后程序应该询问是否有其他订单。如果有,程序应该按照刚才描述的方式处理它。如果没有更多订单,程序应显示已处理的订单总数,已售书籍总数和总收据。
A wholesale book dealer needs a program to write invoices for book orders that he takes for a customer over the phone. Each order usually consists of multiple copies of several book titles. The program should ask the user if there is an order to process. If the user responses yes, then the program should ask for the price of the first book in the order and the number of such books. The program should then display the cost of these books, including a 7.5% sales tax. Then the program should ask if there is another order. If there is one, the program should process it as just described. If there are no more orders, the program should display the total number of orders processed, the total number of books sold, and the total receipts.



SAmple输出:


SAmple Output :


是否有处理订单(是/否) ? y


输入图书1的价格:RM 20.00

输入图书1:3的数量

图书1的成本:RM64.50


是否有处理订单(是/否)? y


输入图书2的价格:RM 50.00

输入图书2的数量:2

第2册的成本:RM 107.50


是否有订单处理(是/否)? y


输入图书3的价格:RM 40.00

输入图书3的数量:2

图书3的成本:RM 86.00


是否有订单处理(是/否)? y


输入图书4的价格:RM 10.00

输入图书4:3的数量

图书4的成本:RM 32.25


是否有处理订单(是/否)?


处理完的订单总数:4

已售出的总书数:10

总价:RM 290.25
Is there an order to process (Y/N)? y

Enter the price for book 1: RM 20.00
Enter the quantity for book 1: 3
Cost for book 1: RM64.50

Is there an order to process (Y/N)? y

Enter the price for book 2: RM 50.00
Enter the quantity for book 2: 2
Cost for book 2: RM 107.50

Is there an order to process (Y/N)? y

Enter the price for book 3: RM 40.00
Enter the quantity for book 3: 2
Cost for book 3: RM 86.00

Is there an order to process (Y/N)? y

Enter the price for book 4: RM 10.00
Enter the quantity for book 4: 3
Cost for book 4: RM 32.25

Is there an order to process (Y/N)? n

Total number of orders processed: 4
Total number of books sold: 10
Total price: RM 290.25



我有点搞砸了..

这里是我的代码..



I kinda messed up alot..
here is my codes..



import java.util。*;

import java.text.DecimalFormat;

import java.lang.Double;



公共类预订{



public static void main(String args []){


int process;

双倍价格;

int数量;

int quantity1 = 0;

double sum = 0.00;

double sum1 = 0.00;

double cost = 0.00;

String Result ="" ;;


DecimalFormat twoDigits = new DecimalFormat(" 0.00");

Scanner stdin = new Scanner(System.in);



System.out.print(是否有处理订单?(Y?N));


Result = stdin.nex t();


do


{

System.out.print("输入图书的价格%d:RM");


price = stdin.nextDouble();


System.out.print (输入图书的数量%d:);


quantity = stdin.nextInt();



quantity1 = quantity1 +数量;


成本=(双倍)((价格*数量)* 1.075);


System.out。 println(书籍成本%d:%。2lf \ n);


sum1 =总和+成本;

count ++;


System.out.print(是否有处理订单? (Y?N)");


} while((结果==''y''));


System.out.println(\ n处理的订单总数:%d+计数);

System.out.println(" \ nTotal书籍销售数量: %d" + quantity1);

System.out.println(" \ n总价:%。2lf \ n" + sum1);





}

}
import java.util.*;
import java.text.DecimalFormat;
import java.lang.Double;


public class Book {



public static void main(String args[]){

int process;
double price;
int quantity;
int quantity1=0;
double sum=0.00;
double sum1=0.00;
double cost=0.00;
String Result="";


DecimalFormat twoDigits = new DecimalFormat("0.00");
Scanner stdin= new Scanner(System.in);


System.out.print("Is there an order to process? (Y?N)");

Result= stdin.next();


do

{
System.out.print("Enter the price for book %d: RM ");

price = stdin.nextDouble();

System.out.print("Enter the quantity for book %d: ");

quantity = stdin.nextInt();


quantity1 = quantity1 + quantity;

cost = (double)((price * quantity) * 1.075);

System.out.println("Cost for book %d: %.2lf \n");

sum1 = sum + cost;
count++;

System.out.print("Is there an order to process? (Y?N)");


}while ((Result ==''y''));

System.out.println("\nTotal number of orders processed:%d "+count);
System.out.println("\nTotal number of books sold:%d "+quantity1);
System.out.println("\nTotal price:%.2lf \n"+sum1);





}
}

推荐答案

你非常接近,但下面的事情让你失望。

1.)变量名的选择

2.)使用.equals方法比较字符串

3.)println与printf不同

我在这里把这些东西搞砸了:

You were very close but the following things let you down.
1.) Choice of variable names
2.) Compare strings using .equals method
3.) println is different from printf
I twicked those things here:

展开 | Sele ct | Wrap | 行号


Thx dude ..它有效..顺便说一下我可以''似乎有一个开始..看起来令人困惑..

Thx dude.. it works.. btw i can''t seem to have a start at this ..seems confusing..


写一个程序,要求用户输入一个月的数字一年又一年。例如,如果用户想要进入1992年6月,他或她将输入6然后输入1992.该程序应该显示该月的天数。一定要考虑闰年。
Write a program that asks the user to enter the number of a month of the year and the year. For example, if the user wants to enter June, 1992, he or she would enter 6 and then enter 1992. The program should then display the number of days in that month. Be sure to take leap years into account.



样本输出:


Sample output:


输入月份:8

输入年份:2006


2006年8月的天数为31
Enter month: 8
Enter year: 2006

The number of days in August, 2006 is 31



样本输出2:


Sample output2:


输入月份:2

输入年份:2000

二月份的天数,2000年是29
Enter month: 2
Enter year: 2000

The number of days in February, 2000 is 29



样本输出3:

Sample output3:


输入月份:2
输入年份:2005


2005年2月的天数是28
Enter month: 2
Enter year: 2005

The number of days in February, 2005 is 28



我有点做又乱了.. = \

I kinda made a mess again.. =\


import java.util.Scanner;


class Switch2

{


public static void main(String [] args)

抛出java.io.IOException

{

int choice;

System.out.println(" year of year of year 2006 ..... 1");

System.out.println(2006年2月..... 2);

系统。 out.println(2006年3月..... 3);

System.out.println(2006年4月..... 4);

System.out.println(2006年5月..... 5);

System.out.println("年度六月) 2006 ..... 6");

System.out.println(2006年7月..... 7);

系统。 out.println(2006年8月..... 8);

System.out.println(2006年9月..... 9);

System.out.println(2006年10月..... 10);

System.out.println("年度十一月) 2006 ..... 11");

System.out.println(2006年度疾病年度...... 12);


do

{


Scanner stdin = new Scanner(System.in);


System.out .PRINT(QUOT;吨你选择[1-12]然后按[Enter]:");

choice = stdin.nextInt();


开关(选择)

{

案例0:System.out.println(" INVALID")中断;

案例1:System.out.println( " 31 QUOT);中断;

案例2:System.out.println(" 28");中断;

案例3:System.out.println(" 31");中断;

案例4:System.out.println(" 30");中断;

案例5:System.out.println(" 31");中断;

案例6:System.out.println(" 30");休息;

案例7:System.out.println(" 31"); break;

case 8:System.out.println(" 31");休息;

案例9:System.out.println(" 30"); break;

case 10:System.out.println(" 31");中断;

案例11:System.out.println(" 30");中断;

案例12:System.out.println(" 31");休息;


默认:System.out.println(无效选项);

}


} while(选择!= 13);


}

}
import java.util.Scanner;

class Switch2
{

public static void main(String[]args)
throws java.io.IOException
{
int choice;
System.out.println("January of year year 2006.....1");
System.out.println("February of year year 2006.....2");
System.out.println("March of year year 2006.....3");
System.out.println("April of year year 2006.....4");
System.out.println("May of year year 2006.....5");
System.out.println("June of year year 2006.....6");
System.out.println("July of year year 2006.....7");
System.out.println("August of year year 2006.....8");
System.out.println("September of year year 2006.....9");
System.out.println("October of year year 2006.....10");
System.out.println("November of year year 2006.....11");
System.out.println("Disember of year year 2006.....12");

do
{

Scanner stdin = new Scanner(System.in);

System.out.print("Type your choice[1-12] and press [Enter]: ");
choice = stdin.nextInt();

switch(choice)
{
case 0 : System.out.println("INVALID") break;
case 1 : System.out.println("31"); break;
case 2 : System.out.println("28"); break;
case 3 : System.out.println("31"); break;
case 4 : System.out.println("30"); break;
case 5 : System.out.println("31"); break;
case 6 : System.out.println("30"); break;
case 7 : System.out.println("31"); break;
case 8 : System.out.println("31"); break;
case 9 : System.out.println("30"); break;
case 10 : System.out.println("31"); break;
case 11 : System.out.println("30"); break;
case 12 : System.out.println("31"); break;

default: System.out.println("Invalid Option");
}

} while(choice!=13);

}
}



Thx dude ..它的工作原理..顺便说一下,我似乎无法开始这个......看起来令人困惑......

>


样本输出:




样本输出2:



样本输出3:



我有点乱了.. =
Thx dude.. it works.. btw i can''t seem to have a start at this ..seems confusing..




Sample output:




Sample output2:



Sample output3:



I kinda made a mess again.. =



这里你有一个小错误

案例0:System.out.println(" INVALID")休息;

确保你放置一个;在(INVALID)前面


无论如何,有很多方法可以让你的输出看起来像这样

输入月份:2
输入年份:2005

2005年2月的天数是28

我会制作一个数组或数组列表来保存你的月份和几天然后使用一个if语句使用扫描仪输入。

有人可能会建议使用公历


nomad

You have a small mistake here
case 0 : System.out.println("INVALID") break;
make sure you place a ; in front of ("INVALID")

anyway there are many ways you can get your output to look like this
Enter month: 2
Enter year: 2005
The number of days in February, 2005 is 28
I would make a array or an array list which would hold your months and days and then use an if statement using a scanner for the input .
Someone might suggest using the Gregorian calendar

nomad


这篇关于有谁帮我机智?扫描仪stdin?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆